コード例 #1
0
 public bool AddCollisionObject(BCollisionObject co)
 {
     if (!_isDisposed)
     {
         if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Adding collision object {0} to world", co);
         if (co._BuildCollisionObject())
         {
             m_world.AddCollisionObject(co.GetCollisionObject(), co.groupsIBelongTo, co.collisionMask);
             co.isInWorld = true;
             if (ghostPairCallback == null && co is BGhostObject && world is DynamicsWorld)
             {
                 ghostPairCallback = new GhostPairCallback();
                 ((DynamicsWorld)world).PairCache.SetInternalGhostPairCallback(ghostPairCallback);
             }
             if (co is BCharacterController && world is DynamicsWorld)
             {
                 AddAction(((BCharacterController)co).GetKinematicCharacterController());
             }
         }
         return true;
     }
     return false;
 }
コード例 #2
0
        static void TestGCCollection()
        {
            var conf = new DefaultCollisionConfiguration();
            var dispatcher = new CollisionDispatcher(conf);
            var broadphase = new DbvtBroadphase();
            //var broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
            world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf);
            world.Gravity = new Vector3(0, -10, 0);
            dispatcher.NearCallback = DispatcherNearCallback;

            CreateBody(0.0f, new BoxShape(50, 1, 50), Vector3.Zero);
            var dynamicObject = CreateBody(10.0f, new SphereShape(1.0f), new Vector3(2, 2, 0));
            var dynamicObject2 = CreateBody(1.0f, new SphereShape(1.0f), new Vector3(0, 2, 0));

            var ghostPairCallback = new GhostPairCallback();
            broadphase.OverlappingPairCache.SetInternalGhostPairCallback(ghostPairCallback);
            AddToDisposeQueue(ghostPairCallback);
            ghostPairCallback = null;
            var ghostObject = new PairCachingGhostObject();
            ghostObject.CollisionShape = new BoxShape(2);
            ghostObject.WorldTransform = Matrix.Translation(2,2,0);
            world.AddCollisionObject(ghostObject);

            var trimesh = new TriangleMesh();
            Vector3 v0 = new Vector3(0, 0, 0);
            Vector3 v1 = new Vector3(1, 0, 0);
            Vector3 v2 = new Vector3(0, 1, 0);
            Vector3 v3 = new Vector3(1, 1, 0);
            trimesh.AddTriangle(v0, v1, v2);
            trimesh.AddTriangle(v1, v3, v2);
            var triangleMeshShape = new BvhTriangleMeshShape(trimesh, false);
            var triMeshObject = CreateBody(0, triangleMeshShape, new Vector3(20,0,20));
            AddToDisposeQueue(triangleMeshShape);
            AddToDisposeQueue(trimesh);
            AddToDisposeQueue(triMeshObject);
            triangleMeshShape = null;
            trimesh = null;

            AddToDisposeQueue(conf);
            AddToDisposeQueue(dispatcher);
            AddToDisposeQueue(broadphase);
            AddToDisposeQueue(world);

            //conf.Dispose();
            conf = null;
            //dispatcher.Dispose();
            dispatcher = null;
            //broadphase.Dispose();
            broadphase = null;
            world.DebugDrawer = new DebugDrawTest();
            AddToDisposeQueue(world.DebugDrawer);
            world.SetInternalTickCallback(WorldPreTickCallback);
            for (int i = 0; i < 600; i++)
            {
                world.StepSimulation(1.0f / 60.0f);
            }

            world.DispatchInfo.DebugDraw = new DebugDrawTest2();
            AddToDisposeQueue(world.DispatchInfo.DebugDraw);
            world.DispatchInfo.DebugDraw = world.DispatchInfo.DebugDraw;
            AddToDisposeQueue(world.DispatchInfo.DebugDraw);
            world.DispatchInfo.DebugDraw = null;
            world.DebugDrawer = null;
            world.DebugDrawer = new DebugDrawTest2();
            world.StepSimulation(1.0f / 60.0f);
            world.DebugDrawWorld();
            AddToDisposeQueue(world.DispatchInfo.DebugDraw);

            world.DebugDrawer = new DebugDrawTest();
            world.DebugDrawWorld();
            AddToDisposeQueue(world.DebugDrawer);
            world.DebugDrawer = null;

            TestContactTest(dynamicObject, dynamicObject2);
            TestGhostObjectPairs(ghostObject);
            TestRayCast(dynamicObject);
            TestTriangleMeshRayCast(triMeshObject);
            dynamicObject = null;
            dynamicObject2 = null;
            triMeshObject = null;

            //world.SetInternalTickCallback(null);
            world.Dispose();
            world = null;

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            TestWeakRefs();
            disposeQueue.Clear();
        }
コード例 #3
0
ファイル: Engine.cs プロジェクト: zdimension/FreeRaider
        public static void InitBullet()
        {
            // collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
            BtEngineCollisionConfiguration = new DefaultCollisionConfiguration();

            // use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
            BtEngineDispatcher = new CollisionDispatcher(BtEngineCollisionConfiguration);
            BtEngineDispatcher.NearCallback = RoomNearCallback;

            // btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
            BtEngineOverlappingPairCache = new DbvtBroadphase();
            BtEngineGhostPairCallback = new GhostPairCallback();
            BtEngineOverlappingPairCache.OverlappingPairCache.SetInternalGhostPairCallback(BtEngineGhostPairCallback);

            // the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
            BtEngineSolver = new SequentialImpulseConstraintSolver();

            BtEngineDynamicsWorld = new DiscreteDynamicsWorld(BtEngineDispatcher,
                BtEngineOverlappingPairCache, BtEngineSolver, BtEngineCollisionConfiguration);
            BtEngineDynamicsWorld.SetInternalTickCallback(InternalTickCallback);
            BtEngineDynamicsWorld.Gravity = new BulletSharp.Math.Vector3(0, 0, -4500.0f);

            DebugDrawer = new RenderDebugDrawer();
            DebugDrawer.DebugMode = DebugDrawModes.DrawWireframe | DebugDrawModes.DrawConstraints;
            BtEngineDynamicsWorld.DebugDrawer = DebugDrawer;
            //Global.BtEngineDynamicsWorld.PairCache.SetInternalGhostPairCallback(Global.BtEngineFilterCallback);
        }