示例#1
0
        public static TSMatrix operator *(TSMatrix value1, TSMatrix value2)
        {
            TSMatrix result;

            TSMatrix.Multiply(ref value1, ref value2, out result);
            return(result);
        }
示例#2
0
 public void Rotate(TSMatrix orientation, TSVector center)
 {
     for (int i = 0; i < this.points.Count; i++)
     {
         this.points[i].position = TSVector.Transform(this.points[i].position - center, orientation);
     }
 }
示例#3
0
        public static TSMatrix CreateFromLookAt(TSVector position, TSVector target)
        {
            TSMatrix result;

            TSMatrix.LookAt(out result, position, target);
            return(result);
        }
示例#4
0
        public virtual void Update()
        {
            bool flag = this.isParticle;

            if (flag)
            {
                this.inertia        = TSMatrix.Zero;
                this.invInertia     = (this.invInertiaWorld = TSMatrix.Zero);
                this.invOrientation = (this.orientation = TSMatrix.Identity);
                this.boundingBox    = this.shape.boundingBox;
                TSVector.Add(ref this.boundingBox.min, ref this.position, out this.boundingBox.min);
                TSVector.Add(ref this.boundingBox.max, ref this.position, out this.boundingBox.max);
                this.angularVelocity.MakeZero();
            }
            else
            {
                TSMatrix.Transpose(ref this.orientation, out this.invOrientation);
                this.Shape.GetBoundingBox(ref this.orientation, out this.boundingBox);
                TSVector.Add(ref this.boundingBox.min, ref this.position, out this.boundingBox.min);
                TSVector.Add(ref this.boundingBox.max, ref this.position, out this.boundingBox.max);
                bool flag2 = !this.isStatic;
                if (flag2)
                {
                    TSMatrix.Multiply(ref this.invOrientation, ref this.invInertia, out this.invInertiaWorld);
                    TSMatrix.Multiply(ref this.invInertiaWorld, ref this.orientation, out this.invInertiaWorld);
                }
            }
        }
示例#5
0
 public void SetMassProperties(TSMatrix inertia, FP mass, bool setAsInverseValues)
 {
     if (setAsInverseValues)
     {
         bool flag = !this.isParticle;
         if (flag)
         {
             this.invInertia = inertia;
             TSMatrix.Inverse(ref inertia, out this.inertia);
         }
         this.inverseMass = mass;
     }
     else
     {
         bool flag2 = !this.isParticle;
         if (flag2)
         {
             this.inertia = inertia;
             TSMatrix.Inverse(ref inertia, out this.invInertia);
         }
         this.inverseMass = FP.One / mass;
     }
     this.useShapeMassProperties = false;
     this.Update();
 }
示例#6
0
 public void SetMassProperties()
 {
     this.inertia = this.Shape.inertia;
     TSMatrix.Inverse(ref this.inertia, out this.invInertia);
     this.inverseMass            = FP.One / this.Shape.mass;
     this.useShapeMassProperties = true;
 }
示例#7
0
        public static TSMatrix operator +(TSMatrix value1, TSMatrix value2)
        {
            TSMatrix result;

            TSMatrix.Add(ref value1, ref value2, out result);
            return(result);
        }
示例#8
0
        public static TSVector Transform(TSVector position, TSMatrix matrix)
        {
            TSVector result;

            TSVector.Transform(ref position, ref matrix, out result);
            return(result);
        }
