public bool AddConstraint(BTypedConstraint c)
        {
            if (!_isDisposed)
            {
                if (m_worldType < WorldType.RigidBodyDynamics)
                {
                    Debug.LogError("World type must not be collision only");
                    return(false);
                }

                if (debugType >= BDebug.DebugType.Debug)
                {
                    Debug.LogFormat("Adding constraint {0} to world", c);
                }

                if (c._BuildConstraint())
                {
                    ((DiscreteDynamicsWorld)m_world).AddConstraint(c.GetConstraint(), c.disableCollisionsBetweenConstrainedBodies);
                    c.m_isInWorld = true;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
 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;
     }
 }
        protected override void Dispose(bool isdisposing)
        {
            if (isInWorld && isdisposing && m_rigidBody != null)
            {
                WorldController pw = GetWorld();

                if (pw?.DDWorld != 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;
                        pw.DDWorld.RemoveConstraint(tc.GetConstraint());
                    }

                    pw.DDWorld.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)
     {
         Debug.LogFormat("Adding constraint {0} to world", c);
         if (c._BuildConstraint())
         {
             World.AddConstraint(c.GetConstraint(), c.disableCollisionsBetweenConstrainedBodies);
         }
         return(true);
     }
     return(false);
 }
示例#5
0
 protected override void OnDisable()
 {
     if (m_rigidBody != null && isInWorld)
     {
         //all constraints using RB must be disabled before rigid body is disabled
         for (int i = m_rigidBody.NumConstraintRefs - 1; i >= 0; i--)
         {
             BTypedConstraint btc = (BTypedConstraint)m_rigidBody.GetConstraintRef(i).Userobject;
             Debug.Assert(btc != null);
             btc.enabled = false; //should remove it from the scene
         }
     }
     base.OnDisable();
 }
 public bool AddConstraint(BTypedConstraint c)
 {
     if (!_isDisposed)
     {
         if (m_worldType < WorldType.RigidBodyDynamics)
         {
             BDebug.LogError(debugType, "World type must not be collision only");
             return false;
         }
         if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Adding constraint {0} to world", c);
         if (c._BuildConstraint())
         {
             ((DiscreteDynamicsWorld)m_world).AddConstraint(c.GetConstraint(), c.disableCollisionsBetweenConstrainedBodies);
             c.m_isInWorld = true;
         }
         return true;
     }
     return false;
 }
 public bool AddConstraint(BTypedConstraint c)
 {
     if (!_isDisposed) {
         Debug.LogFormat("Adding constraint {0} to world", c);
         if (c._BuildConstraint()) {
             World.AddConstraint(c.GetConstraint(), c.disableCollisionsBetweenConstrainedBodies);
         }
         return true;
     }
     return false;
 }