示例#1
0
        /// <summary> Sets the value of this axis-angle to the rotational equivalent
        /// of the passed quaternion.
        /// If the specified quaternion has no rotational component, the value
        /// of this AxisAngle4f is set to an angle of 0 about an axis of (0,1,0).
        /// </summary>
        /// <param name="q1"> the Quat4f
        /// </param>
        public void  set_Renamed(Quat4f q1)
        {
            double mag = q1.x * q1.x + q1.y * q1.y + q1.z * q1.z;

            if (mag > EPS)
            {
                mag = System.Math.Sqrt(mag);
                double invMag = 1.0 / mag;

                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                x = (float)(q1.x * invMag);
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                y = (float)(q1.y * invMag);
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                z = (float)(q1.z * invMag);
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                angle = (float)(2.0 * System.Math.Atan2(mag, q1.w));
            }
            else
            {
                x     = 0.0f;
                y     = 1.0f;
                z     = 0.0f;
                angle = 0.0f;
            }
        }
示例#2
0
 /// <summary> Sets the value of this quaternion to the conjugate of quaternion q1.</summary>
 /// <param name="q1">the source vector
 /// </param>
 public void  conjugate(Quat4f q1)
 {
     this.x = -q1.x;
     this.y = -q1.y;
     this.z = -q1.z;
     this.w = q1.w;
 }
示例#3
0
        /// <summary> Multiplies quaternion q1 by the inverse of quaternion q2 and places
        /// the value into this quaternion.  The value of both argument quaternions
        /// is preservered (this = q1 * q2^-1).
        /// </summary>
        /// <param name="q1">the first quaternion
        /// </param>
        /// <param name="q2">the second quaternion
        /// </param>
        public void  mulInverse(Quat4f q1, Quat4f q2)
        {
            Quat4f tempQuat = new Quat4f(q2);

            tempQuat.inverse();
            this.mul(q1, tempQuat);
        }
示例#4
0
        /// <summary> Multiplies this quaternion by the inverse of quaternion q1 and places
        /// the value into this quaternion.  The value of the argument quaternion
        /// is preserved (this = this * q^-1).
        /// </summary>
        /// <param name="q1">the other quaternion
        /// </param>
        public void  mulInverse(Quat4f q1)
        {
            Quat4f tempQuat = new Quat4f(q1);

            tempQuat.inverse();
            this.mul(tempQuat);
        }
示例#5
0
        /// <summary> Sets the value of this quaternion to quaternion inverse of quaternion q1.</summary>
        /// <param name="q1">the quaternion to be inverted
        /// </param>
        public void  inverse(Quat4f q1)
        {
            float norm;

            norm   = 1.0f / (q1.w * q1.w + q1.x * q1.x + q1.y * q1.y + q1.z * q1.z);
            this.w = norm * q1.w;
            this.x = (-norm) * q1.x;
            this.y = (-norm) * q1.y;
            this.z = (-norm) * q1.z;
        }
示例#6
0
        /// <summary> Sets the value of this quaternion to the quaternion product of
        /// itself and q1 (this = this * q1).
        /// </summary>
        /// <param name="q1">the other quaternion
        /// </param>
        public void  mul(Quat4f q1)
        {
            float x, y, w;

            w      = this.w * q1.w - this.x * q1.x - this.y * q1.y - this.z * q1.z;
            x      = this.w * q1.x + q1.w * this.x + this.y * q1.z - this.z * q1.y;
            y      = this.w * q1.y + q1.w * this.y - this.x * q1.z + this.z * q1.x;
            this.z = this.w * q1.z + q1.w * this.z + this.x * q1.y - this.y * q1.x;
            this.w = w;
            this.x = x;
            this.y = y;
        }
