/// Get the mass data of the body. The rotational inertia is relative
/// to the center of mass.
/// @return a struct containing the mass, inertia and center of the body.
public void GetMassData(out MassData data)
{
data = new MassData();
data.Mass = _mass;
data.I = _I;
Vec2 center = Vec2.Zero;
for (Fixture f = _fixtureList; f != null; f = f._next)
{
MassData massData = f.GetMassData();
_mass += massData.Mass;
center += massData.Mass * massData.Center;
_I += massData.I;
}
// Compute center of mass.
if (_mass > 0.0f)
{
_invMass = 1.0f / _mass;
center *= _invMass;
}
if (_I > 0.0f && (_flags & BodyFlags.FixedRotation) == 0)
{
// Center the inertia about the center of mass.
_I -= _mass * Vec2.Dot(center, center);
Box2DXDebug.Assert(_I > 0.0f);
_invI = 1.0f / _I;
}
else
{
_I = 0.0f;
_invI = 0.0f;
}
// Move center of mass.
Vec2 oldCenter = _sweep.C;
_sweep.LocalCenter = center;
_sweep.C0 = _sweep.C = Math.Mul(_xf, _sweep.LocalCenter);
// Update center of mass velocity.
_linearVelocity += Vec2.Cross(_angularVelocity, _sweep.C - oldCenter);
BodyType oldType = _type;
if (_invMass == 0.0f && _invI == 0.0f)
{
_type = BodyType.Static;
_angularVelocity = 0.0f;
_linearVelocity.SetZero();
}
else
{
_type = BodyType.Dynamic;
}
// If the body type changed, we need to flag contacts for filtering.
if (oldType != _type)
{
for (ContactEdge ce = _contactList; ce != null; ce = ce.Next)
{
ce.Contact.FlagForFiltering();
}
}
}