internal DynamicWorldImp()
        {
            //Debug.WriteLine("DynamicWorldImp");

            //Default
            // collision configuration contains default setup for memory, collision setup
            BtCollisionConf = new DefaultCollisionConfiguration();
            BtDispatcher = new CollisionDispatcher(BtCollisionConf);
            BtBroadphase = new DbvtBroadphase();
            BtSolver = new SequentialImpulseConstraintSolver();
               // BtCollisionShapes = new AlignedCollisionShapeArray();

            BtWorld = new DiscreteDynamicsWorld(BtDispatcher, BtBroadphase, BtSolver, BtCollisionConf)
            {
                Gravity = new Vector3(0, -9.81f, 0)
            };

            BtWorld.SolverInfo.NumIterations = 5;

            BtWorld.PerformDiscreteCollisionDetection();

            //GImpactCollisionAlgorithm.RegisterAlgorithm(BtDispatcher);
               // BtWorld.SetInternalTickCallback(MyTickCallBack);
            //BtWorld.SetInternalTickCallback(TickTack);

            //ManifoldPoint.ContactAdded += OnContactAdded;
            //PersistentManifold.ContactDestroyed += OnContactDestroyed;
            //PersistentManifold.ContactProcessed += OnContactProcessed;
        }
Пример #2
0
        public Physics()
        {
            // collision configuration contains default setup for memory, collision setup
            collisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(collisionConf);

            Broadphase = new DbvtBroadphase();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, collisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            CollisionShapes = new List<CollisionShape>();

            // create the ground
            CollisionShape groundShape = new BoxShape(50, 1, 50);
            CollisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape);
            ground.UserObject = "Ground";

            // create a few dynamic rigidbodies
            float mass = 1.0f;

            CollisionShape colShape = new BoxShape(1);
            CollisionShapes.Add(colShape);
            Vector3 localInertia = colShape.CalculateLocalInertia(mass);

            float start_x = StartPosX - ArraySizeX / 2;
            float start_y = StartPosY;
            float start_z = StartPosZ - ArraySizeZ / 2;

            int k, i, j;
            for (k = 0; k < ArraySizeY; k++)
            {
                for (i = 0; i < ArraySizeX; i++)
                {
                    for (j = 0; j < ArraySizeZ; j++)
                    {
                        Matrix startTransform = Matrix.CreateTranslation(
                            new Vector3(
                                2*i + start_x,
                                2*k + start_y,
                                2*j + start_z
                                )
                            );

                        // using motionstate is recommended, it provides interpolation capabilities
                        // and only synchronizes 'active' objects
                        DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
                        RigidBodyConstructionInfo rbInfo =
                            new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia);
                        RigidBody body = new RigidBody(rbInfo);

                        // make it drop from a height
                        body.Translate(new Vector3(0, 20, 0));

                        World.AddRigidBody(body);
                    }
                }
            }
        }
        public BulletPhysicWorld(Vector3 gravity,Dispatcher dispatcher, BroadphaseInterface pairCache, ConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration)
        {
            objs = new List<IPhysicObject>();
            ctns = new List<IPhysicConstraint>();

            world = new DiscreteDynamicsWorld(dispatcher, pairCache, constraintSolver, collisionConfiguration);
            world.Gravity = gravity;
        }
