Example #1
0
        public static TSMatrix CreateFromQuaternion(TSQuaternion quaternion)
        {
            TSMatrix result;

            TSMatrix.CreateFromQuaternion(ref quaternion, out result);
            return(result);
        }
        /**
         *  @brief Initializes internal properties based on whether there is a {@link TSCollider} attached.
         **/
        public void Initialize()
        {
            if (initialized)
            {
                return;
            }

            tsCollider = GetComponent <TSCollider>();
            if (transform.parent != null)
            {
                tsParent = transform.parent.GetComponent <TSTransform>();
            }

            if (!_serialized)
            {
                UpdateEditMode();
            }

            if (tsCollider != null)
            {
                if (tsCollider.IsBodyInitialized)
                {
                    tsCollider.Body.TSPosition    = _position + scaledCenter;
                    tsCollider.Body.TSOrientation = TSMatrix.CreateFromQuaternion(_rotation);
                }
            }
            else
            {
                StateTracker.AddTracking(this);
            }

            initialized = true;
        }
Example #3
0
        public static TSMatrix CreateFromYawPitchRoll(FP yaw, FP pitch, FP roll)
        {
            TSQuaternion tSQuaternion;

            TSQuaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out tSQuaternion);
            TSMatrix result;

            TSMatrix.CreateFromQuaternion(ref tSQuaternion, out result);
            return(result);
        }
Example #4
0
        private void UpdateChildRotation()
        {
            TSMatrix matrix = TSMatrix.CreateFromQuaternion(_rotation);

            foreach (TSTransform child in tsChildren)
            {
                child.localRotation = TSQuaternion.CreateFromMatrix(TSMatrix.Inverse(matrix)) * _rotation;
                child.localPosition = TSVector.Transform(child.localPosition, TSMatrix.CreateFromQuaternion(child.localRotation));
                child.position      = TransformPoint(child.localPosition);
            }
        }
Example #5
0
        internal void PostStep()
        {
            bool flag = this._freezeConstraints > TSRigidBodyConstraints.None;

            if (flag)
            {
                bool flag2 = (this._freezeConstraints & TSRigidBodyConstraints.FreezePositionX) == TSRigidBodyConstraints.FreezePositionX;
                bool flag3 = (this._freezeConstraints & TSRigidBodyConstraints.FreezePositionY) == TSRigidBodyConstraints.FreezePositionY;
                bool flag4 = (this._freezeConstraints & TSRigidBodyConstraints.FreezePositionZ) == TSRigidBodyConstraints.FreezePositionZ;
                bool flag5 = flag2;
                if (flag5)
                {
                    this.position.x = this._freezePosition.x;
                }
                bool flag6 = flag3;
                if (flag6)
                {
                    this.position.y = this._freezePosition.y;
                }
                bool flag7 = flag4;
                if (flag7)
                {
                    this.position.z = this._freezePosition.z;
                }
                bool flag8  = (this._freezeConstraints & TSRigidBodyConstraints.FreezeRotationX) == TSRigidBodyConstraints.FreezeRotationX;
                bool flag9  = (this._freezeConstraints & TSRigidBodyConstraints.FreezeRotationY) == TSRigidBodyConstraints.FreezeRotationY;
                bool flag10 = (this._freezeConstraints & TSRigidBodyConstraints.FreezeRotationZ) == TSRigidBodyConstraints.FreezeRotationZ;
                bool flag11 = flag8 | flag9 | flag10;
                if (flag11)
                {
                    TSQuaternion quaternion = TSQuaternion.CreateFromMatrix(this.Orientation);
                    bool         flag12     = flag8;
                    if (flag12)
                    {
                        quaternion.x = this._freezeRotationQuat.x;
                    }
                    bool flag13 = flag9;
                    if (flag13)
                    {
                        quaternion.y = this._freezeRotationQuat.y;
                    }
                    bool flag14 = flag10;
                    if (flag14)
                    {
                        quaternion.z = this._freezeRotationQuat.z;
                    }
                    quaternion.Normalize();
                    this.Orientation = TSMatrix.CreateFromQuaternion(quaternion);
                }
            }
        }
