示例#1
0
		public void NearCallback(BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo)
		{
			CollisionObject colObj0 = (CollisionObject)collisionPair.m_pProxy0.GetClientObject();
			CollisionObject colObj1 = (CollisionObject)collisionPair.m_pProxy1.GetClientObject();

			if (dispatcher.NeedsCollision(colObj0,colObj1))
			{
				//dispatcher will keep algorithms persistent in the collision pair
				if (collisionPair.m_algorithm == null)
				{
					collisionPair.m_algorithm = dispatcher.FindAlgorithm(colObj0,colObj1,null);
				}

				if (collisionPair.m_algorithm != null)
				{
					ManifoldResult contactPointResult = new ManifoldResult(colObj0,colObj1);

					if (dispatchInfo.GetDispatchFunc() == DispatchFunc.DISPATCH_DISCRETE)
					{
						//discrete collision detection query
						collisionPair.m_algorithm.ProcessCollision(colObj0,colObj1,dispatchInfo,contactPointResult);
					} 
					else
					{
						//continuous collision detection query, time of impact (toi)
						float toi = collisionPair.m_algorithm.CalculateTimeOfImpact(colObj0,colObj1,dispatchInfo,contactPointResult);
						if (dispatchInfo.GetTimeOfImpact() > toi)
						{
							dispatchInfo.SetTimeOfImpact(toi);
						}
					}
				}
			}
		}
示例#2
0
 void SetupEmptyDynamicsWorld()
 {
     CollisionConf = new DefaultCollisionConfiguration();
     Dispatcher    = new CollisionDispatcher(CollisionConf);
     Broadphase    = new DbvtBroadphase();
     Solver        = new SequentialImpulseConstraintSolver();
     World         = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
     World.Gravity = new Vector3(0, -10, 0);
 }
示例#3
0
        public override void Run()
        {
            var conf       = new DefaultCollisionConfiguration();
            var dispatcher = new CollisionDispatcher(conf);
            var broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));

            world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf);

            var indexVertexArray = new TriangleIndexVertexArray(TorusMesh.Indices, TorusMesh.Vertices);

            foreach (var indexedMesh in indexVertexArray.IndexedMeshArray)
            {
                indexedMesh.ToString();
            }
            AddToDisposeQueue(indexVertexArray);

            var     gImpactMesh = new GImpactMeshShape(indexVertexArray);
            Vector3 aabbMin, aabbMax;

            gImpactMesh.GetAabb(Matrix.Identity, out aabbMin, out aabbMax);
            CreateBody(1.0f, gImpactMesh, Vector3.Zero);
            AddToDisposeQueue(gImpactMesh);
            gImpactMesh = null;

            var triangleMesh = new BvhTriangleMeshShape(indexVertexArray, true);

            triangleMesh.CalculateLocalInertia(1.0f);
            triangleMesh.GetAabb(Matrix.Identity, out aabbMin, out aabbMax);
            CreateBody(1.0f, triangleMesh, Vector3.Zero);
            AddToDisposeQueue(triangleMesh);
            triangleMesh = null;

            indexVertexArray = null;


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

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

            ForceGC();
            TestWeakRefs();
            ClearRefs();
        }