Пример #4
0
		public void Setup(Vector3Df gravity)
		{
			bulletCollisionConfiguration = new DefaultCollisionConfiguration();
			bulletCollisionDispatcher = new CollisionDispatcher(bulletCollisionConfiguration);
			bulletBroadphase = new DbvtBroadphase();

			bulletWorld = new DiscreteDynamicsWorld(bulletCollisionDispatcher, bulletBroadphase, null, bulletCollisionConfiguration);
			bulletWorld.Gravity = new Vector3(gravity.X, gravity.Y, gravity.Z);
		}
        public DiscreteDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache,
            ConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration)
            : base(btDiscreteDynamicsWorld_new(dispatcher != null ? dispatcher._native : IntPtr.Zero, pairCache != null ? pairCache._native : IntPtr.Zero,
				constraintSolver != null ? constraintSolver._native : IntPtr.Zero, collisionConfiguration != null ? collisionConfiguration._native : IntPtr.Zero))
        {
            _constraintSolver = constraintSolver;
            Dispatcher = dispatcher;
            Broadphase = pairCache;
        }
        public MultiBodyDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache, MultiBodyConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration)
            : base(btMultiBodyDynamicsWorld_new(dispatcher._native, pairCache._native, constraintSolver._native, collisionConfiguration._native))
        {
            _constraintSolver = constraintSolver;
            _dispatcher = dispatcher;
            _broadphase = pairCache;

            _bodies = new List<MultiBody>();
            _constraints = new List<MultiBodyConstraint>();
        }
 public DiscreteDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache, ConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration)
     : base(btDiscreteDynamicsWorld_new(
                dispatcher != null ? dispatcher._native : IntPtr.Zero,
                pairCache != null ? pairCache._native : IntPtr.Zero,
                constraintSolver != null ? constraintSolver._native : IntPtr.Zero,
                collisionConfiguration != null ? collisionConfiguration._native : IntPtr.Zero))
 {
     Dispatcher        = dispatcher;
     Broadphase        = pairCache;
     _constraintSolver = constraintSolver;
 }
Пример #8
0
        /// <summary>
        /// コンストラクター
        /// </summary>
        public PhysicsSimulator()
        {
            var cc = new DefaultCollisionConfiguration ();

            this.dispatcher = new CollisionDispatcher (cc);
            this.broadphase = new DbvtBroadphase ();
            this.solver = new SequentialImpulseConstraintSolver ();
            this.wld = new DiscreteDynamicsWorld (dispatcher, broadphase, solver, cc);

            this.wld.Gravity = new BulletSharp.Vector3 (0, -9.8f, 0);   // 重力は-Y方向
        }
 public override void LoadContent()
 {
     base.LoadContent();
     _collisionConfiguration = new DefaultCollisionConfiguration();
     _collisionDispatcher = new CollisionDispatcher(_collisionConfiguration);
     _broadphaseInterface = new DbvtBroadphase();
     World = new DiscreteDynamicsWorld(_collisionDispatcher, _broadphaseInterface, null, _collisionConfiguration);
     World.Gravity = new Vector3(0, 9.8f, 0);
     _worldSyncEvent = new AutoResetEvent(false);
     _worldUpdateTask = new Task(UpdateWorld);
 }
        public MultiBodyDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache,
                                      MultiBodyConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration)
        {
            IntPtr native = btMultiBodyDynamicsWorld_new(dispatcher.Native, pairCache.Native,
                                                         constraintSolver.Native, collisionConfiguration.Native);

            InitializeUserOwned(native);
            InitializeMembers(dispatcher, pairCache, constraintSolver);

            _bodies      = new List <MultiBody>();
            _constraints = new List <MultiBodyConstraint>();
        }