Example #6
0
        private void IntegrateCallback(object obj)
        {
            RigidBody rigidBody = obj as RigidBody;
            TSVector  tSVector;

            TSVector.Multiply(ref rigidBody.linearVelocity, this.timestep, out tSVector);
            TSVector.Add(ref tSVector, ref rigidBody.position, out rigidBody.position);
            bool flag = !rigidBody.isParticle;

            if (flag)
            {
                FP       magnitude = rigidBody.angularVelocity.magnitude;
                bool     flag2     = magnitude < FP.EN3;
                TSVector tSVector2;
                if (flag2)
                {
                    TSVector.Multiply(ref rigidBody.angularVelocity, FP.Half * this.timestep - this.timestep * this.timestep * this.timestep * (2082 * FP.EN6) * magnitude * magnitude, out tSVector2);
                }
                else
                {
                    TSVector.Multiply(ref rigidBody.angularVelocity, FP.Sin(FP.Half * magnitude * this.timestep) / magnitude, out tSVector2);
                }
                TSQuaternion tSQuaternion = new TSQuaternion(tSVector2.x, tSVector2.y, tSVector2.z, FP.Cos(magnitude * this.timestep * FP.Half));
                TSQuaternion tSQuaternion2;
                TSQuaternion.CreateFromMatrix(ref rigidBody.orientation, out tSQuaternion2);
                TSQuaternion.Multiply(ref tSQuaternion, ref tSQuaternion2, out tSQuaternion);
                tSQuaternion.Normalize();
                TSMatrix.CreateFromQuaternion(ref tSQuaternion, out rigidBody.orientation);
            }
            bool flag3 = (rigidBody.Damping & RigidBody.DampingType.Linear) > RigidBody.DampingType.None;

            if (flag3)
            {
                TSVector.Multiply(ref rigidBody.linearVelocity, this.currentLinearDampFactor, out rigidBody.linearVelocity);
            }
            bool flag4 = (rigidBody.Damping & RigidBody.DampingType.Angular) > RigidBody.DampingType.None;

            if (flag4)
            {
                TSVector.Multiply(ref rigidBody.angularVelocity, this.currentAngularDampFactor, out rigidBody.angularVelocity);
            }
            rigidBody.Update();
            bool flag5 = this.CollisionSystem.EnableSpeculativeContacts || rigidBody.EnableSpeculativeContacts;

            if (flag5)
            {
                rigidBody.SweptExpandBoundingBox(this.timestep);
            }
        }
Example #7
0
        /**
         *  @brief Initializes internal properties based on whether there is a {@link TSCollider} attached.
         **/
        public void Initialize()
        {
            if (initialized)
            {
                return;
            }

            rb             = GetComponent <TSRigidBody>();
            transformCache = transform;

            tsCollider = GetComponent <TSCollider>();
            if (transformCache.parent != null)
            {
                tsParent = transformCache.parent.GetComponent <TSTransform>();
            }

            foreach (Transform child in transformCache)
            {
                TSTransform tsChild = child.GetComponent <TSTransform>();
                if (tsChild != null)
                {
                    tsChildren.Add(tsChild);
                }
            }

            if (!_serialized)
            {
                UpdateEditMode();
            }

            if (tsCollider != null)
            {
                if (tsCollider.IsBodyInitialized)
                {
                    tsCollider.Body.TSPosition    = _position + scaledCenter;
                    tsCollider.Body.TSOrientation = TSMatrix.CreateFromQuaternion(_rotation);
                }
            }
            else
            {
                StateTracker.AddTracking(this);
            }

            initialized = true;
        }
        /**
         *  @brief Initializes internal properties based on whether there is a {@link TSCollider} attached.
         **/
        public void Initialize()
        {
            if (initialized)
            {
                return;
            }

            tsCollider = GetComponent <TSCollider>();
            if (transform.parent != null)
            {
                tsParent = transform.parent.GetComponent <TSTransform>();
            }

            foreach (Transform child in transform)
            {
                TSTransform tsChild = child.GetComponent <TSTransform>();
                if (tsChild != null)
                {
                    tsChildren.Add(tsChild);
                }
            }

            if (!_serialized)
            {
                UpdateEditMode();
            }

            if (tsCollider != null)
            {
                if (tsCollider.IsBodyInitialized)
                {
                    tsCollider.Body.TSPosition    = _position + scaledCenter;
                    tsCollider.Body.TSOrientation = TSMatrix.CreateFromQuaternion(_rotation);
                }
            }
            else
            {
                //配合 [AddTracking] Attribute 使用, StateTracker.AddTracking(object obj)通过反射获取obj的成员变量
                StateTracker.AddTracking(this);
            }

            initialized = true;
        }