示例#7
0
        /// <summary>  Performs a great circle interpolation between this quaternion
        /// and the quaternion parameter and places the result into this
        /// quaternion.
        /// </summary>
        /// <param name="q1"> the other quaternion
        /// </param>
        /// <param name="alpha"> the alpha interpolation parameter
        /// </param>
        public void  interpolate(Quat4f q1, float alpha)
        {
            // From "Advanced Animation and Rendering Techniques"
            // by Watt and Watt pg. 364, function as implemented appeared to be
            // incorrect.  Fails to choose the same quaternion for the double
            // covering. Resulting in change of direction for rotations.
            // Fixed function to negate the first quaternion in the case that the
            // dot product of q1 and this is negative. Second case was not needed.

            double dot, s1, s2, om, sinom;

            dot = x * q1.x + y * q1.y + z * q1.z + w * q1.w;

            if (dot < 0)
            {
                // negate quaternion
                q1.x = -q1.x; q1.y = -q1.y; q1.z = -q1.z; q1.w = -q1.w;
                dot  = -dot;
            }

            if ((1.0 - dot) > EPS)
            {
                om    = System.Math.Acos(dot);
                sinom = System.Math.Sin(om);
                s1    = System.Math.Sin((1.0 - alpha) * om) / sinom;
                s2    = System.Math.Sin(alpha * om) / sinom;
            }
            else
            {
                s1 = 1.0 - alpha;
                s2 = alpha;
            }

            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            w = (float)(s1 * w + s2 * q1.w);
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            x = (float)(s1 * x + s2 * q1.x);
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            y = (float)(s1 * y + s2 * q1.y);
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            z = (float)(s1 * z + s2 * q1.z);
        }
示例#8
0
        /// <summary> Sets the value of this quaternion to the quaternion product of
        /// quaternions q1 and q2 (this = q1 * q2).
        /// Note that this is safe for aliasing (e.g. this can be q1 or q2).
        /// </summary>
        /// <param name="q1">the first quaternion
        /// </param>
        /// <param name="q2">the second quaternion
        /// </param>
        public void  mul(Quat4f q1, Quat4f q2)
        {
            if (this != q1 && this != q2)
            {
                this.w = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z;
                this.x = q1.w * q2.x + q2.w * q1.x + q1.y * q2.z - q1.z * q2.y;
                this.y = q1.w * q2.y + q2.w * q1.y - q1.x * q2.z + q1.z * q2.x;
                this.z = q1.w * q2.z + q2.w * q1.z + q1.x * q2.y - q1.y * q2.x;
            }
            else
            {
                float x, y, w;

                w      = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z;
                x      = q1.w * q2.x + q2.w * q1.x + q1.y * q2.z - q1.z * q2.y;
                y      = q1.w * q2.y + q2.w * q1.y - q1.x * q2.z + q1.z * q2.x;
                this.z = q1.w * q2.z + q2.w * q1.z + q1.x * q2.y - q1.y * q2.x;
                this.w = w;
                this.x = x;
                this.y = y;
            }
        }
示例#9
0
        /// <summary> Sets the value of this axis-angle to the rotational equivalent
        /// of the passed quaternion.
        /// If the specified quaternion has no rotational component, the value
        /// of this AxisAngle4d is set to an angle of 0 about an axis of (0,1,0).
        /// </summary>
        /// <param name="q1"> the Quat4f
        /// </param>
        public void  set_Renamed(Quat4f q1)
        {
            double mag = q1.x * q1.x + q1.y * q1.y + q1.z * q1.z;

            if (mag > EPS)
            {
                mag = System.Math.Sqrt(mag);
                double invMag = 1.0 / mag;

                x     = q1.x * invMag;
                y     = q1.y * invMag;
                z     = q1.z * invMag;
                angle = 2.0 * System.Math.Atan2(mag, q1.w);
            }
            else
            {
                x     = 0.0f;
                y     = 1.0f;
                z     = 0.0f;
                angle = 0.0f;
            }
        }
