Exemple #1
0
 /// <summary>
 /// Scale a quaternion
 /// </summary>
 /// <param name="quaternion1">The quaternion to scale.</param>
 /// <param name="scaleFactor">Scale factor.</param>
 /// <param name="result">The scaled quaternion.</param>
 public static void Multiply(ref JQuaternion quaternion1, float scaleFactor, out JQuaternion result)
 {
     result.X = quaternion1.X * scaleFactor;
     result.Y = quaternion1.Y * scaleFactor;
     result.Z = quaternion1.Z * scaleFactor;
     result.W = quaternion1.W * scaleFactor;
 }
Exemple #2
0
 /// <summary>
 /// Quaternions are subtracted.
 /// </summary>
 /// <param name="quaternion1">The first quaternion.</param>
 /// <param name="quaternion2">The second quaternion.</param>
 /// <param name="result">The difference of both quaternions.</param>
 public static void Subtract(ref JQuaternion quaternion1, ref JQuaternion quaternion2, out JQuaternion result)
 {
     result.X = quaternion1.X - quaternion2.X;
     result.Y = quaternion1.Y - quaternion2.Y;
     result.Z = quaternion1.Z - quaternion2.Z;
     result.W = quaternion1.W - quaternion2.W;
 }
Exemple #3
0
        /// <summary>
        /// Scale a quaternion
        /// </summary>
        /// <param name="quaternion1">The quaternion to scale.</param>
        /// <param name="scaleFactor">Scale factor.</param>
        /// <returns>The scaled quaternion.</returns>
        #region public static JQuaternion Multiply(JQuaternion quaternion1, float scaleFactor)
        public static JQuaternion Multiply(JQuaternion quaternion1, float scaleFactor)
        {
            JQuaternion result;

            JQuaternion.Multiply(ref quaternion1, scaleFactor, out result);
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Multiply two quaternions.
        /// </summary>
        /// <param name="quaternion1">The first quaternion.</param>
        /// <param name="quaternion2">The second quaternion.</param>
        /// <returns>The product of both quaternions.</returns>
        #region public static JQuaternion Multiply(JQuaternion quaternion1, JQuaternion quaternion2)
        public static JQuaternion Multiply(JQuaternion quaternion1, JQuaternion quaternion2)
        {
            JQuaternion result;

            JQuaternion.Multiply(ref quaternion1, ref quaternion2, out result);
            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Quaternions are subtracted.
        /// </summary>
        /// <param name="quaternion1">The first quaternion.</param>
        /// <param name="quaternion2">The second quaternion.</param>
        /// <returns>The difference of both quaternions.</returns>
        #region public static JQuaternion Subtract(JQuaternion quaternion1, JQuaternion quaternion2)
        public static JQuaternion Subtract(JQuaternion quaternion1, JQuaternion quaternion2)
        {
            JQuaternion result;

            JQuaternion.Subtract(ref quaternion1, ref quaternion2, out result);
            return(result);
        }
Exemple #6
0
 /// <summary>
 /// Quaternions are added.
 /// </summary>
 /// <param name="quaternion1">The first quaternion.</param>
 /// <param name="quaternion2">The second quaternion.</param>
 /// <param name="result">The sum of both quaternions.</param>
 public static void Add(ref JQuaternion quaternion1, ref JQuaternion quaternion2, out JQuaternion result)
 {
     result.X = quaternion1.X + quaternion2.X;
     result.Y = quaternion1.Y + quaternion2.Y;
     result.Z = quaternion1.Z + quaternion2.Z;
     result.W = quaternion1.W + quaternion2.W;
 }
Exemple #7
0
        /// <summary>
        /// Creates a quaternion from a matrix.
        /// </summary>
        /// <param name="matrix">A matrix representing an orientation.</param>
        /// <returns>JQuaternion representing an orientation.</returns>
        #region public static JQuaternion CreateFromMatrix(JMatrix matrix)
        public static JQuaternion CreateFromMatrix(JMatrix matrix)
        {
            JQuaternion result;

            JQuaternion.CreateFromMatrix(ref matrix, out result);
            return(result);
        }
Exemple #8
0
 public static JMatrix CreateFromYawPitchRoll(float yaw, float pitch, float roll)
 {
     JMatrix matrix;
     JQuaternion quaternion;
     JQuaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out quaternion);
     CreateFromQuaternion(ref quaternion, out matrix);
     return matrix;
 }
Exemple #9
0
        public static JQuaternion Conjugate(JQuaternion value)
        {
            JQuaternion quaternion;

            quaternion.X = -value.X;
            quaternion.Y = -value.Y;
            quaternion.Z = -value.Z;
            quaternion.W = value.W;
            return(quaternion);
        }
Exemple #10
0
        /// <summary>
        /// Multiply two quaternions.
        /// </summary>
        /// <param name="quaternion1">The first quaternion.</param>
        /// <param name="quaternion2">The second quaternion.</param>
        /// <param name="result">The product of both quaternions.</param>
        public static void Multiply(ref JQuaternion quaternion1, ref JQuaternion quaternion2, out JQuaternion result)
        {
            float x     = quaternion1.X;
            float y     = quaternion1.Y;
            float z     = quaternion1.Z;
            float w     = quaternion1.W;
            float num4  = quaternion2.X;
            float num3  = quaternion2.Y;
            float num2  = quaternion2.Z;
            float num   = quaternion2.W;
            float num12 = (y * num2) - (z * num3);
            float num11 = (z * num4) - (x * num2);
            float num10 = (x * num3) - (y * num4);
            float num9  = ((x * num4) + (y * num3)) + (z * num2);

            result.X = ((x * num) + (num4 * w)) + num12;
            result.Y = ((y * num) + (num3 * w)) + num11;
            result.Z = ((z * num) + (num2 * w)) + num10;
            result.W = (w * num) - num9;
        }
Exemple #11
0
        /// <summary>
        /// Creates a quaternion from a matrix.
        /// </summary>
        /// <param name="matrix">A matrix representing an orientation.</param>
        /// <param name="result">JQuaternion representing an orientation.</param>
        public static void CreateFromMatrix(ref JMatrix matrix, out JQuaternion result)
        {
            float num8 = (matrix.M11 + matrix.M22) + matrix.M33;

            if (num8 > 0f)
            {
                float num = (float)Math.Sqrt((double)(num8 + 1f));
                result.W = num * 0.5f;
                num      = 0.5f / num;
                result.X = (matrix.M23 - matrix.M32) * num;
                result.Y = (matrix.M31 - matrix.M13) * num;
                result.Z = (matrix.M12 - matrix.M21) * num;
            }
            else if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33))
            {
                float num7 = (float)Math.Sqrt((double)(((1f + matrix.M11) - matrix.M22) - matrix.M33));
                float num4 = 0.5f / num7;
                result.X = 0.5f * num7;
                result.Y = (matrix.M12 + matrix.M21) * num4;
                result.Z = (matrix.M13 + matrix.M31) * num4;
                result.W = (matrix.M23 - matrix.M32) * num4;
            }
            else if (matrix.M22 > matrix.M33)
            {
                float num6 = (float)Math.Sqrt((double)(((1f + matrix.M22) - matrix.M11) - matrix.M33));
                float num3 = 0.5f / num6;
                result.X = (matrix.M21 + matrix.M12) * num3;
                result.Y = 0.5f * num6;
                result.Z = (matrix.M32 + matrix.M23) * num3;
                result.W = (matrix.M31 - matrix.M13) * num3;
            }
            else
            {
                float num5 = (float)Math.Sqrt((double)(((1f + matrix.M33) - matrix.M11) - matrix.M22));
                float num2 = 0.5f / num5;
                result.X = (matrix.M31 + matrix.M13) * num2;
                result.Y = (matrix.M32 + matrix.M23) * num2;
                result.Z = 0.5f * num5;
                result.W = (matrix.M12 - matrix.M21) * num2;
            }
        }