Пример #11
0
        public MultiBodyDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache,
                                      MultiBodyConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration)
            : base(btMultiBodyDynamicsWorld_new(dispatcher._native, pairCache._native,
                                                constraintSolver._native, collisionConfiguration._native))
        {
            _constraintSolver = constraintSolver;
            _dispatcher       = dispatcher;
            _broadphase       = pairCache;

            _bodies      = new List <MultiBody>();
            _constraints = new List <MultiBodyConstraint>();
        }
        public DiscreteDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache,
                                     ConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration)
        {
            IntPtr native = btDiscreteDynamicsWorld_new(
                dispatcher != null ? dispatcher.Native : IntPtr.Zero,
                pairCache != null ? pairCache.Native : IntPtr.Zero,
                constraintSolver != null ? constraintSolver.Native : IntPtr.Zero,
                collisionConfiguration != null ? collisionConfiguration.Native : IntPtr.Zero);

            InitializeUserOwned(native);
            InitializeMembers(dispatcher, pairCache, constraintSolver);
        }
        public BulletPhysicWorld(Vector3 gravity)
        {
            collisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(collisionConf);
            Broadphase = new DbvtBroadphase();
            constraintSolver = new SequentialImpulseConstraintSolver();

            objs = new List<IPhysicObject>();
            ctns = new List<IPhysicConstraint>();

            world = new DiscreteDynamicsWorld(Dispatcher, Broadphase ,constraintSolver, collisionConf);
            world.Gravity = gravity;            
        }
 public unsafe static void RayTest(this BroadphaseInterface obj, ref OpenTK.Vector3 rayFrom, ref OpenTK.Vector3 rayTo, BroadphaseRayCallback rayCallback, ref OpenTK.Vector3 aabbMin, ref OpenTK.Vector3 aabbMax)
 {
     fixed(OpenTK.Vector3 *rayFromPtr = &rayFrom)
     {
         fixed(OpenTK.Vector3 *rayToPtr = &rayTo)
         {
             fixed(OpenTK.Vector3 *aabbMinPtr = &aabbMin)
             {
                 fixed(OpenTK.Vector3 *aabbMaxPtr = &aabbMax)
                 {
                     obj.RayTest(ref *(BulletSharp.Math.Vector3 *)rayFromPtr, ref *(BulletSharp.Math.Vector3 *)rayToPtr, rayCallback, ref *(BulletSharp.Math.Vector3 *)aabbMinPtr, ref *(BulletSharp.Math.Vector3 *)aabbMaxPtr);
                 }
             }
         }
     }
 }
Пример #15
0
	void Awake ()
	{
		if (BtWorld.main == null || gameObject.tag.Equals ("main"))
			BtWorld.main = this;
		
		// TODO: expose in editor?
		broadphase = new BulletSharp.DbvtBroadphase ();
		collisionConfiguration = new BulletSharp.DefaultCollisionConfiguration ();
		dispatcher = new BulletSharp.CollisionDispatcher (collisionConfiguration);
		solver = new BulletSharp.SequentialImpulseConstraintSolver ();
		world = new BulletSharp.DiscreteDynamicsWorld (dispatcher, broadphase, solver, collisionConfiguration);
		
		world.Gravity = new BulletSharp.Vector3 (gravity.x, gravity.y, gravity.z);
		world.DebugDrawer = new UnityDebugDrawer ();
		world.DebugDrawer.DebugMode = BulletSharp.DebugDrawModes.None;
		foreach (BulletSharp.DebugDrawModes drawMode in debugDrawModes) {
			world.DebugDrawer.DebugMode |= drawMode;
		}
	}
Пример #16
0
        public void Create()
        {
            if (created)
            {
                this.Destroy();
            }

            this.bodyindex = 0;
            this.cstindex = 0;

            collisionConfiguration = new SoftBodyRigidBodyCollisionConfiguration();
            dispatcher = new CollisionDispatcher(collisionConfiguration);
            solver = new SequentialImpulseConstraintSolver();
            overlappingPairCache = new DbvtBroadphase();
            dynamicsWorld = new SoftRigidDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
            worldInfo = new SoftBodyWorldInfo();
            worldInfo.Gravity = dynamicsWorld.Gravity;
            worldInfo.Broadphase = overlappingPairCache;
            worldInfo.Dispatcher = dispatcher;
            worldInfo.SparseSdf.Initialize();
            this.created = true;

            if (this.WorldHasReset != null)
            {
                this.WorldHasReset();
            }
        }
