Box2D.Dynamics.Body.SetMassData C# (CSharp) Method

SetMassData() public method

Set the mass properties to override the mass properties of the fixtures. Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.
public SetMassData ( MassData massData ) : void
massData Box2D.Collision.Shapes.MassData the mass properties.
return void
        public void SetMassData(MassData massData)
        {
            // TODO_ERIN adjust linear velocity and torque to account for movement of center.
            Debug.Assert(World.Locked == false);
            if (World.Locked)
            {
                return;
            }

            if (m_type != BodyType.Dynamic)
            {
                return;
            }

            InvMass = 0.0f;
            I = 0.0f;
            InvI = 0.0f;

            Mass = massData.Mass;
            if (Mass <= 0.0f)
            {
                Mass = 1f;
            }

            InvMass = 1.0f / Mass;

            if (massData.I > 0.0f && (Flags & TypeFlags.FixedRotation) == 0)
            {
                I = massData.I - Mass * Vec2.Dot(massData.Center, massData.Center);
                Debug.Assert(I > 0.0f);
                InvI = 1.0f / I;
            }

            Vec2 oldCenter = World.Pool.PopVec2();
            // Move center of mass.
            oldCenter.Set(Sweep.C);
            Sweep.LocalCenter.Set(massData.Center);
            // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
            Transform.MulToOutUnsafe(Xf, Sweep.LocalCenter, Sweep.C0);
            Sweep.C.Set(Sweep.C0);

            // Update center of mass velocity.
            // m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
            Vec2 temp = World.Pool.PopVec2();
            temp.Set(Sweep.C).SubLocal(oldCenter);
            Vec2.CrossToOut(m_angularVelocity, temp, temp);
            m_linearVelocity.AddLocal(temp);

            World.Pool.PushVec2(2);
        }