Exemple #12
0
 /// <summary>
 /// Creates a JMatrix representing an orientation from a quaternion.
 /// </summary>
 /// <param name="quaternion">The quaternion the matrix should be created from.</param>
 /// <param name="result">JMatrix representing an orientation.</param>
 public static void CreateFromQuaternion(ref JQuaternion quaternion, out JMatrix result)
 {
     float num9 = quaternion.X * quaternion.X;
     float num8 = quaternion.Y * quaternion.Y;
     float num7 = quaternion.Z * quaternion.Z;
     float num6 = quaternion.X * quaternion.Y;
     float num5 = quaternion.Z * quaternion.W;
     float num4 = quaternion.Z * quaternion.X;
     float num3 = quaternion.Y * quaternion.W;
     float num2 = quaternion.Y * quaternion.Z;
     float num = quaternion.X * quaternion.W;
     result.M11 = 1f - (2f * (num8 + num7));
     result.M12 = 2f * (num6 + num5);
     result.M13 = 2f * (num4 - num3);
     result.M21 = 2f * (num6 - num5);
     result.M22 = 1f - (2f * (num7 + num9));
     result.M23 = 2f * (num2 + num);
     result.M31 = 2f * (num4 + num3);
     result.M32 = 2f * (num2 - num);
     result.M33 = 1f - (2f * (num8 + num9));
 }