Пример #17
0
        /*
        Does not set any local variables. Is safe to use to create duplicate physics worlds for independant simulation.
        */
        public bool CreatePhysicsWorld( out CollisionWorld world, 
            out CollisionConfiguration collisionConfig,
            out CollisionDispatcher dispatcher,
            out BroadphaseInterface broadphase,
            out SequentialImpulseConstraintSolver solver,
            out SoftBodyWorldInfo softBodyWorldInfo)
        {
            bool success = true;
            if (m_worldType == WorldType.SoftBodyAndRigidBody && m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf)
            {
                BDebug.LogError(debugType, "For World Type = SoftBodyAndRigidBody collisionType must be collisionType=SoftBodyRigidBodyCollisionConf. Switching");
                m_collisionType = CollisionConfType.SoftBodyRigidBodyCollisionConf;
                success = false;
            }

            collisionConfig = null;
            if (m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf)
            {
                collisionConfig = new DefaultCollisionConfiguration();
            }
            else if (m_collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf)
            {
                collisionConfig = new SoftBodyRigidBodyCollisionConfiguration();
            }

            dispatcher = new CollisionDispatcher(collisionConfig);

            if (m_broadphaseType == BroadphaseType.DynamicAABBBroadphase)
            {
                broadphase = new DbvtBroadphase();
            }
            else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase)
            {
                broadphase = new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            }
            else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit)
            {
                broadphase = new AxisSweep3_32Bit(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            }
            else
            {
                broadphase = null;
            }
            world = null;
            softBodyWorldInfo = null;
            solver = null;
            if (m_worldType == WorldType.CollisionOnly)
            {
                world = new CollisionWorld(dispatcher, broadphase, collisionConfig);
            }
            else if (m_worldType == WorldType.RigidBodyDynamics)
            {
                world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConfig);
            }
            else if (m_worldType == WorldType.MultiBodyWorld)
            {
                world = new MultiBodyDynamicsWorld(dispatcher, broadphase, null, collisionConfig);
            }
            else if (m_worldType == WorldType.SoftBodyAndRigidBody)
            {
                solver = new SequentialImpulseConstraintSolver();
                solver.RandSeed = sequentialImpulseConstraintSolverRandomSeed;
                softBodyWorldInfo = new SoftBodyWorldInfo
                {
                    AirDensity = 1.2f,
                    WaterDensity = 0,
                    WaterOffset = 0,
                    WaterNormal = BulletSharp.Math.Vector3.Zero,
                    Gravity = UnityEngine.Physics.gravity.ToBullet(),
                    Dispatcher = dispatcher,
                    Broadphase = broadphase
                };
                softBodyWorldInfo.SparseSdf.Initialize();

                world = new SoftRigidDynamicsWorld(dispatcher, broadphase, solver, collisionConfig);

                world.DispatchInfo.EnableSpu = true;
                softBodyWorldInfo.SparseSdf.Reset();
                softBodyWorldInfo.AirDensity = 1.2f;
                softBodyWorldInfo.WaterDensity = 0;
                softBodyWorldInfo.WaterOffset = 0;
                softBodyWorldInfo.WaterNormal = BulletSharp.Math.Vector3.Zero;
                softBodyWorldInfo.Gravity = m_gravity.ToBullet();
            }
            if (world is DiscreteDynamicsWorld)
            {
                ((DiscreteDynamicsWorld)world).Gravity = m_gravity.ToBullet();
            }
            if (_doDebugDraw)
            {
                DebugDrawUnity db = new DebugDrawUnity();
                db.DebugMode = _debugDrawMode;
                world.DebugDrawer = db;
            }
            return success;
        }
 public static void Benchmark(BroadphaseInterface broadphase)
 {
     btDbvtBroadphase_benchmark(broadphase._native);
 }
 internal DynamicsWorld(IntPtr native, Dispatcher dispatcher, BroadphaseInterface pairCache)
     : base(native, dispatcher, pairCache)
 {
 }
Пример #20
0
 /// <inheritdoc/>
 void System.IDisposable.Dispose()
 {
     if (wld != null) {
         dispatcher.Dispose ();
         broadphase.Dispose ();
         solver.Dispose ();
         wld.Dispose ();
         this.dispatcher = null;
         this.broadphase = null;
         this.solver = null;
         this.wld = null;
     }
 }