示例#4
0
        public void Init(string MediaDir)
        {
            #region Configuracion Basica de World

            //Creamos el mundo fisico por defecto.
            collisionConfiguration = new DefaultCollisionConfiguration();
            dispatcher             = new CollisionDispatcher(collisionConfiguration);
            GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
            constraintSolver      = new SequentialImpulseConstraintSolver();
            overlappingPairCache  = new DbvtBroadphase(); //AxisSweep3(new BsVector3(-5000f, -5000f, -5000f), new BsVector3(5000f, 5000f, 5000f), 8192);
            dynamicsWorld         = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration);
            dynamicsWorld.Gravity = new TGCVector3(0, -100f, 0).ToBulletVector3();

            #endregion Configuracion Basica de World

            foreach (var mesh in meshes)
            {
                var buildingbody = BulletRigidBodyFactory.Instance.CreateRigidBodyFromTgcMesh(mesh);
                dynamicsWorld.AddRigidBody(buildingbody);
            }

            //Se crea un plano ya que esta escena tiene problemas
            //con la definición de triangulos para el suelo
            var floorShape = new StaticPlaneShape(TGCVector3.Up.ToBulletVector3(), 10);
            floorShape.LocalScaling = new TGCVector3().ToBulletVector3();
            var floorMotionState = new DefaultMotionState();
            var floorInfo        = new RigidBodyConstructionInfo(0, floorMotionState, floorShape);
            floorBody                 = new RigidBody(floorInfo);
            floorBody.Friction        = 1;
            floorBody.RollingFriction = 1;
            floorBody.Restitution     = 1f;
            floorBody.UserObject      = "floorBody";
            dynamicsWorld.AddRigidBody(floorBody);

            var loader = new TgcSceneLoader();
            ///Se crea una caja para que haga las veces del Hummer dentro del modelo físico
            TgcTexture texture  = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"\MeshCreator\Scenes\Deposito\Textures\box4.jpg");
            TGCBox     boxMesh1 = TGCBox.fromSize(new TGCVector3(20, 20, 20), texture);
            boxMesh1.Position = new TGCVector3(0, 10, 0);
            hummer            = boxMesh1.ToMesh("box");
            boxMesh1.Dispose();

            //Se crea el cuerpo rígido de la caja, en la definicio de CreateBox el ultimo parametro representa si se quiere o no
            //calcular el momento de inercia del cuerpo. No calcularlo lo que va a hacer es que la caja que representa el Hummer
            //no rote cuando colicione contra el mundo.
            hummerBody             = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(55, 20, 80), 10, hummer.Position, 0, 0, 0, 0.55f, false);
            hummerBody.Restitution = 0;
            hummerBody.Gravity     = new TGCVector3(0, -100, 0).ToBulletVector3();
            dynamicsWorld.AddRigidBody(hummerBody);

            //Se carga el modelo del Hummer
            hummer = loader.loadSceneFromFile(MediaDir + @"MeshCreator\\Meshes\\Vehiculos\\Hummer\\Hummer-TgcScene.xml").Meshes[0];

            leftright  = new TGCVector3(1, 0, 0);
            fowardback = new TGCVector3(0, 0, 1);
        }
示例#5
0
        public BasicDemoSimulation()
        {
            CollisionConfiguration = new DefaultCollisionConfiguration();
            Dispatcher             = new CollisionDispatcher(CollisionConfiguration);
            Broadphase             = new DbvtBroadphase();
            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration);

            CreateGround();
            CreateBoxes();
        }
示例#6
0
        public override void InitializeDemo()

        {
            // Setup the basic world

            SetTexturing(true);
            SetShadows(true);

            SetCameraDistance(5.0f);

            m_collisionConfiguration = new DefaultCollisionConfiguration();

            m_dispatcher = new CollisionDispatcher(m_collisionConfiguration);

            IndexedVector3 worldAabbMin = new IndexedVector3(-10000, -10000, -10000);
            IndexedVector3 worldAabbMax = new IndexedVector3(10000, 10000, 10000);

            m_broadphase = new AxisSweep3Internal(ref worldAabbMin, ref worldAabbMax, 0xfffe, 0xffff, 16384, null, true);
            //m_broadphase = new SimpleBroadphase(1000, null);
            m_constraintSolver = new SequentialImpulseConstraintSolver();

            m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);
            //m_dynamicsWorld.getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
            //m_dynamicsWorld.getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f;



            // Setup a big ground box
            {
                CollisionShape groundShape = new BoxShape(new IndexedVector3(200.0f, 10.0f, 200.0f));
                m_collisionShapes.Add(groundShape);
                IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(0, -10, 0);

                CollisionObject fixedGround = new CollisionObject();
                fixedGround.SetCollisionShape(groundShape);
                fixedGround.SetWorldTransform(ref groundTransform);
                fixedGround.SetUserPointer("Ground");
                m_dynamicsWorld.AddCollisionObject(fixedGround);
            }

            // Spawn one ragdoll
            IndexedVector3 startOffset = new IndexedVector3(1, 0.5f, 0);


            //string filename = @"c:\users\man\bullet\xna-ragdoll-constraints-output.txt";
            //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
            //BulletGlobals.g_streamWriter = new StreamWriter(filestream);


            SpawnRagdoll(ref startOffset, BulletGlobals.g_streamWriter);
            //startOffset = new IndexedVector3(-1,0.5f,0);
            //spawnRagdoll(ref startOffset);

            ClientResetScene();
        }