Exemple #13
0
 public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out JQuaternion result)
 {
     float num9 = roll * 0.5f;
     float num6 = (float)Math.Sin((double)num9);
     float num5 = (float)Math.Cos((double)num9);
     float num8 = pitch * 0.5f;
     float num4 = (float)Math.Sin((double)num8);
     float num3 = (float)Math.Cos((double)num8);
     float num7 = yaw * 0.5f;
     float num2 = (float)Math.Sin((double)num7);
     float num = (float)Math.Cos((double)num7);
     result.X = ((num * num4) * num5) + ((num2 * num3) * num6);
     result.Y = ((num2 * num3) * num5) - ((num * num4) * num6);
     result.Z = ((num * num3) * num6) - ((num2 * num4) * num5);
     result.W = ((num * num3) * num5) + ((num2 * num4) * num6);
 }
Exemple #14
0
 /// <summary>
 /// Creates a quaternion from a matrix.
 /// </summary>
 /// <param name="matrix">A matrix representing an orientation.</param>
 /// <param name="result">JQuaternion representing an orientation.</param>
 public static void CreateFromMatrix(ref JMatrix matrix, out JQuaternion result)
 {
     float num8 = (matrix.M11 + matrix.M22) + matrix.M33;
     if (num8 > 0f)
     {
         float num = (float)Math.Sqrt((double)(num8 + 1f));
         result.W = num * 0.5f;
         num = 0.5f / num;
         result.X = (matrix.M23 - matrix.M32) * num;
         result.Y = (matrix.M31 - matrix.M13) * num;
         result.Z = (matrix.M12 - matrix.M21) * num;
     }
     else if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33))
     {
         float num7 = (float)Math.Sqrt((double)(((1f + matrix.M11) - matrix.M22) - matrix.M33));
         float num4 = 0.5f / num7;
         result.X = 0.5f * num7;
         result.Y = (matrix.M12 + matrix.M21) * num4;
         result.Z = (matrix.M13 + matrix.M31) * num4;
         result.W = (matrix.M23 - matrix.M32) * num4;
     }
     else if (matrix.M22 > matrix.M33)
     {
         float num6 = (float)Math.Sqrt((double)(((1f + matrix.M22) - matrix.M11) - matrix.M33));
         float num3 = 0.5f / num6;
         result.X = (matrix.M21 + matrix.M12) * num3;
         result.Y = 0.5f * num6;
         result.Z = (matrix.M32 + matrix.M23) * num3;
         result.W = (matrix.M31 - matrix.M13) * num3;
     }
     else
     {
         float num5 = (float)Math.Sqrt((double)(((1f + matrix.M33) - matrix.M11) - matrix.M22));
         float num2 = 0.5f / num5;
         result.X = (matrix.M31 + matrix.M13) * num2;
         result.Y = (matrix.M32 + matrix.M23) * num2;
         result.Z = 0.5f * num5;
         result.W = (matrix.M12 - matrix.M21) * num2;
     }
 }