Пример #21
0
        protected void Dispose(bool disposing)
        {
            if (debugType >= BDebug.DebugType.Debug) Debug.Log("BDynamicsWorld Disposing physics.");

            if (lateUpdateHelper != null)
            {
                lateUpdateHelper.m_ddWorld = null;
                lateUpdateHelper.m_world = null;
            }
            if (m_world != null)
            {
                //remove/dispose constraints
                int i;
                if (_ddWorld != null)
                {
                    if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removing Constraints {0}", _ddWorld.NumConstraints);
                    for (i = _ddWorld.NumConstraints - 1; i >= 0; i--)
                    {
                        TypedConstraint constraint = _ddWorld.GetConstraint(i);
                        _ddWorld.RemoveConstraint(constraint);
                        if (constraint.Userobject is BTypedConstraint) ((BTypedConstraint)constraint.Userobject).m_isInWorld = false;
                        if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removed Constaint {0}", constraint.Userobject);
                        constraint.Dispose();
                    }
                }

                if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removing Collision Objects {0}", _ddWorld.NumCollisionObjects);
                //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)
                    {
                        Debug.Assert(body.NumConstraintRefs == 0, "Rigid body still had constraints");
                        body.MotionState.Dispose();
                    }
                    m_world.RemoveCollisionObject(obj);
                    if (obj.UserObject is BCollisionObject) ((BCollisionObject)obj.UserObject).isInWorld = false;
                    if (debugType >= BDebug.DebugType.Debug) Debug.LogFormat("Removed CollisionObject {0}", obj.UserObject);
                    obj.Dispose();
                }

                if (m_world.DebugDrawer != null)
                {
                    if (m_world.DebugDrawer is IDisposable)
                    {
                        IDisposable dis = (IDisposable)m_world.DebugDrawer;
                        dis.Dispose();
                    }
                }

                m_world.Dispose();
                Broadphase.Dispose();
                Dispatcher.Dispose();
                CollisionConf.Dispose();
                _ddWorld = null;
                m_world = null;
            }

            if (Broadphase != null)
            {
                Broadphase.Dispose();
                Broadphase = null;
            }
            if (Dispatcher != null)
            {
                Dispatcher.Dispose();
                Dispatcher = null;
            }
            if (CollisionConf != null)
            {
                CollisionConf.Dispose();
                CollisionConf = null;
            }
            if (Solver != null)
            {
                Solver.Dispose();
                Solver = null;
            }
            if (softBodyWorldInfo != null)
            {
                softBodyWorldInfo.Dispose();
                softBodyWorldInfo = null;
            }
            _isDisposed = true;
            singleton = null;
        }
Пример #22
0
 protected internal void InitializeMembers(Dispatcher dispatcher, BroadphaseInterface pairCache, ConstraintSolver constraintSolver)
 {
     InitializeMembers(dispatcher, pairCache);
     _constraintSolver = constraintSolver;
 }
Пример #23
0
        /// <summary>
        /// Creates the world
        /// </summary>
        void CreateWorld(string levelName)
        {
            Launch.Log("[PhysicsMain] Creating new world...");
            // have to make more of these every level because disposing the world apparently disposes of them too.
            broadphase = new DbvtBroadphase();
            solver = new SequentialImpulseConstraintSolver();
            dcc = new DefaultCollisionConfiguration();
            dispatcher = new CollisionDispatcher(dcc);
            // set up this stuff... not quite sure what it's for, but you need it if you want the CCD to work for the karts
            dispatcher.RegisterCollisionCreateFunc(BroadphaseNativeType.ConvexHullShape, BroadphaseNativeType.ConvexHullShape,
                dcc.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.TriangleMeshShape, BroadphaseNativeType.TriangleMeshShape));
            dispatcher.RegisterCollisionCreateFunc(BroadphaseNativeType.ConvexHullShape, BroadphaseNativeType.ConvexHullShape,
                dcc.GetCollisionAlgorithmCreateFunc(BroadphaseNativeType.ConvexHullShape, BroadphaseNativeType.ConvexHullShape));

            world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, dcc);
            // and then turn on CCD
            world.DispatchInfo.UseContinuous = true;

            world.Gravity = new Vector3(0, Settings.Default.Gravity, 0);

            ManifoldPoint.ContactAddedCallback = ContactAdded;
        }
		public CollisionWorld(Dispatcher dispatcher, BroadphaseInterface broadphasePairCache,
			CollisionConfiguration collisionConfiguration)
            : this(btCollisionWorld_new(dispatcher._native, broadphasePairCache._native,
                collisionConfiguration._native))
		{
			_dispatcher = dispatcher;
			Broadphase = broadphasePairCache;
		}