示例#7
0
        public UrdfDemoSimulation(string urdfFileName)
        {
            CollisionConfiguration = new DefaultCollisionConfiguration();
            Dispatcher             = new CollisionDispatcher(CollisionConfiguration);
            Broadphase             = new DbvtBroadphase();
            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration);

            CreateGround();

            LoadUrdf(urdfFileName);
        }
示例#8
0
        public void SetUp()
        {
            conf       = new DefaultCollisionConfiguration();
            dispatcher = new CollisionDispatcher(conf);
            broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
            world      = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf);

            broadphase.OverlappingPairUserCallback = new AxisSweepUserCallback();

            boxShape = new BoxShape(1);
        }
示例#9
0
        public Physics()
        {
            _Main = this;

            collisionConf = new DefaultCollisionConfiguration();
            dispatcher    = new CollisionDispatcher(collisionConf);

            broadphase     = new DbvtBroadphase();
            _World         = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConf);
            _World.Gravity = new Vector3(0, -10, 0);
        }
示例#10
0
 public virtual void Init(BulletExampleWall ctx)
 {
     Ctx = ctx;
     //Creamos el mundo fisico por defecto.
     collisionConfiguration = new DefaultCollisionConfiguration();
     dispatcher             = new CollisionDispatcher(collisionConfiguration);
     GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
     constraintSolver      = new SequentialImpulseConstraintSolver();
     overlappingPairCache  = new DbvtBroadphase(); //AxisSweep3(new BsVector3(-5000f, -5000f, -5000f), new BsVector3(5000f, 5000f, 5000f), 8192);
     dynamicsWorld         = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration);
     dynamicsWorld.Gravity = new TGCVector3(0, -20f, 0).ToBsVector;
 }
 public override void Init(GameModel env)
 {
     Env = env;
     //Creamos el mundo fisico por defecto.
     collisionConfiguration = new DefaultCollisionConfiguration();
     dispatcher             = new CollisionDispatcher(collisionConfiguration);
     //GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
     //constraintSolver = new SequentialImpulseConstraintSolver();
     overlappingPairCache  = new DbvtBroadphase(); //AxisSweep3(new BsVector3(-5000f, -5000f, -5000f), new BsVector3(5000f, 5000f, 5000f), 8192);
     dynamicsWorld         = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, null, collisionConfiguration);
     dynamicsWorld.Gravity = new TGCVector3(0, -10f, 0).ToBsVector;
 }
示例#12
0
 private void Init()
 {
     collisionConfiguration = new DefaultCollisionConfiguration();
     dispatcher             = new CollisionDispatcher(collisionConfiguration);
     GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
     constraintSolver     = new SequentialImpulseConstraintSolver();
     overlappingPairCache = new DbvtBroadphase();
     dynamicsWorld        = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration)
     {
         Gravity = gravityZero
     };
 }
示例#13
0
        public PhysicsWorld()
        {
            collisionConf = new DefaultCollisionConfiguration();

            btDispatcher    = new CollisionDispatcher(collisionConf);
            broadphase      = new DbvtBroadphase();
            btWorld         = new DiscreteDynamicsWorld(btDispatcher, broadphase, null, collisionConf);
            btWorld.Gravity = BM.Vector3.Zero;

            pointObj = new CollisionObject();
            pointObj.CollisionShape = new SphereShape(1);
        }
