const Zeni::Vector3f Utils::getSurfaceNormal(const Zeni::Point3f &p1, const Zeni::Point3f &p2, const Zeni::Point3f &p3) { Zeni::Vector3f v1 = p2 - p1; Zeni::Vector3f v2 = p3 - p2; Zeni::Vector3f normal = Zeni::Vector3f(); normal.i = (v1.y * v2.z) - (v1.z * v2.y); normal.j = (v1.z * v2.x) - (v1.x * v2.z); normal.k = (v1.x * v2.y) - (v1.y * v2.x); return normal.normalize(); }
void Energy::Update (Zeni::Time::Second_Type elapsedTime) { Zeni::Point2f hero = HeroComponent::GetInstance().GetPosition(); Zeni::Vector3f a (hero.x - position.x, hero.y - position.y, 0.0f); a.normalize(); SetAcceleration (100.0f * a); Simulateable::UpdatePosition (elapsedTime); }
const double Utils::getAngleBetweenVectors(const Zeni::Vector3f &v0, const Zeni::Vector3f &v1) { const double a = v0.magnitude(); const double b = v1.magnitude(); const double c = (v1 - v0).magnitude(); double d = (a * a + b * b - c * c) / (2 * a * b); if (d > 1) { d = 1.0f; } else if (d < -1.0f) { d = -1.0f; } return double(acos(d)); }
const Zeni::Vector3f Utils::getVectorComponent(const Zeni::Vector3f &vector, const Zeni::Vector3f &direction) { return vector*direction/direction.magnitude() * direction.normalized(); }