Пример #25
0
        public Physics(SceneManager sceneMgr)
        {
            // collision configuration contains default setup for memory, collision setup
            collisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(collisionConf);

            Broadphase = new DbvtBroadphase();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, collisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            // create the ground
            CollisionShape groundShape = new BoxShape(50, 1, 50);
            CollisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, Matrix4.IDENTITY, groundShape);
            ground.UserObject = "Ground";

            // create a few dynamic rigidbodies
            float mass = 1.0f;

            CollisionShape colShape = new BoxShape(1);
            CollisionShapes.Add(colShape);
            Vector3 localInertia = colShape.CalculateLocalInertia(mass);

            var rbInfo = new RigidBodyConstructionInfo(mass, null, colShape, localInertia);

            float start_x = StartPosX - ArraySizeX / 2;
            float start_y = StartPosY;
            float start_z = StartPosZ - ArraySizeZ / 2;

            int k, i, j;
            for (k = 0; k < ArraySizeY; k++)
            {
                for (i = 0; i < ArraySizeX; i++)
                {
                    for (j = 0; j < ArraySizeZ; j++)
                    {
                        Matrix4 startTransform = new Matrix4();
                        startTransform.MakeTrans(
                            new Vector3(
                                2*i + start_x,
                                2*k + start_y,
                                2*j + start_z
                                )
                            );

                        // using motionstate is recommended, it provides interpolation capabilities
                        // and only synchronizes 'active' objects
                        int index = (k * ArraySizeX + i) * ArraySizeZ + j;
                        Entity box = sceneMgr.CreateEntity("Box" + index.ToString(), "box.mesh");
                        box.SetMaterialName("BoxMaterial/Active");
                        SceneNode boxNode = sceneMgr.RootSceneNode.CreateChildSceneNode("BoxNode" + index.ToString());
                        boxNode.AttachObject(box);
                        boxNode.Scale(new Vector3(2, 2, 2));
                        var mogreMotionState = new MogreMotionState(box, boxNode, startTransform);
                        rbInfo.MotionState = mogreMotionState;

                        RigidBody body = new RigidBody(rbInfo);
                        mogreMotionState.Body = body;

                        // make it drop from a height
                        body.Translate(new Vector3(0, 20, 0));

                        World.AddRigidBody(body);
                    }
                }
            }

            rbInfo.Dispose();
        }
Пример #26
0
 public static void Benchmark(BroadphaseInterface broadphase)
 {
     btDbvtBroadphase_benchmark(broadphase._native);
 }
        protected override void _InitializePhysicsWorld()
        {
            base._InitializePhysicsWorld();

            if (collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf)
            {
                CollisionConf = new DefaultCollisionConfiguration();
            } else if (collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf)
            {
                CollisionConf = new SoftBodyRigidBodyCollisionConfiguration();
            }

            Dispatcher = new CollisionDispatcher(CollisionConf);

            if (broadphaseType == BroadphaseType.DynamicAABBBroadphase)
            {
                Broadphase = new DbvtBroadphase();
            } else if (broadphaseType == BroadphaseType.Axis3SweepBroadphase)
            {
                Broadphase = new AxisSweep3(axis3SweepBroadphaseMin.ToBullet(), axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            } else if (broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit)
            {
                Broadphase = new AxisSweep3_32Bit(axis3SweepBroadphaseMin.ToBullet(), axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            } else
            {
                Broadphase = new SimpleBroadphase();
            }

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
            World.Gravity = gravity.ToBullet();
            if (_doDebugDraw) {
                DebugDrawUnity db = new DebugDrawUnity();
                db.DebugMode = _debugDrawMode;
                World.DebugDrawer = db;
            }
        }