示例#1
0
        public void ReInitializeData(Vector3 positionXNA, Material mat, Vector3 halfSize)
        {
            this.HalfSize             = halfSize;
            this.PositionCenterEngine = MathHelperModule.GetPositionCenter(positionXNA, halfSize.X, halfSize.Y);
            this.RectangleArea        = MathHelperModule.GetBoxRigid2DCoordinatesPositionCenter(this.PositionCenterEngine, halfSize.X,
                                                                                                halfSize.Y);

            XAxis = new Vector3(1, 0, 0);
            YAxis = new Vector3(0, 1, 0);
            XAxis.Normalize();
            YAxis.Normalize();

            SetMaterial(mat);
            SetMass(HalfSize);

            this.InvMass = 1 / Mass;

            baseMomentOfInertia = Mass * Math.Max(HalfSize.X, HalfSize.Y) * Math.Max(HalfSize.X, HalfSize.Y) * 4 / 12f;
            dAngle   = 0;
            vertices = new VertexPositionColor[5];
            velocity = new Vector3(0, 0, 0);

            InverseInertiaTensorWorld         = new Matrix();
            InverseInertiaTensorWorld.M11     =
                InverseInertiaTensorWorld.M22 = InverseInertiaTensorWorld.M33 = (float)1 / baseMomentOfInertia;
            InverseInertiaTensorWorld.M44     = 1;

            vertices[0].Position = this.PositionCenterEngine + new Vector3(HalfSize.X, HalfSize.Y, 0);
            vertices[1].Position = this.PositionCenterEngine + new Vector3(-HalfSize.X, HalfSize.Y, 0);
            vertices[2].Position = this.PositionCenterEngine + new Vector3(-HalfSize.X, -HalfSize.Y, 0);
            vertices[3].Position = this.PositionCenterEngine + new Vector3(HalfSize.X, -HalfSize.Y, 0);
            vertices[4].Position = this.PositionCenterEngine + new Vector3(HalfSize.X, HalfSize.Y, 0);
        }