Esempio n. 1
0
        /// <summary>
        /// Convert this instance to an axis-angle representation.
        /// </summary>
        /// <returns>A Vector4 that is the axis-angle representation of this quaternion.</returns>
        public SCNVector4 ToAxisAngle()
        {
            SCNQuaternion q = this;

            if (q.W > 1.0f)
            {
                q.Normalize();
            }

            SCNVector4 result = new SCNVector4();

            result.W = 2.0f * (pfloat)System.Math.Acos(q.W); // angle
            pfloat den = (pfloat)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 = SCNVector3.UnitX;
            }

            return(result);
        }
Esempio n. 2
0
        /// <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 SCNVector3 axis, out pfloat angle)
        {
            SCNVector4 result = ToAxisAngle();

            axis  = result.Xyz;
            angle = result.W;
        }
Esempio n. 3
0
        /// <summary>Transform a Vector by the given Matrix</summary>
        /// <param name="vec">The vector to transform</param>
        /// <param name="mat">The desired transformation</param>
        /// <returns>The transformed vector</returns>
        public static SCNVector4 Transform(SCNVector3 vec, SCNMatrix4 mat)
        {
            SCNVector4 v4 = new SCNVector4(vec.X, vec.Y, vec.Z, 1.0f);
            SCNVector4 result;

            result.X = SCNVector4.Dot(v4, mat.Column0);
            result.Y = SCNVector4.Dot(v4, mat.Column1);
            result.Z = SCNVector4.Dot(v4, mat.Column2);
            result.W = SCNVector4.Dot(v4, mat.Column3);
            return(result);
        }
Esempio n. 4
0
        /// <summary>Transform a SCNVector3 by the given Matrix, and project the resulting Vector4 back to a SCNVector3</summary>
        /// <param name="vec">The vector to transform</param>
        /// <param name="mat">The desired transformation</param>
        /// <returns>The transformed vector</returns>
        public static SCNVector3 TransformPerspective(SCNVector3 vec, SCNMatrix4 mat)
        {
            SCNVector4 h = Transform(vec, mat);

            return(new SCNVector3(h.X / h.W, h.Y / h.W, h.Z / h.W));
        }
Esempio n. 5
0
        /// <summary>Transform a Vector by the given Matrix</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 Transform(ref SCNVector3 vec, ref SCNMatrix4 mat, out SCNVector4 result)
        {
            SCNVector4 v4 = new SCNVector4(vec.X, vec.Y, vec.Z, 1.0f);

            SCNVector4.Transform(ref v4, ref mat, out result);
        }
Esempio n. 6
0
 /// <summary>
 /// Constructs a new Vector3 from the given Vector4.
 /// </summary>
 /// <param name="v">The Vector4 to copy components from.</param>
 public SCNVector3(SCNVector4 v)
 {
     X = v.X;
     Y = v.Y;
     Z = v.Z;
 }