示例#10
0
        /// <summary> Sets the value of this quaternion to the normalized value
        /// of quaternion q1.
        /// </summary>
        /// <param name="q1">the quaternion to be normalized.
        /// </param>
        public void  normalize(Quat4f q1)
        {
            float norm;

            norm = (q1.x * q1.x + q1.y * q1.y + q1.z * q1.z + q1.w * q1.w);

            if (norm > 0.0f)
            {
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                norm   = 1.0f / (float)System.Math.Sqrt(norm);
                this.x = norm * q1.x;
                this.y = norm * q1.y;
                this.z = norm * q1.z;
                this.w = norm * q1.w;
            }
            else
            {
                this.x = (float)0.0;
                this.y = (float)0.0;
                this.z = (float)0.0;
                this.w = (float)0.0;
            }
        }
示例#11
0
		/// <summary> Sets the rotational component (upper 3x3) of this matrix to the matrix
		/// equivalent values of the quaternion argument; the other elements of this
		/// matrix are unchanged; a singular value decomposition is performed on
		/// this object's upper 3x3 matrix to factor out the scale, then this
		/// object's upper 3x3 matrix components are replaced by the matrix
		/// equivalent of the quaternion, and then the scale is reapplied to the
		/// rotational components.
		/// </summary>
		/// <param name="q1">the quaternion that specifies the rotation
		/// </param>
		public void  setRotation(Quat4f q1)
		{
			float scale = SVD(null, null);
			
			// save other values
			float tx = m03;
			float ty = m13;
			float tz = m23;
			float w0 = m30;
			float w1 = m31;
			float w2 = m32;
			float w3 = m33;
			
			set_Renamed(q1);
			mulRotationScale(scale);
			
			// set back
			m03 = tx;
			m13 = ty;
			m23 = tz;
			m30 = w0;
			m31 = w1;
			m32 = w2;
			m33 = w3;
		}
示例#12
0
		/// <summary> Sets the value of this matrix from the rotation expressed by the
		/// quaternion q1, the translation t1, and the scale s.
		/// </summary>
		/// <param name="q1"> the rotation expressed as a quaternion
		/// </param>
		/// <param name="t1"> the translation
		/// </param>
		/// <param name="s"> the scale value
		/// </param>
		public void  set_Renamed(Quat4f q1, Vector3f t1, float s)
		{
			set_Renamed(q1);
			mulRotationScale(s);
			m03 = t1.x;
			m13 = t1.y;
			m23 = t1.z;
		}
示例#13
0
		/// <summary> Sets the value of this matrix to the matrix conversion of the
		/// single precision quaternion argument. 
		/// </summary>
		/// <param name="q1">the quaternion to be converted 
		/// </param>
		public void  set_Renamed(Quat4f q1)
		{
			setFromQuat(q1.x, q1.y, q1.z, q1.w);
		}
示例#14
0
		/// <summary> Sets the value of this axis-angle to the rotational equivalent
		/// of the passed quaternion.
		/// If the specified quaternion has no rotational component, the value
		/// of this AxisAngle4d is set to an angle of 0 about an axis of (0,1,0).
		/// </summary>
		/// <param name="q1"> the Quat4f
		/// </param>
		public void  set_Renamed(Quat4f q1)
		{
			double mag = q1.x * q1.x + q1.y * q1.y + q1.z * q1.z;
			
			if (mag > EPS)
			{
				mag = System.Math.Sqrt(mag);
				double invMag = 1.0 / mag;
				
				x = q1.x * invMag;
				y = q1.y * invMag;
				z = q1.z * invMag;
				angle = 2.0 * System.Math.Atan2(mag, q1.w);
			}
			else
			{
				x = 0.0f;
				y = 1.0f;
				z = 0.0f;
				angle = 0.0f;
			}
		}
示例#15
0
		/// <summary> Constructs and initializes a Quat4d from the specified Quat4f.</summary>
		/// <param name="q1">the Quat4f containing the initialization x y z w data
		/// </param>
		public Quat4d(Quat4f q1):base(q1)
		{
		}
