/// <summary> /// Convert this instance to an axis-angle representation. /// </summary> /// <returns>A TkVector4 that is the axis-angle representation of this quaternion.</returns> public TkVector4 ToAxisAngle() { TkQuaternion q = this; if (Math.Abs(q.W) > 1.0f) { q.Normalize(); } TkVector4 result = new TkVector4(); 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 = TkVector3.UnitX; } return(result); }
/// <summary> /// The new Half4 instance will convert the TkVector4 into 16-bit half-precision floating-point. /// </summary> /// <param name="v">OpenTK.TkVector4</param> /// <param name="throwOnError">Enable checks that will throw if the conversion result is not meaningful.</param> public TkVector4h(ref TkVector4 v, bool throwOnError) { X = new Half(v.X, throwOnError); Y = new Half(v.Y, throwOnError); Z = new Half(v.Z, throwOnError); W = new Half(v.W, throwOnError); }
/// <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 TkVector3 axis, out float angle) { TkVector4 result = ToAxisAngle(); axis = result.Xyz; angle = result.W; }
/// <summary> /// The new Half4 instance will convert the TkVector4 into 16-bit half-precision floating-point. /// This is the fastest constructor. /// </summary> /// <param name="v">OpenTK.TkVector4</param> public TkVector4h(ref TkVector4 v) { X = new Half(v.X); Y = new Half(v.Y); Z = new Half(v.Z); W = new Half(v.W); }