示例#9
0
        /**
         *  @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;
        }
示例#10
0
        public static TSMatrix Add(TSMatrix matrix1, TSMatrix matrix2)
        {
            TSMatrix result;

            TSMatrix.Add(ref matrix1, ref matrix2, out result);
            return(result);
        }
示例#11
0
        public static TSMatrix AngleAxis(FP angle, TSVector axis)
        {
            TSMatrix result;

            TSMatrix.CreateFromAxisAngle(ref axis, angle, out result);
            return(result);
        }
示例#12
0
        public static TSMatrix Multiply(TSMatrix matrix1, long scaleFactor)
        {
            TSMatrix result;

            TSMatrix.Multiply(ref matrix1, scaleFactor, out result);
            return(result);
        }
示例#13
0
        public static TSMatrix Multiply(TSMatrix matrix1, TSMatrix matrix2)
        {
            TSMatrix result;

            TSMatrix.Multiply(ref matrix1, ref matrix2, out result);
            return(result);
        }
示例#14
0
        public static TSMatrix CreateFromQuaternion(TSQuaternion quaternion)
        {
            TSMatrix result;

            TSMatrix.CreateFromQuaternion(ref quaternion, out result);
            return(result);
        }
示例#15
0
        public RigidBody(Shape shape, BodyMaterial material, bool isParticle)
        {
            this.readOnlyArbiters    = new ReadOnlyHashset <Arbiter>(this.arbiters);
            this.readOnlyConstraints = new ReadOnlyHashset <Constraint>(this.constraints);
            RigidBody.instanceCount++;
            this.instance    = RigidBody.instanceCount;
            this.hashCode    = this.CalculateHash(this.instance);
            this.Shape       = shape;
            this.orientation = TSMatrix.Identity;
            bool flag = !isParticle;

            if (flag)
            {
                this.updatedHandler      = new ShapeUpdatedHandler(this.ShapeUpdated);
                this.Shape.ShapeUpdated += this.updatedHandler;
                this.SetMassProperties();
            }
            else
            {
                this.inertia        = TSMatrix.Zero;
                this.invInertia     = (this.invInertiaWorld = TSMatrix.Zero);
                this.invOrientation = (this.orientation = TSMatrix.Identity);
                this.inverseMass    = FP.One;
            }
            this.material                  = material;
            this.AllowDeactivation         = true;
            this.EnableSpeculativeContacts = false;
            this.isParticle                = isParticle;
            this.Update();
        }
示例#16
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 TSQuaternion CreateFromMatrix(TSMatrix matrix)
        {
            TSQuaternion result;

            TSQuaternion.CreateFromMatrix(ref matrix, out result);
            return(result);
        }
示例#17
0
        public static TSMatrix Transpose(TSMatrix matrix)
        {
            TSMatrix result;

            TSMatrix.Transpose(ref matrix, out result);
            return(result);
        }
示例#18
0
        public static TSMatrix operator -(TSMatrix value1, TSMatrix value2)
        {
            TSMatrix result; TSMatrix.Multiply(ref value2, -FP.One, out value2);

            TSMatrix.Add(ref value1, ref value2, out result);
            return(result);
        }
示例#19
0
        public static void Invert(ref TSMatrix matrix, out TSMatrix result)
        {
            FP determinantInverse = 1 / matrix.Determinant();
            FP m11 = (matrix.M22 * matrix.M33 - matrix.M23 * matrix.M32) * determinantInverse;
            FP m12 = (matrix.M13 * matrix.M32 - matrix.M33 * matrix.M12) * determinantInverse;
            FP m13 = (matrix.M12 * matrix.M23 - matrix.M22 * matrix.M13) * determinantInverse;

            FP m21 = (matrix.M23 * matrix.M31 - matrix.M21 * matrix.M33) * determinantInverse;
            FP m22 = (matrix.M11 * matrix.M33 - matrix.M13 * matrix.M31) * determinantInverse;
            FP m23 = (matrix.M13 * matrix.M21 - matrix.M11 * matrix.M23) * determinantInverse;

            FP m31 = (matrix.M21 * matrix.M32 - matrix.M22 * matrix.M31) * determinantInverse;
            FP m32 = (matrix.M12 * matrix.M31 - matrix.M11 * matrix.M32) * determinantInverse;
            FP m33 = (matrix.M11 * matrix.M22 - matrix.M12 * matrix.M21) * determinantInverse;

            result.M11 = m11;
            result.M12 = m12;
            result.M13 = m13;

            result.M21 = m21;
            result.M22 = m22;
            result.M23 = m23;

            result.M31 = m31;
            result.M32 = m32;
            result.M33 = m33;
        }
示例#20
0
        public static TSMatrix Inverse(TSMatrix matrix)
        {
            TSMatrix result;

            TSMatrix.Inverse(ref matrix, out result);
            return(result);
        }
示例#21
0
 static TSMatrix()
 {
     TSMatrix.Zero             = default(TSMatrix);
     TSMatrix.Identity         = default(TSMatrix);
     TSMatrix.Identity.M11     = FP.One;
     TSMatrix.Identity.M22     = FP.One;
     TSMatrix.Identity.M33     = FP.One;
     TSMatrix.InternalIdentity = TSMatrix.Identity;
 }
示例#22
0
 public override void GetBoundingBox(ref TSMatrix orientation, out TSBBox box)
 {
     box.min.x = -this.radius;
     box.min.y = -this.radius;
     box.min.z = -this.radius;
     box.max.x = this.radius;
     box.max.y = this.radius;
     box.max.z = this.radius;
 }
示例#23
0
 public TransformedShape(Shape shape, TSMatrix orientation, TSVector position)
 {
     this.position    = position;
     this.orientation = orientation;
     TSMatrix.Transpose(ref orientation, out this.invOrientation);
     this.shape       = shape;
     this.boundingBox = default(TSBBox);
     this.UpdateBoundingBox();
 }
示例#24
0
        /// <summary>
        /// Transforms a vector by the transposed of the given Matrix.
        /// </summary>
        /// <param name="position">The vector to transform.</param>
        /// <param name="matrix">The transform matrix.</param>
        /// <param name="result">The transformed vector.</param>
        public static void TransposedTransform(ref TSVector position, ref TSMatrix matrix, out TSVector result)
        {
            FP num0 = ((position.x * matrix.M11) + (position.y * matrix.M12)) + (position.z * matrix.M13);
            FP num1 = ((position.x * matrix.M21) + (position.y * matrix.M22)) + (position.z * matrix.M23);
            FP num2 = ((position.x * matrix.M31) + (position.y * matrix.M32)) + (position.z * matrix.M33);

            result.x = num0;
            result.y = num1;
            result.z = num2;
        }
示例#25
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);
        }
示例#26
0
        public static void TransposedTransform(ref TSVector position, ref TSMatrix matrix, out TSVector result)
        {
            FP fP  = position.x * matrix.M11 + position.y * matrix.M12 + position.z * matrix.M13;
            FP fP2 = position.x * matrix.M21 + position.y * matrix.M22 + position.z * matrix.M23;
            FP fP3 = position.x * matrix.M31 + position.y * matrix.M32 + position.z * matrix.M33;

            result.x = fP;
            result.y = fP2;
            result.z = fP3;
        }
示例#27
0
        /**
         *  @brief Rotates game object based on provided axis, point and angle of rotation.
         **/
        public void RotateAround(TSVector point, TSVector axis, FP angle)
        {
            TSVector vector  = this.position;
            TSVector vector2 = vector - point;

            vector2       = TSVector.Transform(vector2, TSMatrix.AngleAxis(angle * FP.Deg2Rad, axis));
            vector        = point + vector2;
            this.position = vector;

            Rotate(axis, angle);
        }
示例#28
0
        static TSMatrix()
        {
            Zero = new TSMatrix();

            Identity     = new TSMatrix();
            Identity.M11 = FP.One;
            Identity.M22 = FP.One;
            Identity.M33 = FP.One;

            InternalIdentity = Identity;
        }
示例#29
0
        public override void GetBoundingBox(ref TSMatrix orientation, out TSBBox box)
        {
            TSMatrix tSMatrix;

            TSMath.Absolute(ref orientation, out tSMatrix);
            TSVector max;

            TSVector.Transform(ref this.halfSize, ref tSMatrix, out max);
            box.max = max;
            TSVector.Negate(ref max, out box.min);
        }
示例#30
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);
            }
        }