Example #9
0
        private void UpdatePlayMode()
        {
            if (tsParent != null)
            {
                _localPosition = tsParent.InverseTransformPoint(position);
                TSMatrix matrix = TSMatrix.CreateFromQuaternion(tsParent.rotation);
                _localRotation = TSQuaternion.CreateFromMatrix(TSMatrix.Inverse(matrix)) * rotation;
            }
            else
            {
                _localPosition = position;
                _localRotation = rotation;
            }

            if (rb != null)
            {
                transform.position   = position.ToVector();
                transform.rotation   = rotation.ToQuaternion();
                transform.localScale = localScale.ToVector();

                /*if (rb.interpolation == TSRigidBody.InterpolateMode.Interpolate) {
                 *  transform.position = Vector3.Lerp(transform.position, position.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR);
                 *  transform.rotation = Quaternion.Lerp(transform.rotation, rotation.ToQuaternion(), Time.deltaTime * DELTA_TIME_FACTOR);
                 *  transform.localScale = Vector3.Lerp(transform.localScale, localScale.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR);
                 *  return;
                 * } else if (rb.interpolation == TSRigidBody.InterpolateMode.Extrapolate) {
                 *  transform.position = (position + rb.tsCollider.Body.TSLinearVelocity * Time.deltaTime * DELTA_TIME_FACTOR).ToVector();
                 *  transform.rotation = Quaternion.Lerp(transform.rotation, rotation.ToQuaternion(), Time.deltaTime * DELTA_TIME_FACTOR);
                 *  transform.localScale = Vector3.Lerp(transform.localScale, localScale.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR);
                 *  return;
                 * }*/
            }

            transform.position   = position.ToVector();
            transform.rotation   = rotation.ToQuaternion();
            transform.localScale = localScale.ToVector();
            _scale = transform.lossyScale.ToTSVector();
        }
Example #10
0
        public override void PostStep()
        {
            TSVector position = base.Body1.Position;

            position.z          = 0;
            base.Body1.Position = position;
            TSQuaternion quaternion = TSQuaternion.CreateFromMatrix(base.Body1.Orientation);

            quaternion.Normalize();
            quaternion.x = 0;
            quaternion.y = 0;
            bool flag = this.freezeZAxis;

            if (flag)
            {
                quaternion.z = 0;
            }
            base.Body1.Orientation = TSMatrix.CreateFromQuaternion(quaternion);
            bool isStatic = base.Body1.isStatic;

            if (!isStatic)
            {
                TSVector linearVelocity = base.Body1.LinearVelocity;
                linearVelocity.z          = 0;
                base.Body1.LinearVelocity = linearVelocity;
                TSVector angularVelocity = base.Body1.AngularVelocity;
                angularVelocity.x = 0;
                angularVelocity.y = 0;
                bool flag2 = this.freezeZAxis;
                if (flag2)
                {
                    angularVelocity.z = 0;
                }
                base.Body1.AngularVelocity = angularVelocity;
            }
        }
Example #11
0
 /**
  *  @brief Moves game object based on provided translation vector and a relative {@link TSTransform}.
  *
  *  The game object will move based on TSTransform's forward vector.
  **/
 public void Translate(TSVector translation, TSTransform relativeTo)
 {
     this.position += TSVector.Transform(translation, TSMatrix.CreateFromQuaternion(relativeTo.rotation));
 }