示例#14
0
        public PhysicsDriver()
        {
            // Collision configuration contains default setup for memory, collision setup
            _collision_config = new DefaultCollisionConfiguration();
            _dispatcher       = new CollisionDispatcher(_collision_config);
            _broadphase       = new DbvtBroadphase();
            _solver           = new SequentialImpulseConstraintSolver();

            _physics_world = new PhysicsWorld(_gravity, _dispatcher, _broadphase, _solver, _collision_config);
            ;
            _picking_distance_minimum = 10.0f;
        }
示例#15
0
        public void SetUp()
        {
            conf       = new DefaultCollisionConfiguration();
            dispatcher = new CollisionDispatcher(conf);
            broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
            world      = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf);

            broadphase.OverlappingPairUserCallback = new AxisSweepUserCallback();

            body1 = CreateBody(10.0f, new SphereShape(1.0f), new Vector3(2, 2, 0));
            body2 = CreateBody(1.0f, new SphereShape(1.0f), new Vector3(0, 2, 0));
        }
示例#16
0
        public void InitializeWorld()
        {
            DbvtBroadphase broadphase = new DbvtBroadphase();
            DefaultCollisionConfiguration     conf      = new DefaultCollisionConfiguration();
            CollisionDispatcher               dispacher = new CollisionDispatcher(conf);
            SequentialImpulseConstraintSolver solver    = new SequentialImpulseConstraintSolver();

            dynamicsWorld = new DiscreteDynamicsWorld(dispacher, broadphase, solver, conf);

            BulletSharp.Math.Vector3 gravity = new BulletSharp.Math.Vector3(0, -10, 0);
            dynamicsWorld.SetGravity(ref gravity);
        }
示例#17
0
        protected override void Init()
        {
            collisionShapes   = new List <CollisionShape>();
            collidersToUpdate = new List <ICollider>();
            collisionConf     = new DefaultCollisionConfiguration();
            broadphase        = new DbvtBroadphase();
            dispatcher        = new CollisionDispatcher(collisionConf);

            //ManifoldPoint.ContactAdded += Callback_ContactAdded;
            //PersistentManifold.ContactProcessed += Callback_ContactProcessed;
            //PersistentManifold.ContactDestroyed += Callback_ContactDestroyed;
        }
示例#18
0
        public BspDemoSimulation()
        {
            CollisionConfiguration = new DefaultCollisionConfiguration();
            Dispatcher             = new CollisionDispatcher(CollisionConfiguration);

            Broadphase = new DbvtBroadphase();

            World         = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration);
            World.Gravity = Up * -10.0f;

            LoadBspFile();
        }
示例#19
0
        public CollisionManager(Program debug)
        {
            var defaultCollisionConfiguration = new DefaultCollisionConfiguration();
            var collisionDispatcher           = new CollisionDispatcher(defaultCollisionConfiguration);
            var broadphase = new DbvtBroadphase();

            this.World = new CollisionWorld(collisionDispatcher, broadphase, defaultCollisionConfiguration);
            if (debug != null)
            {
                this.World.DebugDrawer = new BulletDebugDrawer(debug);
            }
        }
