/************************************************************/ static EVector3() { ms_zeroVector = new EVector3 (true); ms_oneVector = new EVector3 (1.0f); }
// "direction" must be a unit vector public EVector3 project(EVector3 direction) { float mag = dot (direction); return (mag * direction); }
public EVector3 projectOntoNonUnitVector(EVector3 v) { float mag = dot (v) / v.normSquared (); return (mag * v); }
public void multiplyComponents(EVector3 v) { X *= v.X; Y *= v.Y; Z *= v.Z; }
public EVector3 multiplyComponents(EVector3 v1, EVector3 v2) { EVector3 prodV = v1; prodV.multiplyComponents (v2); return (prodV); }
public EVector3 cross(EVector3 v) { float rx, ry, rz; rx = Y * v.Z - Z * v.Y; ry = -X * v.Z + Z * v.X; rz = X * v.Y - Y * v.X; return (new EVector3 (rx, ry, rz)); }
public float dot(EVector3 v) { return (X * v.X + Y * v.Y + Z * v.Z); }
// Return the perpendicular component of the projection of // this onto "direction" // "direction" must be a unit vector public EVector3 computePerpendicularComponentWrt(EVector3 direction) { return (this - project (direction)); }
// consider "v" non-normal regardless of "isNormal" public EVector3 computePerpendicularComponentWrt(EVector3 v, bool isNormal) { return (this - projectOntoNonUnitVector (v)); }
public static EVector3 lerp(EVector3 source, EVector3 destination, float destinationWeight) { EVector3 result = (1 - destinationWeight) * source + destinationWeight * destination; return (result); }
public static float dot(EVector3 v1, EVector3 v2) { return (v1.dot (v2)); }
public static EVector3 cross(EVector3 v1, EVector3 v2) { return (v1.cross (v2)); }
public Matrix3(EVector3 right, EVector3 up, EVector3 forward) { m00 = right.X; m01 = right.Y; m02 = right.Z; m10 = up.X; m11 = up.Y; m12 = up.Z; m20 = -forward.X; m21 = -forward.Y; m22 = -forward.Z; }
public void decompose(out Vector3 scale, out Quaternion rotation) { EVector3 right = new EVector3 (this.Right); scale.X = right.normalize (); EVector3 up = new EVector3 (this.Up); scale.Y = up.normalize (); EVector3 forward = new EVector3 (this.Forward); scale.Z = forward.normalize (); Matrix3 m = new Matrix3 (right, up, forward); rotation = m.getQuaternion (); }