Example #1
0
 public static TSQuaternion Euler(TSVector eulerAngles)
 {
     return(TSQuaternion.Euler(eulerAngles.x, eulerAngles.y, eulerAngles.z));
 }
Example #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)
        {
            if (instance != null && instance.lockstep != null)
            {
                GameObject go = GameObject.Instantiate(prefab, position.ToVector(), rotation.ToQuaternion()) as GameObject;

                if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
                {
                    AddGameObjectOnSafeMap(go);
                }

                MonoBehaviour[] monoBehaviours = go.GetComponentsInChildren <MonoBehaviour>();
                for (int index = 0, length = monoBehaviours.Length; index < length; index++)
                {
                    MonoBehaviour bh = monoBehaviours[index];

                    if (bh is ITrueSyncBehaviour)
                    {
                        instance.queuedBehaviours.Add(instance.NewManagedBehavior((ITrueSyncBehaviour)bh));//先加入缓存列表,等下一个帧才加入到逻辑列表去
                    }
                }

                InitializeGameObject(go, position, rotation);

                return(go);
            }

            return(null);
        }
Example #3
0
 static TSQuaternion()
 {
     TSQuaternion.identity = new TSQuaternion(0, 0, 0, 1);
 }
Example #4
0
        public void SetFromToRotation(TSVector fromDirection, TSVector toDirection)
        {
            TSQuaternion tSQuaternion = TSQuaternion.FromToRotation(fromDirection, toDirection);

            this.Set(tSQuaternion.x, tSQuaternion.y, tSQuaternion.z, tSQuaternion.w);
        }
Example #5
0
    public static Quaternion ToQuaternion(TrueSync.TSQuaternion q)
    {
        Quaternion ret = new Quaternion(q.x.AsFloat(), q.y.AsFloat(), q.z.AsFloat(), q.w.AsFloat());

        return(ret);
    }
Example #6
0
        public static void Multiply(ref TSQuaternion quaternion1, ref TSQuaternion quaternion2, out TSQuaternion result)
        {
            FP fP   = quaternion1.x;
            FP fP2  = quaternion1.y;
            FP fP3  = quaternion1.z;
            FP fP4  = quaternion1.w;
            FP fP5  = quaternion2.x;
            FP fP6  = quaternion2.y;
            FP fP7  = quaternion2.z;
            FP fP8  = quaternion2.w;
            FP fP9  = fP2 * fP7 - fP3 * fP6;
            FP fP10 = fP3 * fP5 - fP * fP7;
            FP fP11 = fP * fP6 - fP2 * fP5;
            FP fP12 = fP * fP5 + fP2 * fP6 + fP3 * fP7;

            result.x = fP * fP8 + fP5 * fP4 + fP9;
            result.y = fP2 * fP8 + fP6 * fP4 + fP10;
            result.z = fP3 * fP8 + fP7 * fP4 + fP11;
            result.w = fP4 * fP8 - fP12;
        }
Example #7
0
        public static TSQuaternion Inverse(TSQuaternion rotation)
        {
            FP scaleFactor = FP.One / (rotation.x * rotation.x + rotation.y * rotation.y + rotation.z * rotation.z + rotation.w * rotation.w);

            return(TSQuaternion.Multiply(TSQuaternion.Conjugate(rotation), scaleFactor));
        }
Example #8
0
 /**
  *  @brief Changes orientation to look at target position.
  *
  *  @param target A {@link TSVector} representing the position to look at.
  **/
 public void LookAt(TSVector target)
 {
     rotation = TSQuaternion.CreateFromMatrix(TSMatrix.CreateFromLookAt(position, target));
 }
Example #9
0
 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;
 }
Example #10
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);
 }
Example #11
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;
        }
Example #12
0
        /// <summary>
        /// DV 返回反向的旋转。
        /// 例子:设置这个变换具有target相反的旋转
        /// transform.rotation = Quaternion.Inverse(target.rotation);
        /// </summary
        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));
        }
Example #13
0
 public static TrueSync.TSQuaternion ToTSQuaternion(Quaternion q)
 {
     TrueSync.TSQuaternion ret = new TrueSync.TSQuaternion(q.x, q.y, q.z, q.w);
     return(ret);
 }
Example #14
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, TSVector2 position, TSQuaternion rotation)
 {
     return(SyncedInstantiate(prefab, new TSVector(position.x, position.y, 0), rotation));
 }
Example #15
0
 public static TSQuaternion Lerp(TSQuaternion a, TSQuaternion b, FP t)
 {
     t = TSMath.Clamp(t, FP.Zero, FP.One);
     return(TSQuaternion.LerpUnclamped(a, b, t));
 }
 /**
  *  @brief Changes orientation to look at target position.
  *
  *  @param target A {@link TSVector} representing the position to look at.
  **/
 public void LookAt(TSVector target)
 {
     rotation = TSQuaternion.CreateFromMatrix(TSMatrix.CreateFromLookAt(position, target));
     tsCollider.Body.TSUpdate();
 }
Example #17
0
 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;
 }
Example #18
0
 /**
  *  @brief Rotates the body to a provided rotation.
  **/
 public void MoveRotation(TSQuaternion rot)
 {
     this.rotation = rot;
 }
Example #19
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)
        {
            if (instance != null && instance.lockstep != null)
            {
                GameObject go = GameObject.Instantiate(prefab, position.ToVector(), rotation.ToQuaternion()) as GameObject;
                AddGameObjectOnSafeMap(go);

                foreach (MonoBehaviour bh in go.GetComponentsInChildren <MonoBehaviour>())
                {
                    if (bh is ITrueSyncBehaviour)
                    {
                        instance.queuedBehaviours.Add(instance.NewManagedBehavior((ITrueSyncBehaviour)bh));
                    }
                }

                InitializeGameObject(go, position, rotation);

                return(go);
            }

            return(null);
        }