示例#20
0
            public ChCollisionSystemBullet(uint max_objects, double scene_size)
            {
                // btDefaultCollisionConstructionInfo conf_info(...); ***TODO***
                bt_collision_configuration = new DefaultCollisionConfiguration();

                bt_dispatcher = new CollisionDispatcher(bt_collision_configuration);
                //((btDefaultCollisionConfiguration*)bt_collision_configuration)->setConvexConvexMultipointIterations(4,4);

                //***OLD***
                float          sscene_size  = (float)scene_size;
                IndexedVector3 worldAabbMin = new IndexedVector3(-sscene_size, -sscene_size, -sscene_size);
                IndexedVector3 worldAabbMax = -worldAabbMin;//new IndexedVector3(sscene_size, sscene_size, sscene_size);

                // bt_broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax, max_objects, 0, true); // true for disabling
                // raycast accelerator

                //***NEW***
                bt_broadphase = new AxisSweep3Internal(ref worldAabbMin, ref worldAabbMax, 0xfffe, 0xffff, 16384, null, false);
                //bt_broadphase = new DbvtBroadphase();

                bt_collision_world = new CollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);

                // TO DO!!!

                // custom collision for 2D arc-segment case

                /* CollisionAlgorithmCreateFunc m_collision_arc_seg = new ArcSegmentCollisionAlgorithm.CreateFunc;
                 * btCollisionAlgorithmCreateFunc* m_collision_seg_arc = new btArcSegmentCollisionAlgorithm::CreateFunc;
                 * m_collision_seg_arc->m_swapped = true;
                 * bt_dispatcher->registerCollisionCreateFunc(ARC_SHAPE_PROXYTYPE, SEGMENT_SHAPE_PROXYTYPE, m_collision_arc_seg);
                 * bt_dispatcher->registerCollisionCreateFunc(SEGMENT_SHAPE_PROXYTYPE, ARC_SHAPE_PROXYTYPE, m_collision_seg_arc);
                 *
                 * // custom collision for 2D arc-arc case
                 * btCollisionAlgorithmCreateFunc* m_collision_arc_arc = new btArcArcCollisionAlgorithm::CreateFunc;
                 * bt_dispatcher->registerCollisionCreateFunc(ARC_SHAPE_PROXYTYPE, ARC_SHAPE_PROXYTYPE, m_collision_arc_arc);*/

                // custom collision for C::E triangles:
                //  CollisionAlgorithmCreateFunc m_collision_cetri_cetri = new CEtriangleShapeCollisionAlgorithm.CreateFunc;
                // bt_dispatcher.RegisterCollisionCreateFunc((int)BroadphaseNativeTypes.CE_TRIANGLE_SHAPE_PROXYTYPE, (int)BroadphaseNativeTypes.CE_TRIANGLE_SHAPE_PROXYTYPE, m_collision_cetri_cetri);

                // custom collision for point-point case (in point clouds, just never create point-point contacts)
                //btCollisionAlgorithmCreateFunc* m_collision_point_point = new btPointPointCollisionAlgorithm::CreateFunc;

                /* void* mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc), 16);
                 * btCollisionAlgorithmCreateFunc* m_emptyCreateFunc = new (mem) btEmptyAlgorithm::CreateFunc;
                 * bt_dispatcher->registerCollisionCreateFunc(POINT_SHAPE_PROXYTYPE, POINT_SHAPE_PROXYTYPE, m_emptyCreateFunc);
                 * bt_dispatcher->registerCollisionCreateFunc(POINT_SHAPE_PROXYTYPE, BOX_SHAPE_PROXYTYPE, bt_collision_configuration->getCollisionAlgorithmCreateFunc(SPHERE_SHAPE_PROXYTYPE, BOX_SHAPE_PROXYTYPE)); // just for speedup
                 * bt_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE, POINT_SHAPE_PROXYTYPE, bt_collision_configuration->getCollisionAlgorithmCreateFunc(BOX_SHAPE_PROXYTYPE, SPHERE_SHAPE_PROXYTYPE)); // just for speedup
                 *
                 * // custom collision for GIMPACT mesh case too
                 * btGImpactCollisionAlgorithm::registerAlgorithm(bt_dispatcher);*/
            }
示例#21
0
        public override void InitializeDemo()
        {
            SetCameraDistance(50f);

            m_collisionConfiguration = new DefaultCollisionConfiguration();

            ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
            m_dispatcher = new CollisionDispatcher(m_collisionConfiguration);


            IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000);
            IndexedVector3 worldMax = -worldMin;
            //m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false);

            //m_broadphase = new DbvtBroadphase();
            IOverlappingPairCache pairCache = null;

            //pairCache = new SortedOverlappingPairCache();

            m_broadphase = new SimpleBroadphase(1000, pairCache);

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

            m_constraintSolver = sol;

            m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);

            IndexedVector3 gravity = new IndexedVector3(0, -10, 0);

            m_dynamicsWorld.SetGravity(ref gravity);

            ///create a few basic rigid bodies
            IndexedVector3 halfExtents = new IndexedVector3(50, 50, 50);
            //IndexedVector3 halfExtents = new IndexedVector3(10, 10, 10);
            CollisionShape groundShape = new BoxShape(ref halfExtents);

            //CollisionShape groundShape = new StaticPlaneShape(new IndexedVector3(0,1,0), 50);

            m_collisionShapes.Add(groundShape);

            IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, -50, 0));
            //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0));
            float mass = 0f;

            LocalCreateRigidBody(mass, ref groundTransform, groundShape);
            CollisionShape shape        = SetupShape();
            IndexedMatrix  objTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, 2, 0));

            LocalCreateRigidBody(mass, ref objTransform, shape);
            //ClientResetScene();
        }
        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;
        }