Exemple #15
0
 public static JQuaternion Conjugate(JQuaternion value)
 {
     JQuaternion quaternion;
     quaternion.X = -value.X;
     quaternion.Y = -value.Y;
     quaternion.Z = -value.Z;
     quaternion.W = value.W;
     return quaternion;
 }
Exemple #16
0
 /// <summary>
 /// Quaternions are added.
 /// </summary>
 /// <param name="quaternion1">The first quaternion.</param>
 /// <param name="quaternion2">The second quaternion.</param>
 /// <param name="result">The sum of both quaternions.</param>
 public static void Add(ref JQuaternion quaternion1, ref JQuaternion quaternion2, out JQuaternion result)
 {
     result.X = quaternion1.X + quaternion2.X;
     result.Y = quaternion1.Y + quaternion2.Y;
     result.Z = quaternion1.Z + quaternion2.Z;
     result.W = quaternion1.W + quaternion2.W;
 }
Exemple #17
0
 public static JQuaternion Add(JQuaternion quaternion1, JQuaternion quaternion2)
 {
     JQuaternion result;
     JQuaternion.Add(ref quaternion1, ref quaternion2, out result);
     return result;
 }
Exemple #18
0
 public static JQuaternion Multiply(JQuaternion quaternion1, JQuaternion quaternion2)
 {
     JQuaternion result;
     JQuaternion.Multiply(ref quaternion1, ref quaternion2, out result);
     return result;
 }
Exemple #19
0
 /// <summary>
 /// Creates a JMatrix representing an orientation from a quaternion.
 /// </summary>
 /// <param name="quaternion">The quaternion the matrix should be created from.</param>
 /// <param name="result">JMatrix representing an orientation.</param>
 public static void CreateFromQuaternion(ref JQuaternion quaternion, out JMatrix result)
 {
     float num9 = quaternion.X * quaternion.X;
     float num8 = quaternion.Y * quaternion.Y;
     float num7 = quaternion.Z * quaternion.Z;
     float num6 = quaternion.X * quaternion.Y;
     float num5 = quaternion.Z * quaternion.W;
     float num4 = quaternion.Z * quaternion.X;
     float num3 = quaternion.Y * quaternion.W;
     float num2 = quaternion.Y * quaternion.Z;
     float num = quaternion.X * quaternion.W;
     result.M11 = 1f - (2f * (num8 + num7));
     result.M12 = 2f * (num6 + num5);
     result.M13 = 2f * (num4 - num3);
     result.M21 = 2f * (num6 - num5);
     result.M22 = 1f - (2f * (num7 + num9));
     result.M23 = 2f * (num2 + num);
     result.M31 = 2f * (num4 + num3);
     result.M32 = 2f * (num2 - num);
     result.M33 = 1f - (2f * (num8 + num9));
 }
Exemple #20
0
 public static JQuaternion Subtract(JQuaternion quaternion1, JQuaternion quaternion2)
 {
     JQuaternion result;
     JQuaternion.Subtract(ref quaternion1, ref quaternion2, out result);
     return result;
 }
Exemple #21
0
 public static JQuaternion Multiply(JQuaternion quaternion1, float scaleFactor)
 {
     JQuaternion result;
     JQuaternion.Multiply(ref quaternion1, scaleFactor, out result);
     return result;
 }
