Example #1
0
        public virtual void ExitPhysics()
        {
            BulletExampleRunner.Get().ExitPhysics();
            UnityEngine.Debug.Log("ExitPhysics");
            if (_world != null)
            {
                //remove/dispose constraints
                int i;
                for (i = _world.NumConstraints - 1; i >= 0; i--)
                {
                    TypedConstraint constraint = _world.GetConstraint(i);
                    _world.RemoveConstraint(constraint);
                    constraint.Dispose();
                }

                //remove the rigidbodies from the dynamics world and delete them
                for (i = _world.NumCollisionObjects - 1; i >= 0; i--)
                {
                    CollisionObject obj  = _world.CollisionObjectArray[i];
                    RigidBody       body = obj as RigidBody;
                    if (body != null && body.MotionState != null)
                    {
                        body.MotionState.Dispose();
                    }
                    _world.RemoveCollisionObject(obj);
                    obj.Dispose();
                }

                //delete collision shapes
                foreach (CollisionShape shape in CollisionShapes)
                {
                    shape.Dispose();
                }
                CollisionShapes.Clear();

                _world.Dispose();
                Broadphase.Dispose();
                Dispatcher.Dispose();
                CollisionConf.Dispose();
            }

            if (Broadphase != null)
            {
                Broadphase.Dispose();
            }
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
            }
            if (CollisionConf != null)
            {
                CollisionConf.Dispose();
            }
        }
Example #2
0
            public virtual void Cleanup()
            {
                int i;

                // Remove all constraints
                for (i = 0; i < (int)JOINT.COUNT; ++i)
                {
                    if (m_joints[i] != null)
                    {
                        m_ownerWorld.RemoveConstraint(m_joints[i]);
                        m_joints[i].Cleanup();
                        m_joints[i] = null;
                    }
                }

                // Remove all bodies and shapes
                for (i = 0; i < (int)BODYPART.COUNT; ++i)
                {
                    if (m_bodies[i] != null)
                    {
                        m_ownerWorld.RemoveRigidBody(m_bodies[i]);

                        //delete m_bodies[i].getMotionState();

                        m_bodies[i].Cleanup();
                        m_bodies[i] = null;
                        m_shapes[i].Cleanup();
                        m_shapes[i] = null;
                    }
                }
            }
Example #3
0
        public void Dispose()
        {
            int i;

            // Remove all constraints
            for (i = 0; i < JointCount; ++i)
            {
                _ownerWorld.RemoveConstraint(Joints[i]);
                Joints[i].Dispose();
                Joints[i] = null;
            }

            // Remove all bodies and shapes
            for (i = 0; i < JointCount; ++i)
            {
                _ownerWorld.RemoveRigidBody(_jointBodies[i]);
                _jointBodies[i].MotionState.Dispose();
                _jointBodies[i].Dispose();
            }
            _jointBodies = null;

            _thighShape.Dispose();
            _thighShape = null;
            _shinShape.Dispose();
            _shinShape = null;
        }
 public void RemoveConstraint(BulletSharp.TypedConstraint c)
 {
     if (!_isDisposed)
     {
         Debug.LogFormat("Removing constraint {0} from world", c);
         World.RemoveConstraint(c);
     }
 }
    void OnDestroy()
    {
        for (int i = 0; i < createdObjs.Count; i++)
        {
            Destroy(createdObjs[i]);
        }
        createdObjs.Clear();
        UnityEngine.Debug.Log("ExitPhysics");
        if (World != null)
        {
            //remove/dispose constraints
            int i;
            for (i = World.NumConstraints - 1; i >= 0; i--)
            {
                TypedConstraint constraint = World.GetConstraint(i);
                World.RemoveConstraint(constraint);
                constraint.Dispose();
            }

            //remove the rigidbodies from the dynamics world and delete them
            for (i = World.NumCollisionObjects - 1; i >= 0; i--)
            {
                CollisionObject obj  = World.CollisionObjectArray[i];
                RigidBody       body = obj as RigidBody;
                if (body != null && body.MotionState != null)
                {
                    body.MotionState.Dispose();
                }
                World.RemoveCollisionObject(obj);
                obj.Dispose();
            }

            //delete collision shapes
            foreach (CollisionShape shape in CollisionShapes)
            {
                shape.Dispose();
            }
            CollisionShapes.Clear();

            World.Dispose();
            Broadphase.Dispose();
            Dispatcher.Dispose();
            CollisionConf.Dispose();
        }

        if (Broadphase != null)
        {
            Broadphase.Dispose();
        }
        if (Dispatcher != null)
        {
            Dispatcher.Dispose();
        }
        if (CollisionConf != null)
        {
            CollisionConf.Dispose();
        }
    }
 private static void CleanupConstraints(DynamicsWorld world)
 {
     for (int i = world.NumConstraints - 1; i >= 0; i--)
     {
         TypedConstraint constraint = world.GetConstraint(i);
         world.RemoveConstraint(constraint);
         constraint.Dispose();
     }
 }
 public override void RemoveConstraint(Physic.Constraints.IPhysicConstraint ctn)
 {
     if (ctn is BulletConstraint)
     {
         BulletConstraint BulletConstraint = ctn as BulletConstraint;
         world.RemoveConstraint(BulletConstraint.Constraint);
     }
     ctns.Remove(ctn);
 }
