// TODO_ERIN adjust linear velocity and torque to account for movement of center. /// <summary> /// Set the mass properties. Note that this changes the center of mass position. /// If you are not sure how to compute mass properties, use SetMassFromShapes. /// The inertia tensor is assumed to be relative to the center of mass. /// </summary> /// <param name="massData">The mass properties.</param> public void SetMass(MassData massData) { Box2DXDebug.Assert(_world._lock == false); if (_world._lock == true) { return; } _invMass = 0.0f; _I = 0.0f; _invI = 0.0f; _mass = massData.Mass; if (_mass > 0.0f) { _invMass = 1.0f / _mass; } _I = massData.I; if (_I > 0.0f && (_flags & BodyFlags.FixedRotation) == 0) { _invI = 1.0f / _I; } // Move center of mass. _sweep.LocalCenter = massData.Center; _sweep.C0 = _sweep.C = _xf.TransformPoint(_sweep.LocalCenter); BodyType oldType = _type; if (_invMass == 0.0f && _invI == 0.0f) { _type = BodyType.Static; } else { _type = BodyType.Dynamic; } // If the body type changed, we need to refilter the broad-phase proxies. if (oldType != _type) { for (Fixture f = _fixtureList; f != null; f = f.Next) { f.RefilterProxy(_world._broadPhase, _xf); } } }
public void SetStatic() { if (_type == BodyType.Static) { return; } _mass = 0.0f; _invMass = 0.0f; _I = 0.0f; _invI = 0.0f; _type = BodyType.Static; for (Fixture f = _fixtureList; f != null; f = f.Next) { f.RefilterProxy(_world._broadPhase, _xf); } }
// TODO_ERIN adjust linear velocity and torque to account for movement of center. /// <summary> /// Compute the mass properties from the attached shapes. You typically call this /// after adding all the shapes. If you add or remove shapes later, you may want /// to call this again. Note that this changes the center of mass position. /// </summary> public void SetMassFromShapes() { Box2DXDebug.Assert(_world._lock == false); if (_world._lock == true) { return; } // Compute mass data from shapes. Each shape has its own density. _mass = 0.0f; _invMass = 0.0f; _I = 0.0f; _invI = 0.0f; Vector2 center = Vector2.zero; for (Fixture f = _fixtureList; f != null; f = f.Next) { MassData massData; f.ComputeMass(out massData); _mass += massData.Mass; center += massData.Mass * massData.Center; _I += massData.I; } // Compute center of mass, and shift the origin to the COM. 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 * Vector2.Dot(center, center); Box2DXDebug.Assert(_I > 0.0f); _invI = 1.0f / _I; } else { _I = 0.0f; _invI = 0.0f; } // Move center of mass. _sweep.LocalCenter = center; _sweep.C0 = _sweep.C = _xf.TransformPoint(_sweep.LocalCenter); BodyType oldType = _type; if (_invMass == 0.0f && _invI == 0.0f) { _type = BodyType.Static; } else { _type = BodyType.Dynamic; } // If the body type changed, we need to refilter the broad-phase proxies. if (oldType != _type) { for (Fixture f = _fixtureList; f != null; f = f.Next) { f.RefilterProxy(_world._broadPhase, _xf); } } }
/// <summary> /// Re-filter a fixture. This re-runs contact filtering on a fixture. /// </summary> public void Refilter(Fixture fixture) { Box2DXDebug.Assert(_lock == false); fixture.RefilterProxy(_broadPhase, fixture.Body.GetTransform()); }