示例#16
0
		/// <summary> Sets the value of this quaternion to the quaternion product of
		/// quaternions q1 and q2 (this = q1 * q2).  
		/// Note that this is safe for aliasing (e.g. this can be q1 or q2).
		/// </summary>
		/// <param name="q1">the first quaternion
		/// </param>
		/// <param name="q2">the second quaternion
		/// </param>
		public void  mul(Quat4f q1, Quat4f q2)
		{
			if (this != q1 && this != q2)
			{
				this.w = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z;
				this.x = q1.w * q2.x + q2.w * q1.x + q1.y * q2.z - q1.z * q2.y;
				this.y = q1.w * q2.y + q2.w * q1.y - q1.x * q2.z + q1.z * q2.x;
				this.z = q1.w * q2.z + q2.w * q1.z + q1.x * q2.y - q1.y * q2.x;
			}
			else
			{
				float x, y, w;
				
				w = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z;
				x = q1.w * q2.x + q2.w * q1.x + q1.y * q2.z - q1.z * q2.y;
				y = q1.w * q2.y + q2.w * q1.y - q1.x * q2.z + q1.z * q2.x;
				this.z = q1.w * q2.z + q2.w * q1.z + q1.x * q2.y - q1.y * q2.x;
				this.w = w;
				this.x = x;
				this.y = y;
			}
		}
示例#17
0
		/// <summary> Sets the value of this matrix to the matrix conversion of the
		/// single precision quaternion argument.
		/// </summary>
		/// <param name="q1">the quaternion to be converted
		/// </param>
		public void  set_Renamed(Quat4f q1)
		{
			this.m00 = (1.0 - 2.0 * q1.y * q1.y - 2.0 * q1.z * q1.z);
			this.m10 = (2.0 * (q1.x * q1.y + q1.w * q1.z));
			this.m20 = (2.0 * (q1.x * q1.z - q1.w * q1.y));
			
			this.m01 = (2.0 * (q1.x * q1.y - q1.w * q1.z));
			this.m11 = (1.0 - 2.0 * q1.x * q1.x - 2.0 * q1.z * q1.z);
			this.m21 = (2.0 * (q1.y * q1.z + q1.w * q1.x));
			
			this.m02 = (2.0 * (q1.x * q1.z + q1.w * q1.y));
			this.m12 = (2.0 * (q1.y * q1.z - q1.w * q1.x));
			this.m22 = (1.0 - 2.0 * q1.x * q1.x - 2.0 * q1.y * q1.y);
		}
示例#18
0
		/// <summary> Sets the value of this quaternion to quaternion inverse of quaternion q1.</summary>
		/// <param name="q1">the quaternion to be inverted
		/// </param>
		public void  inverse(Quat4f q1)
		{
			float norm;
			
			norm = 1.0f / (q1.w * q1.w + q1.x * q1.x + q1.y * q1.y + q1.z * q1.z);
			this.w = norm * q1.w;
			this.x = (- norm) * q1.x;
			this.y = (- norm) * q1.y;
			this.z = (- norm) * q1.z;
		}
示例#19
0
		/// <summary> Sets the value of this quaternion to the normalized value
		/// of quaternion q1.
		/// </summary>
		/// <param name="q1">the quaternion to be normalized.
		/// </param>
		public void  normalize(Quat4f q1)
		{
			float norm;
			
			norm = (q1.x * q1.x + q1.y * q1.y + q1.z * q1.z + q1.w * q1.w);
			
			if (norm > 0.0f)
			{
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				norm = 1.0f / (float) System.Math.Sqrt(norm);
				this.x = norm * q1.x;
				this.y = norm * q1.y;
				this.z = norm * q1.z;
				this.w = norm * q1.w;
			}
			else
			{
				this.x = (float) 0.0;
				this.y = (float) 0.0;
				this.z = (float) 0.0;
				this.w = (float) 0.0;
			}
		}
