Exemplo n.º 1
0
        public void SetFromToRotation(TSVector fromDirection, TSVector toDirection)
        {
            TSQuaternion targetRotation = TSQuaternion.FromToRotation(fromDirection, toDirection);

            this.Set(targetRotation.x, targetRotation.y, targetRotation.z, targetRotation.w);
        }
Exemplo n.º 2
0
        /**
         * @brief Instantiates a new prefab in a deterministic way.
         *
         * @param prefab GameObject's prefab to instantiate.
         * @param position Position to place the new GameObject.
         * @param rotation Rotation to set in the new GameObject.
         **/
        public static GameObject SyncedInstantiate(GameObject prefab, TSVector position, TSQuaternion rotation)
        {
            GameObject go = GameObject.Instantiate(prefab, position.ToVector(), rotation.ToQuaternion()) as GameObject;

            InitializeGameObject(go, position, rotation);
            return(go);
        }
Exemplo n.º 3
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 TSQuaternion quaternion1, ref TSQuaternion quaternion2, out TSQuaternion result)
        {
            FP x     = quaternion1.x;
            FP y     = quaternion1.y;
            FP z     = quaternion1.z;
            FP w     = quaternion1.w;
            FP num4  = quaternion2.x;
            FP num3  = quaternion2.y;
            FP num2  = quaternion2.z;
            FP num   = quaternion2.w;
            FP num12 = (y * num2) - (z * num3);
            FP num11 = (z * num4) - (x * num2);
            FP num10 = (x * num3) - (y * num4);
            FP 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;
        }
Exemplo n.º 4
0
 static TSQuaternion()
 {
     identity = new TSQuaternion(0, 0, 0, 1);
 }
Exemplo n.º 5
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 TSQuaternion quaternion1, ref TSQuaternion quaternion2, out TSQuaternion 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;
 }
Exemplo n.º 6
0
        public static TSQuaternion Lerp(TSQuaternion a, TSQuaternion b, FP t)
        {
            t = TSMath.Clamp(t, FP.Zero, FP.One);

            return(LerpUnclamped(a, b, t));
        }
Exemplo n.º 7
0
        public static TSQuaternion Inverse(TSQuaternion rotation)
        {
            FP invNorm = FP.One / ((rotation.x * rotation.x) + (rotation.y * rotation.y) + (rotation.z * rotation.z) + (rotation.w * rotation.w));

            return(TSQuaternion.Multiply(TSQuaternion.Conjugate(rotation), invNorm));
        }
Exemplo n.º 8
0
 public static FP Dot(TSQuaternion a, TSQuaternion b)
 {
     return(a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z);
 }
Exemplo n.º 9
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 TSQuaternion quaternion1, ref TSQuaternion quaternion2, out TSQuaternion 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;
 }