示例#23
0
        public CollisionManager(Program debug)
        {
            var defaultCollisionConfiguration = new DefaultCollisionConfiguration( );
            var collisionDispatcher           = new CollisionDispatcher(defaultCollisionConfiguration);
            var broadphase = new AxisSweep3(new Vector3(-100, -100, -100), new Vector3(100, 100, 100));

            World = new CollisionWorld(collisionDispatcher, broadphase, defaultCollisionConfiguration);

            if (debug != null)
            {
                this.World.DebugDrawer = new BulletDebugDrawer(debug);
            }
        }
        public BulletXmlImportDemoSimulation()
        {
            CollisionConfiguration = new DefaultCollisionConfiguration();
            Dispatcher             = new CollisionDispatcher(CollisionConfiguration);
            Broadphase             = new DbvtBroadphase();
            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration);

            _importer = new BulletXmlWorldImporter(World);
            if (!_importer.LoadFile(Path.Combine("data", "bullet_basic.xml")))
            {
                //throw new FileNotFoundException();
            }
        }
示例#25
0
        public void SetUp()
        {
            conf       = new SoftBodyRigidBodyCollisionConfiguration();
            dispatcher = new CollisionDispatcher(conf);
            broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000),
                                        new Vector3(1000, 1000, 1000));
            solver = new DefaultSoftBodySolver();
            world  = new SoftRigidDynamicsWorld(dispatcher, broadphase, null, conf, solver);

            softBodyWorldInfo = new SoftBodyWorldInfo();
            softBody          = new SoftBody(softBodyWorldInfo);
            world.AddSoftBody(softBody);
        }
示例#26
0
        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher    = new CollisionDispatcher(CollisionConf);

            Broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
            Solver     = new SequentialImpulseConstraintSolver();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.DispatchInfo.AllowedCcdPenetration = 0.0001f;
            //World.Gravity = Freelook.Up * -10.0f;

            Matrix startTransform = Matrix.Translation(10.210098f, -1.6433364f, 16.453260f);

            ghostObject = new PairCachingGhostObject();
            ghostObject.WorldTransform = startTransform;
            Broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback());

            const float characterHeight = 1.75f;
            const float characterWidth  = 1.75f;
            ConvexShape capsule         = new CapsuleShape(characterWidth, characterHeight);

            ghostObject.CollisionShape = capsule;
            ghostObject.CollisionFlags = CollisionFlags.CharacterObject;

            const float stepHeight = 0.35f;

            character = new KinematicCharacterController(ghostObject, capsule, stepHeight);

            BspLoader bspLoader = new BspLoader();

            //string filename = UnityEngine.Application.dataPath + "/BulletUnity/Examples/Scripts/BulletSharpDemos/CharacterDemo/data/BspDemo.bsp";
            UnityEngine.TextAsset bytes      = (UnityEngine.TextAsset)UnityEngine.Resources.Load("BspDemo");
            System.IO.Stream      byteStream = new System.IO.MemoryStream(bytes.bytes);
            bspLoader.LoadBspFile(byteStream);
            BspConverter bsp2Bullet = new BspToBulletConverter(this);

            bsp2Bullet.ConvertBsp(bspLoader, 0.1f);

            World.AddCollisionObject(ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter);

            World.AddAction(character);

            Vector3 v1 = new Vector3(0f, 0f, 0f);
            Vector3 v2 = new Vector3(0f, 0f, 0f);

            convexResultCallback = new ClosestConvexResultCallback(ref v1, ref v2);
            convexResultCallback.CollisionFilterMask = (short)CollisionFilterGroups.StaticFilter;
            cameraSphere = new SphereShape(0.2f);
        }