示例#20
0
		/// <summary> Multiplies this quaternion by the inverse of quaternion q1 and places
		/// the value into this quaternion.  The value of the argument quaternion
		/// is preserved (this = this * q^-1).
		/// </summary>
		/// <param name="q1">the other quaternion
		/// </param>
		public void  mulInverse(Quat4f q1)
		{
			Quat4f tempQuat = new Quat4f(q1);
			
			tempQuat.inverse();
			this.mul(tempQuat);
		}
示例#21
0
		/// <summary> Multiplies quaternion q1 by the inverse of quaternion q2 and places
		/// the value into this quaternion.  The value of both argument quaternions 
		/// is preservered (this = q1 * q2^-1).
		/// </summary>
		/// <param name="q1">the first quaternion
		/// </param>
		/// <param name="q2">the second quaternion
		/// </param>
		public void  mulInverse(Quat4f q1, Quat4f q2)
		{
			Quat4f tempQuat = new Quat4f(q2);
			
			tempQuat.inverse();
			this.mul(q1, tempQuat);
		}
示例#22
0
		/// <summary> Sets the value of this quaternion to the quaternion product of
		/// itself and q1 (this = this * q1).  
		/// </summary>
		/// <param name="q1">the other quaternion
		/// </param>
		public void  mul(Quat4f q1)
		{
			float x, y, w;
			
			w = this.w * q1.w - this.x * q1.x - this.y * q1.y - this.z * q1.z;
			x = this.w * q1.x + q1.w * this.x + this.y * q1.z - this.z * q1.y;
			y = this.w * q1.y + q1.w * this.y - this.x * q1.z + this.z * q1.x;
			this.z = this.w * q1.z + q1.w * this.z + this.x * q1.y - this.y * q1.x;
			this.w = w;
			this.x = x;
			this.y = y;
		}
示例#23
0
		/// <summary> Constructs and initializes a Matrix4f from the quaternion,
		/// translation, and scale values; the scale is applied only to the
		/// rotational components of the matrix (upper 3x3) and not to the
		/// translational components.
		/// </summary>
		/// <param name="q1"> The quaternion value representing the rotational component
		/// </param>
		/// <param name="t1"> The translational component of the matrix
		/// </param>
		/// <param name="s"> The scale value applied to the rotational components
		/// </param>
		public Matrix4f(Quat4f q1, Vector3f t1, float s)
		{
			set_Renamed(q1, t1, s);
		}
示例#24
0
		/// <summary> Sets the rotational component (upper 3x3) of this matrix to the matrix
		/// equivalent values of the quaternion argument; the other elements of this
		/// matrix are unchanged; a singular value decomposition is performed on
		/// this object's upper 3x3 matrix to factor out the scale, then this
		/// object's upper 3x3 matrix components are replaced by the matrix
		/// equivalent of the quaternion, and then the scale is reapplied to the
		/// rotational components.
		/// </summary>
		/// <param name="q1">the quaternion that specifies the rotation
		/// </param>
		public void  setRotation(Quat4f q1)
		{
			double scale = SVD(null, null);
			
			// save other values
			double tx = m03;
			double ty = m13;
			double tz = m23;
			double w0 = m30;
			double w1 = m31;
			double w2 = m32;
			double w3 = m33;
			
			set_Renamed(q1);
			mulRotationScale(scale);
			
			// set back
			m03 = tx;
			m13 = ty;
			m23 = tz;
			m30 = w0;
			m31 = w1;
			m32 = w2;
			m33 = w3;
		}
示例#25
0
		/// <summary> Performs an SVD normalization of this matrix in order to acquire the
		/// normalized rotational component; the values are placed into
		/// the Quat4f parameter.
		/// </summary>
		/// <param name="q1">quaternion into which the rotation component is placed
		/// </param>
		public void  get_Renamed(Quat4f q1)
		{
			q1.set_Renamed(this);
			q1.normalize();
		}
