protected override void Dispose(bool isdisposing) { if (isInWorld && isdisposing && m_rigidBody != null) { BPhysicsWorld pw = BPhysicsWorld.Get; if (pw != null && pw.world != null) { //constraints must be removed before rigid body is removed for (int i = m_rigidBody.NumConstraintRefs; i > 0; i--) { BTypedConstraint tc = (BTypedConstraint)m_rigidBody.GetConstraintRef(i - 1).Userobject; ((DiscreteDynamicsWorld)pw.world).RemoveConstraint(tc.GetConstraint()); } ((DiscreteDynamicsWorld)pw.world).RemoveRigidBody(m_rigidBody); } } if (m_rigidBody != null) { if (m_rigidBody.MotionState != null) { m_rigidBody.MotionState.Dispose(); } m_rigidBody.Dispose(); m_rigidBody = null; } }
public bool AddConstraint(BTypedConstraint c) { if (!_isDisposed) { if (m_worldType < WorldType.RigidBodyDynamics) { Log.Warning("World type must not be collision only"); return(false); } if (c._BuildConstraint()) { ((DiscreteDynamicsWorld)m_world).AddConstraint(c.GetConstraint(), c.disableCollisionsBetweenConstrainedBodies); c.m_isInWorld = true; } return(true); } return(false); }