示例#27
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);

            // create the ground
            var groundShape = new BoxShape(50, 50, 50);

            _collisionShapes.Add(groundShape);
            CollisionObject ground = CreateStaticBody(Matrix.Translation(0, -50, 0), groundShape);

            ground.UserObject = "Ground";

            // create a few dynamic rigidbodies
            var colShape = new BoxShape(1);

            _collisionShapes.Add(colShape);

            float   mass         = 1.0f;
            Vector3 localInertia = colShape.CalculateLocalInertia(mass);

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

            for (int y = 0; y < ArraySizeY; y++)
            {
                for (int x = 0; x < ArraySizeX; x++)
                {
                    for (int z = 0; z < ArraySizeZ; z++)
                    {
                        Matrix startTransform = Matrix.Translation(
                            _startPosition + 2 * new Vector3(x, y, z));

                        // using motionstate is recommended, it provides interpolation capabilities
                        // and only synchronizes 'active' objects
                        rbInfo.MotionState = new DefaultMotionState(startTransform);
                        var body = new RigidBody(rbInfo);

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

                        World.AddRigidBody(body);
                    }
                }
            }

            rbInfo.Dispose();
        }
示例#28
0
        public override void InitializeDemo()
        {
            m_maxIterations = 500;
            SetCameraDistance(SCALING * 50f);

            //string filename = @"E:\users\man\bullet\xna-basic-output-1.txt";
            //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
            //BulletGlobals.g_streamWriter = new StreamWriter(filestream);

            ///collision configuration contains default setup for memory, collision setup
            m_collisionConfiguration = new DefaultCollisionConfiguration();

            ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
            m_dispatcher = new CollisionDispatcher(m_collisionConfiguration);

            m_broadphase = new DbvtBroadphase();
            IOverlappingPairCache pairCache = null;
            //pairCache = new SortedOverlappingPairCache();

            //m_broadphase = new SimpleBroadphase(1000, pairCache);

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

            m_constraintSolver = sol;

            m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);

            IndexedVector3 gravity = new IndexedVector3(0, -10, 0);

            m_dynamicsWorld.SetGravity(ref gravity);

            ///create a few basic rigid bodies
            IndexedVector3 halfExtents = new IndexedVector3(50, 50, 50);
            //IndexedVector3 halfExtents = new IndexedVector3(10, 10, 10);
            CollisionShape groundShape = new BoxShape(ref halfExtents);

            //CollisionShape groundShape = new StaticPlaneShape(new IndexedVector3(0,1,0), 50);

            m_collisionShapes.Add(groundShape);

            IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, -52, 0));
            //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0));
            float mass = 0f;

            LocalCreateRigidBody(mass, ref groundTransform, groundShape);

            CreateScene5(20);

            ClientResetScene();
        }
示例#29
0
        public FeatherStoneDemoSimulation()
        {
            CollisionConfiguration = new DefaultCollisionConfiguration();
            Dispatcher             = new CollisionDispatcher(CollisionConfiguration);
            Broadphase             = new DbvtBroadphase();
            _solver        = new MultiBodyConstraintSolver();
            MultiBodyWorld = new MultiBodyDynamicsWorld(Dispatcher, Broadphase, _solver, CollisionConfiguration);

            CreateGround();

            int  numLinks        = 5;
            bool spherical       = true;
            bool floatingBase    = false;
            var  basePosition    = new Vector3(-0.4f, 3.0f, 0.0f);
            var  baseHalfExtents = new Vector3(0.05f, 0.37f, 0.1f);
            var  linkHalfExtents = new Vector3(0.05f, 0.37f, 0.1f);
            var  multiBody       = CreateFeatherstoneMultiBody(MultiBodyWorld, numLinks, basePosition, baseHalfExtents, linkHalfExtents, spherical, floatingBase);

            bool damping = true;

            if (damping)
            {
                multiBody.LinearDamping  = 0.1f;
                multiBody.AngularDamping = 0.9f;
            }
            else
            {
                multiBody.LinearDamping  = 0;
                multiBody.AngularDamping = 0;
            }

            if (numLinks > 0)
            {
                float q0 = 45.0f * (float)Math.PI / 180.0f;
                if (spherical)
                {
                    Quaternion quat0 = Quaternion.RotationAxis(Vector3.Normalize(new Vector3(1, 1, 0)), q0);
                    quat0.Normalize();
                    multiBody.SetJointPosMultiDof(0, new float[] { quat0.X, quat0.Y, quat0.Z, quat0.W });
                }
                else
                {
                    multiBody.SetJointPosMultiDof(0, new float[] { q0 });
                }
            }
            CreateColliders(multiBody, baseHalfExtents, linkHalfExtents);


            CreateRigidBody(1, Matrix.Translation(0, -0.95f, 0), new BoxShape(0.5f, 0.5f, 0.5f));
        }
