/// <summary> /// Convert this instance to an axis-angle representation. /// </summary> /// <returns>A Vector4 that is the axis-angle representation of this quaternion.</returns> public GVector4 ToAxisAngle() { var q = this; if (Math.Abs(q.W) > 1.0f) { q.Normalize(); } GVector4 result = new GVector4(); result.W = 2.0f * (float)System.Math.Acos(q.W); // angle float den = (float)System.Math.Sqrt(1.0 - q.W * q.W); if (den > 0.0001f) { result.Xyz = q.Xyz / den; } else { // This occurs when the angle is zero. // Not a problem: just set an arbitrary normalized axis. result.Xyz = GVector3.UnitX; } return(result); }
/// <summary> /// Convert the current quaternion to axis angle representation /// </summary> /// <param name="axis">The resultant axis</param> /// <param name="angle">The resultant angle</param> public void ToAxisAngle(out GVector3 axis, out float angle) { GVector4 result = ToAxisAngle(); axis = result.Xyz; angle = result.W; }
/// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary> /// <param name="vec">The vector to transform</param> /// <param name="mat">The desired transformation</param> /// <param name="result">The transformed vector</param> public static void TransformPerspective(ref GVector3 vec, ref Matrix4 mat, out GVector3 result) { GVector4 v = new GVector4(vec, 1); GVector4.Transform(ref v, ref mat, out v); result.x = v.X / v.W; result.y = v.Y / v.W; result.z = v.Z / v.W; }
public GVector3(GVector4 src) { this.x = src.X; this.y = src.Y; this.z = src.Z; }