A Quaternion representing an orientation. Member of the math namespace, so every method has it's 'by reference' equivalent to speed up time critical math operations.
Пример #1
0
        /// <summary>
        /// Quaternions are added.
        /// </summary>
        /// <param name="quaternion1">The first quaternion.</param>
        /// <param name="quaternion2">The second quaternion.</param>
        /// <returns>The sum of both quaternions.</returns>
        #region public static JQuaternion Add(JQuaternion quaternion1, JQuaternion quaternion2)
        public static JQuaternion Add(JQuaternion quaternion1, JQuaternion quaternion2)
        {
            JQuaternion result;

            JQuaternion.Add(ref quaternion1, ref quaternion2, out result);
            return(result);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Add two quaternions.
        /// </summary>
        /// <param name="value1">The first quaternion.</param>
        /// <param name="value2">The second quaternion.</param>
        /// <returns>The sum of both quaternions.</returns>
        #region public static float operator +(JQuaternion value1, JQuaternion value2)
        public static JQuaternion operator +(JQuaternion value1, JQuaternion value2)
        {
            JQuaternion result;

            JQuaternion.Add(ref value1, ref value2, out result);
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Subtract two quaternions.
        /// </summary>
        /// <param name="value1">The first quaternion.</param>
        /// <param name="value2">The second quaternion.</param>
        /// <returns>The difference of both quaternions.</returns>
        #region public static float operator -(JQuaternion value1, JQuaternion value2)
        public static JQuaternion operator -(JQuaternion value1, JQuaternion value2)
        {
            JQuaternion result;

            JQuaternion.Subtract(ref value1, ref value2, out result);
            return(result);
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Multiply two quaternions.
        /// </summary>
        /// <param name="value1">The first quaternion.</param>
        /// <param name="value2">The second quaternion.</param>
        /// <returns>The product of both quaternions.</returns>
        #region public static float operator *(JQuaternion value1, JQuaternion value2)
        public static JQuaternion operator *(JQuaternion value1, JQuaternion value2)
        {
            JQuaternion result;

            JQuaternion.Multiply(ref value1, ref value2, out result);
            return(result);
        }
Пример #7
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);
        }
Пример #8
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;
 }
Пример #9
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);
        }
Пример #10
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;
 }
Пример #11
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);
        }
Пример #12
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;
 }
Пример #13
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);
        }
        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);
        }
Пример #15
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);
 }
        /// <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;
        }
        /// <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;
            }
        }
Пример #18
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));
        }
Пример #19
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;
 }
 /// <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)
 {
     Multiply(ref quaternion1, ref quaternion2, out var result);
     return(result);
 }
 /// <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)
 {
     Subtract(ref quaternion1, ref quaternion2, out var result);
     return(result);
 }
Пример #22
0
 public static JMatrix CreateFromYawPitchRoll(float yaw, float pitch, float roll)
 {
     JQuaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out var quaternion);
     CreateFromQuaternion(quaternion, out var matrix);
     return(matrix);
 }
Пример #23
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)
        {
            CreateFromQuaternion(ref quaternion, out var result);
            return(result);
        }
Пример #24
0
 /// <summary>
 /// Quaternions are added.
 /// </summary>
 /// <param name="quaternion1">The first quaternion.</param>
 /// <param name="quaternion2">The second quaternion.</param>
 /// <returns>The sum of both quaternions.</returns>
 #region public static JQuaternion Add(JQuaternion quaternion1, JQuaternion quaternion2)
 public static JQuaternion Add(JQuaternion quaternion1, JQuaternion quaternion2)
 {
     JQuaternion result;
     JQuaternion.Add(ref quaternion1, ref quaternion2, out result);
     return result;
 }
Пример #25
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;
     }
 }
Пример #26
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;
 }
Пример #27
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;
 }
Пример #28
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;
 }
Пример #29
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)
 {
     double num9 = quaternion.X * quaternion.X;
     double num8 = quaternion.Y * quaternion.Y;
     double num7 = quaternion.Z * quaternion.Z;
     double num6 = quaternion.X * quaternion.Y;
     double num5 = quaternion.Z * quaternion.W;
     double num4 = quaternion.Z * quaternion.X;
     double num3 = quaternion.Y * quaternion.W;
     double num2 = quaternion.Y * quaternion.Z;
     double 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));
 }
        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);
        }
 /// <summary>
 /// Quaternions are added.
 /// </summary>
 /// <param name="quaternion1">The first quaternion.</param>
 /// <param name="quaternion2">The second quaternion.</param>
 /// <returns>The sum of both quaternions.</returns>
 #region public static JQuaternion Add(JQuaternion quaternion1, JQuaternion quaternion2)
 public static JQuaternion Add(JQuaternion quaternion1, JQuaternion quaternion2)
 {
     Add(ref quaternion1, ref quaternion2, out var result);
     return(result);
 }
Пример #32
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;
 }
Пример #33
0
 public static JMatrix CreateFromQuaternion(JQuaternion quaternion)
 {
     JMatrix result;
     JMatrix.CreateFromQuaternion(ref quaternion,out result);
     return result;
 }
Пример #34
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;
 }
Пример #35
0
        private void IntegrateCallback(object obj)
        {
            RigidBody body = obj as RigidBody;

            JVector temp;
            JVector.Multiply(ref body.linearVelocity, timestep, out temp);
            JVector.Add(ref temp, ref body.position, out body.position);

            if (!(body.isParticle))
            {

                //exponential map
                JVector axis;
                float angle = body.angularVelocity.Length();

                if (angle < 0.001f)
                {
                    // use Taylor's expansions of sync function
                    // axis = body.angularVelocity * (0.5f * timestep - (timestep * timestep * timestep) * (0.020833333333f) * angle * angle);
                    JVector.Multiply(ref body.angularVelocity, (0.5f * timestep - (timestep * timestep * timestep) * (0.020833333333f) * angle * angle), out axis);
                }
                else
                {
                    // sync(fAngle) = sin(c*fAngle)/t
                    JVector.Multiply(ref body.angularVelocity, ((float)Math.Sin(0.5f * angle * timestep) / angle), out axis);
                }

                JQuaternion dorn = new JQuaternion(axis.X, axis.Y, axis.Z, (float)Math.Cos(angle * timestep * 0.5f));
                JQuaternion ornA; JQuaternion.CreateFromMatrix(ref body.orientation, out ornA);

                JQuaternion.Multiply(ref dorn, ref ornA, out dorn);

                dorn.Normalize(); JMatrix.CreateFromQuaternion(ref dorn, out body.orientation);
            }

            if ((body.Damping & RigidBody.DampingType.Linear) != 0)
                JVector.Multiply(ref body.linearVelocity, currentLinearDampFactor, out body.linearVelocity);

            if ((body.Damping & RigidBody.DampingType.Angular) != 0)
                JVector.Multiply(ref body.angularVelocity, currentAngularDampFactor, out body.angularVelocity);

            body.Update();

            
            if (CollisionSystem.EnableSpeculativeContacts || body.EnableSpeculativeContacts)
                body.SweptExpandBoundingBox(timestep);
        }
Пример #36
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;
 }
Пример #37
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;
 }
Пример #38
0
	    public void RestoreState(BinaryReader reader)
	    {
            Body.Position = new JVector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            var q = new JQuaternion(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            Body.Orientation = JMatrix.CreateFromQuaternion(q);
            if (Body.IsStatic) return;
            Body.LinearVelocity = new JVector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            Body.AngularVelocity = new JVector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
	    }