Exemple #22
0
 /// <summary>
 /// Multiply two quaternions.
 /// </summary>
 /// <param name="quaternion1">The first quaternion.</param>
 /// <param name="quaternion2">The second quaternion.</param>
 /// <param name="result">The product of both quaternions.</param>
 public static void Multiply(ref JQuaternion quaternion1, ref JQuaternion quaternion2, out JQuaternion result)
 {
     float x = quaternion1.X;
     float y = quaternion1.Y;
     float z = quaternion1.Z;
     float w = quaternion1.W;
     float num4 = quaternion2.X;
     float num3 = quaternion2.Y;
     float num2 = quaternion2.Z;
     float num = quaternion2.W;
     float num12 = (y * num2) - (z * num3);
     float num11 = (z * num4) - (x * num2);
     float num10 = (x * num3) - (y * num4);
     float num9 = ((x * num4) + (y * num3)) + (z * num2);
     result.X = ((x * num) + (num4 * w)) + num12;
     result.Y = ((y * num) + (num3 * w)) + num11;
     result.Z = ((z * num) + (num2 * w)) + num10;
     result.W = (w * num) - num9;
 }
Exemple #23
0
        public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out JQuaternion result)
        {
            float num9 = roll * 0.5f;
            float num6 = (float)Math.Sin((double)num9);
            float num5 = (float)Math.Cos((double)num9);
            float num8 = pitch * 0.5f;
            float num4 = (float)Math.Sin((double)num8);
            float num3 = (float)Math.Cos((double)num8);
            float num7 = yaw * 0.5f;
            float num2 = (float)Math.Sin((double)num7);
            float num  = (float)Math.Cos((double)num7);

            result.X = ((num * num4) * num5) + ((num2 * num3) * num6);
            result.Y = ((num2 * num3) * num5) - ((num * num4) * num6);
            result.Z = ((num * num3) * num6) - ((num2 * num4) * num5);
            result.W = ((num * num3) * num5) + ((num2 * num4) * num6);
        }
Exemple #24
0
 /// <summary>
 /// Scale a quaternion
 /// </summary>
 /// <param name="quaternion1">The quaternion to scale.</param>
 /// <param name="scaleFactor">Scale factor.</param>
 /// <param name="result">The scaled quaternion.</param>
 public static void Multiply(ref JQuaternion quaternion1, float scaleFactor, out JQuaternion result)
 {
     result.X = quaternion1.X * scaleFactor;
     result.Y = quaternion1.Y * scaleFactor;
     result.Z = quaternion1.Z * scaleFactor;
     result.W = quaternion1.W * scaleFactor;
 }
Exemple #25
0
        /// <summary>
        /// Creates a JMatrix representing an orientation from a quaternion.
        /// </summary>
        /// <param name="quaternion">The quaternion the matrix should be created from.</param>
        /// <returns>JMatrix representing an orientation.</returns>
        #region public static JMatrix CreateFromQuaternion(JQuaternion quaternion)

        public static JMatrix CreateFromQuaternion(JQuaternion quaternion)
        {
            JMatrix result;
            JMatrix.CreateFromQuaternion(ref quaternion,out result);
            return result;
        }
Exemple #26
0
 /// <summary>
 /// Quaternions are subtracted.
 /// </summary>
 /// <param name="quaternion1">The first quaternion.</param>
 /// <param name="quaternion2">The second quaternion.</param>
 /// <param name="result">The difference of both quaternions.</param>
 public static void Subtract(ref JQuaternion quaternion1, ref JQuaternion quaternion2, out JQuaternion result)
 {
     result.X = quaternion1.X - quaternion2.X;
     result.Y = quaternion1.Y - quaternion2.Y;
     result.Z = quaternion1.Z - quaternion2.Z;
     result.W = quaternion1.W - quaternion2.W;
 }
Exemple #27
0
 public static JMatrix CreateFromQuaternion(JQuaternion quaternion)
 {
     JMatrix result;
     JMatrix.CreateFromQuaternion(ref quaternion,out result);
     return result;
 }