public void Dispose() { if (disposed) { return; } disposed = true; //Delete all RigidBody objects for (int i = btWorld.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = btWorld.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } btWorld.RemoveCollisionObject(obj); obj.Dispose(); } btWorld.Dispose(); broadphase.Dispose(); btDispatcher.Dispose(); collisionConf.Dispose(); }
public void TearDown() { _world.Dispose(); _solver.Dispose(); _broadphase.Dispose(); _dispatcher.Dispose(); _conf.Dispose(); }
public override void Dispose() { base.Dispose(); _needCancel = true; SimulationRunning = false; _collisionConfiguration.Dispose(); _dispatcher.Dispose(); _broadPhase.Dispose(); _world.Dispose(); }
public void Dispose() { for (int i = _World.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = _World.GetConstraint(i); _World.RemoveConstraint(constraint); constraint.Dispose(); } _World.Dispose(); broadphase.Dispose(); if (dispatcher != null) { dispatcher.Dispose(); } collisionConf.Dispose(); }
public static void Dispose() // TODO: can crash; examine! { // remove/dispose of constraints for (int i = World.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = World.GetConstraint(i); lock (_worldSyncRoot) World.RemoveConstraint(constraint); constraint.Dispose(); } // remove the rigidbodies from the dynamics world and delete them for (int 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(); } lock (_worldSyncRoot) World.RemoveCollisionObject(obj); obj.Dispose(); } // delete collision shapes foreach (CollisionShape shape in _collisionShapes) { shape.Dispose(); } _collisionShapes.Clear(); lock (_worldSyncRoot) World.Dispose(); _broadphase.Dispose(); if (_dispatcher != null) { _dispatcher.Dispose(); } _collisionConf.Dispose(); }
public void unload() { int i; // Remove constraints for (i = _physics_world.world.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = _physics_world.world.GetConstraint(i); _physics_world.world.RemoveConstraint(constraint); constraint.Dispose(); } // Remove rigidbodies from the dynamics world and delete them for (i = _physics_world.world.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = _physics_world.world.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } _physics_world.world.RemoveCollisionObject(obj); obj.Dispose(); } // Delete collision shapes foreach (CollisionShape shape in _physics_world.collision_shapes) { shape.Dispose(); } _physics_world.collision_shapes.Clear(); // Delete the world _physics_world.world.Dispose(); _broadphase.Dispose(); if (_dispatcher != null) { _dispatcher.Dispose(); } _collision_config.Dispose(); }
public void ExitPhysics() { //remove/dispose constraints int i; for (i = physics_world.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = physics_world.GetConstraint(i); physics_world.RemoveConstraint(constraint); constraint.Dispose(); } //remove the rigidbodies from the dynamics world and delete them for (i = physics_world.NumCollisionObjects - 1; i >= 0; i--) { CollisionObject obj = physics_world.CollisionObjectArray[i]; RigidBody body = obj as RigidBody; if (body != null && body.MotionState != null) { body.MotionState.Dispose(); } physics_world.RemoveCollisionObject(obj); obj.Dispose(); } //delete collision shapes foreach (CollisionShape shape in collisionShapes) { shape.Dispose(); } collisionShapes.Clear(); physics_world.Dispose(); broadphase.Dispose(); if (dispatcher != null) { dispatcher.Dispose(); } collisionConf.Dispose(); }
protected override void OnDispose() { dispatcher?.Dispose(); broadphase?.Dispose(); collidersToUpdate?.Clear(); if (collisionShapes != null) { for (int i = 0; i < collisionShapes.Count; i++) { collisionShapes[i].Dispose(); } } /*if(rigidbodies != null) { * for(int i = 0; i < rigidbodies.Count; i++) { * rigidbodies[i].Dispose(); * } * * rigidbodies.Clear(); * }*/ }
internal static void Destroy() { if (!initialized) { return; } foreach (CollisionShape shape in collisionShapes) { shape.Destroy(); } collisionShapes.Clear(); // 衝突オブジェクトの解放 foreach (CollisionObject obj in collisionObjects) { world.RemoveCollisionObject(obj.BulletCollisionObject); obj.Destroy(); } collisionObjects.Clear(); // 剛体オブジェクトの解放 foreach (RigidBody rigid in rigidBodies) { world.RemoveRigidBody(rigid.BulletRigidBody); rigid.Destroy(); } rigidBodies.Clear(); //filterCB.Dispose(); dispatcher.Dispose(); collisionConf.Dispose(); solver.Dispose(); broadphase.Dispose(); //world.Dispose(); initialized = false; }
/// <summary> /// Disposes all of the objects and the world, essentially a destructor /// </summary> public void ExitPhysics() { int i; for (i = World.NumConstraints - 1; i >= 0; i--) { TypedConstraint constraint = World.GetConstraint(i); World.RemoveConstraint(constraint); constraint.Dispose(); } 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(); } foreach (CollisionShape shape in collisionShapes) { shape.Dispose(); } collisionShapes.Clear(); World.Dispose(); broadphase.Dispose(); if (dispatcher != null) { dispatcher.Dispose(); } collisionConf.Dispose(); }
private void Start() { //Create a World Debug.Log("Initialize physics"); List <CollisionShape> CollisionShapes = new List <CollisionShape>(); DefaultCollisionConfiguration CollisionConf = new DefaultCollisionConfiguration(); CollisionDispatcher Dispatcher = new CollisionDispatcher(CollisionConf); DbvtBroadphase Broadphase = new DbvtBroadphase(); DiscreteDynamicsWorld World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf) { Gravity = new BulletSharp.Math.Vector3(0, -9.80665f, 0) }; // create a few dynamic rigidbodies const float mass = 1.0f; //Add a single cube RigidBody fallRigidBody; BoxShape shape = new BoxShape(1f, 1f, 1f); BulletSharp.Math.Vector3 localInertia = BulletSharp.Math.Vector3.Zero; shape.CalculateLocalInertia(mass, out localInertia); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, null, shape, localInertia); fallRigidBody = new RigidBody(rbInfo); rbInfo.Dispose(); Matrix st = Matrix.Translation(new BulletSharp.Math.Vector3(0f, 10f, 0f)); fallRigidBody.WorldTransform = st; World.AddRigidBody(fallRigidBody); Matrix trans; //Step the simulation 300 steps for (int i = 0; i < 300; i++) { World.StepSimulation(1f / 60f, 10); fallRigidBody.GetWorldTransform(out trans); Debug.Log("box height: " + trans.Origin); } //Clean up. World.RemoveRigidBody(fallRigidBody); fallRigidBody.Dispose(); 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 ss in CollisionShapes) { ss.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(); } }