Esempio n. 1
0
        private void SetInertiaTensor()
        {
            if (!IsStatic)
            {
                InitCenterOfMass = ShapeCommonUtilities.CalculateCenterOfMass(
                    Vertices,
                    ObjectGeometry.BaseGeometry.Triangle,
                    MassInfo.Mass);

                Matrix3x3 baseTensors = ShapeCommonUtilities.GetInertiaTensor(
                    Vertices,
                    ObjectGeometry.BaseGeometry.Triangle,
                    InitCenterOfMass,
                    MassInfo.Mass).InertiaTensor;

                MassInfo.InverseBaseInertiaTensor = Matrix3x3.Invert(baseTensors);

                MassInfo.InverseInertiaTensor = (RotationMatrix * MassInfo.InverseBaseInertiaTensor) *
                                                Matrix3x3.Transpose(RotationMatrix);
            }
            else
            {
                MassInfo.InverseBaseInertiaTensor = Matrix3x3.IdentityMatrix(0.0);
                MassInfo.InverseInertiaTensor     = Matrix3x3.IdentityMatrix(0.0);
            }
        }
        private Vector3d CalculateCenterOfMass()
        {
            Vector3d startPosition = new Vector3d();

            for (int i = 0; i < ShapesGeometry.Length; i++)
            {
                Vector3d[] vertices = ShapesGeometry[i].GetVertices();

                var centerOfMass = ShapeCommonUtilities.CalculateCenterOfMass(
                    vertices,
                    ShapesGeometry[i].BaseGeometry.Triangle,
                    PartialMass[i]);

                startPosition += centerOfMass * PartialMass[i];
            }

            if (MassInfo.Mass > 0.0)
            {
                return(startPosition / MassInfo.Mass);
            }

            return(Vector3d.ToZero());
        }