示例#30
0
        protected override void OnInitializePhysics()
        {
            // 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);

            CreateGround();
            CreateBoxes();
        }
示例#31
0
        public void SetUp()
        {
            conf       = new DefaultCollisionConfiguration();
            dispatcher = new CollisionDispatcher(conf);
            broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
            world      = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf);

            action = new Action();
            world.AddAction(action);
            world.AddAction(action);
            world.RemoveAction(action);
            world.RemoveAction(action);
            world.AddAction(action);
        }
示例#32
0
		private static void Main(string[] args)
		{
			var collisionConfig = new DefaultCollisionConfiguration();
			var dispatcher = new CollisionDispatcher(collisionConfig);
			var pairCache = new DbvtBroadphase();
			var solver = new SequentialImpulseConstraintSolver();

			var dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, pairCache, solver, collisionConfig);
			dynamicsWorld.Gravity = new Vector3(0, -10, 0);

			var groundShape = new BoxShape(new Vector3(50, 50, 50));
			var groundTransform = Matrix.CreateTranslation(0, -56, 0);

			{
				float mass = 0;
				bool isDynamic = mass != 0;
				Vector3 localInertia = Vector3.Zero;

				if (isDynamic)
					localInertia = groundShape.CalculateLocalInertia(mass);

				var motionState = new DefaultMotionState(groundTransform);
				var rbinfo = new RigidBodyConstructionInfo(mass, motionState, groundShape, localInertia);
				var body = new RigidBody(rbinfo);

				dynamicsWorld.AddRigidBody(body);
			}

			{
				var collisionShape = new SphereShape(1);
				var transform = Matrix.Identity;
				float mass = 1;
				bool isDynamic = mass != 0;
				Vector3 localInertia = Vector3.Zero;

				if (isDynamic)
					localInertia = collisionShape.CalculateLocalInertia(mass);

				transform.Translation = new Vector3(2, 10, 0);

				var motionState = new DefaultMotionState(transform);
				var rbinfo = new RigidBodyConstructionInfo(mass, motionState, collisionShape, localInertia);
				var body = new RigidBody(rbinfo);

				dynamicsWorld.AddRigidBody(body);
			}

			Console.WriteLine("Starting simulation");

			for (int i = 0; i < 100; i++)
			{
				dynamicsWorld.StepSimulation(1f / 60f, 10);

				for (int j = dynamicsWorld.GetNumCollisionObjects() - 1; j >= 0; j--)
				{
					var obj = dynamicsWorld.GetCollisionObjectArray()[j];
					var body = (RigidBody)obj;

					if (body != null && body.GetMotionState() != null)
					{
						Matrix transform = Matrix.Identity;

						body.GetMotionState().GetWorldTransform(ref transform);

						Console.WriteLine("Object@{0} Position={1}", body.GetHashCode(), transform.Translation);
					}
				}
			}

			Console.Read();
		}
示例#33
0
		public CollisionPairCallback(DispatcherInfo dispatchInfo,CollisionDispatcher dispatcher)
		{
			m_dispatchInfo = dispatchInfo;
			m_dispatcher = dispatcher;
		}