Example #8
0
 private void RemoveFromWorld()
 {
     for (int i = 0; i < RigidBodies.Length; i++)
     {
         World.RemoveRigidBody(RigidBodies[i]);
     }
     for (int i = 0; i < Constraints.Length; i++)
     {
         World.RemoveConstraint(Constraints[i]);
     }
 }
Example #9
0
        public void Dispose()
        {
            foreach (var leg in Legs)
            {
                _world.RemoveConstraint(leg.Hip);
                leg.Hip.Dispose();
                _world.RemoveConstraint(leg.Knee);
                leg.Knee.Dispose();
            }

            DisposeRigidBody(_bodyObject);
            foreach (var leg in Legs)
            {
                DisposeRigidBody(leg.Thigh);
                DisposeRigidBody(leg.Shin);
            }

            _bodyShape.Dispose();
            _thighShape.Dispose();
            _shinShape.Dispose();
        }
Example #10
0
        public void Dispose()
        {
            foreach (var joint in _joints)
            {
                _world.RemoveConstraint(joint);
                joint.Dispose();
            }

            foreach (var body in _bodies)
            {
                _world.RemoveRigidBody(body);
                body.Dispose();
            }

            foreach (var shape in _shapes)
            {
                shape.Dispose();
            }
        }
Example #11
0
        public void ExitPhysics()
        {
            //remove/dispose constraints
            int i;

            for (i = World.NumConstraints - 1; i >= 0; i--)
            {
                TypedConstraint constraint = World.GetConstraint(i);
                World.RemoveConstraint(constraint);
                constraint.Dispose();;
            }

            //remove the rigidbodies from the dynamics world and delete them
            for (i = World.NumCollisionObjects - 1; i >= 0; i--)
            {
                CollisionObject obj  = World.CollisionObjectArray[i];
                RigidBody       body = obj as RigidBody;
                if (body != null && body.MotionState != null)
                {
                    body.MotionState.Dispose();
                }
                World.RemoveCollisionObject(obj);
                obj.Dispose();
            }

            //delete collision shapes
            foreach (CollisionShape shape in CollisionShapes)
            {
                shape.Dispose();
            }
            CollisionShapes.Clear();

            World.Dispose();
            Broadphase.Dispose();
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
            }
        }
Example #12
0
            public void Dispose()
            {
                int i;

                // Remove all constraints
                for (i = 0; i < JointCount; ++i)
                {
                    ownerWorld.RemoveConstraint(joints[i]);
                    joints[i].Dispose();
                    joints[i] = null;
                }

                // Remove all bodies and shapes
                for (i = 0; i < BodyPartCount; ++i)
                {
                    ownerWorld.RemoveRigidBody(bodies[i]);
                    bodies[i].MotionState.Dispose();
                    bodies[i].Dispose();
                    bodies[i] = null;
                    shapes[i].Dispose();
                    shapes[i] = null;
                }
            }
        private static void CleanupConstraints(DynamicsWorld world)
        {
            var nonWorldObjects = new HashSet <CollisionObject>();

            for (int i = world.NumConstraints - 1; i >= 0; i--)
            {
                TypedConstraint constraint = world.GetConstraint(i);
                world.RemoveConstraint(constraint);
                if (constraint.RigidBodyA.BroadphaseHandle == null)
                {
                    nonWorldObjects.Add(constraint.RigidBodyA);
                }
                if (constraint.RigidBodyB.BroadphaseHandle == null)
                {
                    nonWorldObjects.Add(constraint.RigidBodyB);
                }
                constraint.Dispose();
            }

            foreach (var obj in nonWorldObjects)
            {
                obj.Dispose();
            }
        }
 public static void DeleteAndDisposeConstraint(this DynamicsWorld world, TypedConstraint constraint)
 {
     world.RemoveConstraint(constraint);
     constraint.UserObject = null;
     constraint.Dispose();
 }
Example #15
0
    // Disposes of all Unity and Bullet objects and closes the application
    protected void ExitSimulation()
    {
        Debug.Log("Quitting simulation...");
        m_quitting = true;
        // destroy all Unity objects
        for (int i = 0; i < m_createdObjs.Count; i++)
        {
            Destroy(m_createdObjs[i]);
        }
        m_createdObjs.Clear();

        // destroy all bullet objects
        if (m_world != null)
        {
            //remove/dispose constraints
            int i;
            for (i = m_world.NumConstraints - 1; i >= 0; i--)
            {
                TypedConstraint constraint = m_world.GetConstraint(i);
                m_world.RemoveConstraint(constraint);
                constraint.Dispose();
            }

            //remove the rigidbodies from the dynamics world and delete them
            for (i = m_world.NumCollisionObjects - 1; i >= 0; i--)
            {
                CollisionObject obj  = m_world.CollisionObjectArray[i];
                RigidBody       body = obj as RigidBody;
                if (body != null && body.MotionState != null)
                {
                    body.MotionState.Dispose();
                }
                m_world.RemoveCollisionObject(obj);
                obj.Dispose();
            }

            //delete collision shapes
            foreach (CollisionShape shape in m_collisionShapes)
            {
                shape.Dispose();
            }
            m_collisionShapes.Clear();

            m_world.Dispose();
            m_broadphase.Dispose();
            m_colDispatcher.Dispose();
            m_colConfig.Dispose();
        }

        if (m_broadphase != null)
        {
            m_broadphase.Dispose();
        }
        if (m_colDispatcher != null)
        {
            m_colDispatcher.Dispose();
        }
        if (m_colConfig != null)
        {
            m_colConfig.Dispose();
        }

        Application.Quit();
    }