示例#26
0
		/// <summary> Constructs and initializes a Matrix4d from the quaternion,
		/// translation, and scale values; the scale is applied only to the
		/// rotational components of the matrix (upper 3x3) and not to the
		/// translational components.
		/// </summary>
		/// <param name="q1"> The quaternion value representing the rotational component
		/// </param>
		/// <param name="t1"> The translational component of the matrix
		/// </param>
		/// <param name="s"> The scale value applied to the rotational components
		/// </param>
		public Matrix4d(Quat4f q1, Vector3d t1, double s)
		{
			set_Renamed(q1, t1, s);
		}
示例#27
0
		/// <summary> Sets the value of this axis-angle to the rotational equivalent
		/// of the passed quaternion.
		/// If the specified quaternion has no rotational component, the value
		/// of this AxisAngle4f is set to an angle of 0 about an axis of (0,1,0).
		/// </summary>
		/// <param name="q1"> the Quat4f
		/// </param>
		public void  set_Renamed(Quat4f q1)
		{
			double mag = q1.x * q1.x + q1.y * q1.y + q1.z * q1.z;
			
			if (mag > EPS)
			{
				mag = System.Math.Sqrt(mag);
				double invMag = 1.0 / mag;
				
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				x = (float) (q1.x * invMag);
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				y = (float) (q1.y * invMag);
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				z = (float) (q1.z * invMag);
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				angle = (float) (2.0 * System.Math.Atan2(mag, q1.w));
			}
			else
			{
				x = 0.0f;
				y = 1.0f;
				z = 0.0f;
				angle = 0.0f;
			}
		}
示例#28
0
		/// <summary> Sets the value of this quaternion to the conjugate of quaternion q1.</summary>
		/// <param name="q1">the source vector
		/// </param>
		public void  conjugate(Quat4f q1)
		{
			this.x = - q1.x;
			this.y = - q1.y;
			this.z = - q1.z;
			this.w = q1.w;
		}
示例#29
0
		/// <summary>  Performs a great circle interpolation between quaternion q1
		/// and quaternion q2 and places the result into this quaternion. 
		/// </summary>
		/// <param name="q1"> the first quaternion
		/// </param>
		/// <param name="q2"> the second quaternion
		/// </param>
		/// <param name="alpha"> the alpha interpolation parameter 
		/// </param>
		public void  interpolate(Quat4f q1, Quat4f q2, float alpha)
		{
			// From "Advanced Animation and Rendering Techniques"
			// by Watt and Watt pg. 364, function as implemented appeared to be 
			// incorrect.  Fails to choose the same quaternion for the double
			// covering. Resulting in change of direction for rotations.
			// Fixed function to negate the first quaternion in the case that the
			// dot product of q1 and this is negative. Second case was not needed. 
			
			double dot, s1, s2, om, sinom;
			
			dot = q2.x * q1.x + q2.y * q1.y + q2.z * q1.z + q2.w * q1.w;
			
			if (dot < 0)
			{
				// negate quaternion
				q1.x = - q1.x; q1.y = - q1.y; q1.z = - q1.z; q1.w = - q1.w;
				dot = - dot;
			}
			
			if ((1.0 - dot) > EPS)
			{
				om = System.Math.Acos(dot);
				sinom = System.Math.Sin(om);
				s1 = System.Math.Sin((1.0 - alpha) * om) / sinom;
				s2 = System.Math.Sin(alpha * om) / sinom;
			}
			else
			{
				s1 = 1.0 - alpha;
				s2 = alpha;
			}
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			w = (float) (s1 * q1.w + s2 * q2.w);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			x = (float) (s1 * q1.x + s2 * q2.x);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			y = (float) (s1 * q1.y + s2 * q2.y);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			z = (float) (s1 * q1.z + s2 * q2.z);
		}
示例#30
0
 /// <summary> Constructs and initializes a Quat4d from the specified Quat4f.</summary>
 /// <param name="q1">the Quat4f containing the initialization x y z w data
 /// </param>
 public Quat4d(Quat4f q1) : base(q1)
 {
 }