Esempio n. 1
0
        public override void InitializeDemo()
        {
            //	std::cerr << "initializing...\n";

            m_nearClip = 1f;
            m_farClip  = 1000f;

            m_aspect      = m_glutScreenWidth / m_glutScreenHeight;
            m_perspective = IndexedMatrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), m_aspect, m_nearClip, m_farClip);


            // set up basic state
            m_upAxis    = 1;                     // start with Y-axis as "up"
            m_type      = PHY_ScalarType.PHY_FLOAT;
            m_model     = eTerrainModel.eRadial; //eFractal;
            m_isDynamic = true;

            // set up the physics world
            m_collisionConfiguration = new DefaultCollisionConfiguration();
            m_dispatcher             = new CollisionDispatcher(m_collisionConfiguration);
            IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000);
            IndexedVector3 worldMax = new IndexedVector3(1000, 1000, 1000);

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

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

            // initialize axis- or type-dependent physics from here
            ClientResetScene();
        }
Esempio n. 2
0
        //----------------------------------------------------------------------------------------------


        public void InitialiseWorld(ref DiscreteDynamicsWorld world)
        {
            IndexedVector3       worldMin = new IndexedVector3(-1000, -1000, -1000);
            IndexedVector3       worldMax = -worldMin;
            IBroadphaseInterface bp       = 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();
            DefaultCollisionConfiguration     collisionConfig = new DefaultCollisionConfiguration();

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

            world = new DiscreteDynamicsWorld(dispatcher, bp, sol, collisionConfig);

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

            world.SetGravity(ref gravity);
            world.SetDebugDrawer(BulletGlobals.gDebugDraw);
        }
Esempio n. 3
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();
        }
Esempio n. 4
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);*/
            }
Esempio n. 5
0
        public BulletXNAPhysicsComponent(Game game, ICollisionConfiguration collisionConf, IConstraintSolver solver, Vector3 gravity)
            : base(game)
        {
            CollisionDispatcher Dispatcher = new CollisionDispatcher(collisionConf);

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

            //broadphase = new DbvtBroadphase();


            World = new DiscreteDynamicsWorld(Dispatcher, broadphase, solver, collisionConf);
            IndexedVector3 iv3Gravity = new IndexedVector3(gravity.X, gravity.Y, gravity.Z);

            World.SetGravity(ref iv3Gravity);
        }
Esempio n. 6
0
        public override void InitializeDemo()
        {
            //maxiterations = 10;
            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);


            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);
            {
                //create a few dynamic rigidbodies
                CollisionShape colShape = new BoxShape(new IndexedVector3(SCALING, SCALING, SCALING));
                //CollisionShape colShape = BuildCorner();
                //btCollisionShape* colShape = new btSphereShape(btScalar(1.));
                //CollisionShape colShape = new CylinderShape(new IndexedVector3(1f, 1, 1f));
                m_collisionShapes.Add(colShape);

                /// Create Dynamic Objects
                IndexedMatrix startTransform = IndexedMatrix.Identity;

                mass = 1f;

                //rigidbody is dynamic if and only if mass is non zero, otherwise static
                bool isDynamic = mass != 0f;

                IndexedVector3 localInertia = IndexedVector3.Zero;
                if (isDynamic)
                {
                    colShape.CalculateLocalInertia(mass, out localInertia);
                }
                float start_x = START_POS_X - ARRAY_SIZE_X / 2;
                float start_y = START_POS_Y;
                float start_z = START_POS_Z - ARRAY_SIZE_Z / 2;

                for (int k = 0; k < ARRAY_SIZE_Y; k++)
                {
                    for (int i = 0; i < ARRAY_SIZE_X; i++)
                    {
                        for (int j = 0; j < ARRAY_SIZE_Z; j++)
                        {
                            startTransform._origin = (new IndexedVector3(2.0f * i + start_x, 20 + 2.0f * k + start_y, 2.0f * j + start_z) * SCALING);

                            //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
                            DefaultMotionState        myMotionState = new DefaultMotionState(startTransform, IndexedMatrix.Identity);
                            RigidBodyConstructionInfo rbInfo        = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia);
                            RigidBody body = new RigidBody(rbInfo);
                            //body->setContactProcessingThreshold(colShape->getContactBreakingThreshold());
                            //body.SetActivationState(ActivationState.ISLAND_SLEEPING);

                            m_dynamicsWorld.AddRigidBody(body);
                            //body.SetActivationState(ActivationState.ISLAND_SLEEPING);
                            body.SetUserPointer(String.Format("Box X{0} Y{1} Z{2}", k, i, j));
                        }
                    }
                }
            }

            //ClientResetScene();
        }
Esempio n. 7
0
        public override void InitializeDemo()
        {
            m_cameraDistance = 10.0f;
            //string filename = @"e:\users\man\bullet\gimpact-demo-xna.txt";
            //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
            //BulletGlobals.g_streamWriter = new StreamWriter(filestream);

            /// Init Bullet
            m_collisionConfiguration = new DefaultCollisionConfiguration();

            m_dispatcher = new CollisionDispatcher(m_collisionConfiguration);
            //btOverlappingPairCache* broadphase = new btSimpleBroadphase();
            //m_broadphase = new btSimpleBroadphase();

            int            maxProxies   = 1024;
            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, false);
            //m_broadphase = new SimpleBroadphase(16384,null);
            m_constraintSolver = new SequentialImpulseConstraintSolver();

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

            //create trimesh model and shape
            InitGImpactCollision();



            /// Create Scene
            float         mass           = 0.0f;
            IndexedMatrix startTransform = IndexedMatrix.Identity;


            CollisionShape staticboxShape1 = new BoxShape(new IndexedVector3(200, 1, 200));//floor

            staticboxShape1.SetUserPointer("Floor");
            CollisionShape staticboxShape2 = new BoxShape(new IndexedVector3(1, 50, 200));//left wall

            staticboxShape1.SetUserPointer("LeftWall");
            CollisionShape staticboxShape3 = new BoxShape(new IndexedVector3(1, 50, 200));//right wall

            staticboxShape1.SetUserPointer("RightWall");
            CollisionShape staticboxShape4 = new BoxShape(new IndexedVector3(200, 50, 1));//front wall

            staticboxShape1.SetUserPointer("FrontWall");
            CollisionShape staticboxShape5 = new BoxShape(new IndexedVector3(200, 50, 1));//back wall

            staticboxShape1.SetUserPointer("BackWall");

            CompoundShape staticScenario = new CompoundShape();//static scenario

            startTransform._origin = new IndexedVector3(0, 0, 0);
            staticScenario.AddChildShape(ref startTransform, staticboxShape1);
            startTransform._origin = new IndexedVector3(-200, 25, 0);
            staticScenario.AddChildShape(ref startTransform, staticboxShape2);
            startTransform._origin = new IndexedVector3(200, 25, 0);
            staticScenario.AddChildShape(ref startTransform, staticboxShape3);
            startTransform._origin = new IndexedVector3(0, 25, 200);
            staticScenario.AddChildShape(ref startTransform, staticboxShape4);
            startTransform._origin = new IndexedVector3(0, 25, -200);
            staticScenario.AddChildShape(ref startTransform, staticboxShape5);

            startTransform._origin = new IndexedVector3(0, 0, 0);

            //RigidBody staticBody = LocalCreateRigidBody(mass, startTransform, staticScenario);
            RigidBody staticBody = LocalCreateRigidBody(mass, startTransform, staticboxShape1);


            staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_STATIC_OBJECT);

            //enable custom material callback
            staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);

            //static plane
            IndexedVector3 normal = new IndexedVector3(0.4f, 1.5f, -0.4f);

            normal.Normalize();
            CollisionShape staticplaneShape6 = new StaticPlaneShape(ref normal, 0.0f);   // A plane

            startTransform._origin = IndexedVector3.Zero;

            RigidBody staticBody2 = LocalCreateRigidBody(mass, startTransform, staticplaneShape6);

            staticBody2.SetCollisionFlags(staticBody2.GetCollisionFlags() | CollisionFlags.CF_STATIC_OBJECT);

            startTransform = IndexedMatrix.Identity;

            /// Create Dynamic Boxes
            {
                int numBoxes = 1;
                for (int i = 0; i < numBoxes; i++)
                {
                    CollisionShape boxShape = new BoxShape(new IndexedVector3(1, 1, 1));
                    //CollisionShape mesh = new BvhTriangleMeshShape(m_indexVertexArrays2,true,true);
                    startTransform._origin = new IndexedVector3(2 * i - (numBoxes - 1), 2, -3);
                    //startTransform._origin = new IndexedVector3(2 * i - 5, 10, -3);
                    //LocalCreateRigidBody(1, startTransform, m_trimeshShape2);
                    LocalCreateRigidBody(1, startTransform, boxShape);
                }
            }
        }
Esempio n. 8
0
        public override void InitializeDemo()
        {
            //maxiterations = 10;
            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);


            IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000);
            IndexedVector3 worldMax = -worldMin;

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

            IOverlappingPairCache pairCache = null;

            //pairCache = new SortedOverlappingPairCache();
            pairCache = new HashedOverlappingPairCache();

            m_broadphase = new DbvtBroadphase(pairCache);

            BulletGlobals.gDebugDraw = Game1.Instance.shape_drawer;

            //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));
            float         mass            = 0f;

            float topY    = 2.5f;
            float bottomY = 0.5f;

            float diff  = 10f;
            float left  = -(diff / 2f);
            float right = -left;


            LocalCreateRigidBody(mass, ref groundTransform, groundShape);
            {
                /// Create Dynamic Objects
                IndexedMatrix startTransform = IndexedMatrix.Identity;

                mass = 0f;

                //rigidbody is dynamic if and only if mass is non zero, otherwise static
                bool isDynamic = mass != 0f;


                RigidBody rb = null;

                //startTransform._origin = new IndexedVector3(left, topY, 0);
                //collisionTopLeftCorner = BuildCorner(vertices, topLeft);
                //rb = LocalCreateRigidBody(0f, startTransform, collisionTopLeftCorner);
                //rb.SetUserPointer("TopLeftCorner");

                //startTransform._origin = new IndexedVector3(right, topY, 0);
                //collisionTopRightCorner = BuildCorner(vertices, topRight);
                //rb = LocalCreateRigidBody(0f, startTransform, collisionTopRightCorner);
                //rb.SetUserPointer("TopRightCorner");

                startTransform._origin    = new IndexedVector3(left, bottomY, 0);
                collisionBottomLeftCorner = BuildCorner(vertices, bottomLeft);
                rb = LocalCreateRigidBody(0f, startTransform, collisionBottomLeftCorner);
                rb.SetUserPointer("BottomLeftCorner");

                startTransform._origin     = new IndexedVector3(right, bottomY, 0);
                collisionBottomRightCorner = BuildCorner(vertices, bottomRight);
                rb = LocalCreateRigidBody(0f, startTransform, collisionBottomRightCorner);
                rb.SetUserPointer("BottomRightCorner");


                startTransform._origin = IndexedVector3.Zero;

                m_playerSphere = LocalCreateRigidBody(1f, startTransform, new SphereShape(0.25f));
                m_playerSphere.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
            }



            BulletGlobals.gDebugDraw.SetDebugMode(BulletMonogame.LinearMath.DebugDrawModes.DBG_DrawAabb | BulletMonogame.LinearMath.DebugDrawModes.DBG_DrawNormals | BulletMonogame.LinearMath.DebugDrawModes.DBG_DrawContactPoints);
            m_dynamicsWorld.SetDebugDrawer(BulletGlobals.gDebugDraw);

            //ClientResetScene();
        }
Esempio n. 9
0
        public override void InitializeDemo()
        {
            base.InitializeDemo();
            SetCameraDistance(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);

            IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000);
            IndexedVector3 worldMax = -worldMin;

            m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false);
            //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);
            m_dynamicsWorld.GetDispatchInfo().SetAllowedCcdPenetration(0.0001f);

            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);



            #region CharacterController
            IndexedMatrix startTransform = IndexedMatrix.Identity;
            //startTransform.setOrigin (btVector3(0.0, 4.0, 0.0));
            startTransform._origin = new IndexedVector3(10.210098f, -1.6433364f, 16.453260f);

            m_ghostObject = new PairCachingGhostObject();
            m_ghostObject.SetWorldTransform(startTransform);
            m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback());
            float       characterHeight = 1.75f;
            float       characterWidth  = 1.75f;
            ConvexShape capsule         = new CapsuleShape(characterWidth, characterHeight);
            m_ghostObject.SetCollisionShape(capsule);
            m_ghostObject.SetCollisionFlags(CollisionFlags.CF_CHARACTER_OBJECT);

            float stepHeight = 0.35f;
            int   upAxis     = 1;
            m_character = new KinematicCharacterController(m_ghostObject, capsule, stepHeight, upAxis);

            m_dynamicsWorld.AddCollisionObject(m_ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter);
            m_dynamicsWorld.AddAction(m_character);

            #endregion
        }
        public override void InitializeDemo()
        {
            //string filename = @"E:\users\man\bullet\xna-concaveray-output-1.txt";
            //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
            //BulletGlobals.g_streamWriter = new StreamWriter(filestream);

            m_cameraDistance = 400f;
            m_farClip        = 1500f;
            m_perspective    = IndexedMatrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), m_aspect, m_nearClip, m_farClip);


            m_animatedMesh = true;
            base.InitializeDemo();
            int totalTriangles = 2 * (NUM_VERTS_X - 1) * (NUM_VERTS_Y - 1);

            gVertices = new ObjectArray <IndexedVector3>(totalVerts);
            int indicesTotal = totalTriangles * 3;

            gIndices = new ObjectArray <int>(indicesTotal);

            BulletGlobals.gContactAddedCallback = null;

            SetVertexPositions(waveheight, 0f);

            int vertStride  = 1;
            int indexStride = 3;

            int index = 0;

            //for (int i=0;i<NUM_VERTS_X-1;i++)
            //{
            //    for (int j=0;j<NUM_VERTS_Y-1;j++)
            //    {
            //        gIndices[index++] = j * NUM_VERTS_X + i;
            //        gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;
            //        gIndices[index++] = j * NUM_VERTS_X + i + 1;

            //        gIndices[index++] = j * NUM_VERTS_X + i;
            //        gIndices[index++] = (j + 1) * NUM_VERTS_X + i;
            //        gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;

            //    }
            //}

            for (int i = 0; i < NUM_VERTS_X - 1; i++)
            {
                for (int j = 0; j < NUM_VERTS_Y - 1; j++)
                {
                    gIndices[index++] = j * NUM_VERTS_X + i;
                    gIndices[index++] = j * NUM_VERTS_X + i + 1;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;

                    gIndices[index++] = j * NUM_VERTS_X + i;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i + 1;
                    gIndices[index++] = (j + 1) * NUM_VERTS_X + i;
                }
            }

            TriangleIndexVertexArray indexVertexArrays = new TriangleIndexVertexArray(totalTriangles,
                                                                                      gIndices, indexStride, totalVerts, gVertices, vertStride);

            bool useQuantizedAabbCompression = true;

            float minX = NUM_VERTS_X * TRIANGLE_SIZE * 0.5f;
            float minZ = NUM_VERTS_Y * TRIANGLE_SIZE * 0.5f;

            //OptimizedBvh bvh = new OptimizedBvh();
            IndexedVector3 aabbMin = new IndexedVector3(-minX, -5, -minZ);
            IndexedVector3 aabbMax = new IndexedVector3(minX, 5, minZ);



            m_trimeshShape = new BvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression, ref aabbMin, ref aabbMax, true);
            //m_trimeshShape = new BvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression,true);
            IndexedVector3 scaling     = IndexedVector3.One;
            CollisionShape groundShape = m_trimeshShape;
            //groundShape = new TriangleMeshShape(indexVertexArrays);
            //groundShape = new StaticPlaneShape(IndexedVector3.Up, 0f);
            IndexedVector3 up = new IndexedVector3(0.4f, 1, 0);

            up.Normalize();
            //groundShape = new StaticPlaneShape(up, 0f);
            //groundShape = new BoxShape(new IndexedVector3(1000, 10, 1000));
            m_collisionConfiguration = new DefaultCollisionConfiguration();
            m_dispatcher             = new      CollisionDispatcher(m_collisionConfiguration);

            IndexedVector3 worldMin = aabbMin;
            IndexedVector3 worldMax = aabbMax;

            m_broadphase       = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false);
            m_constraintSolver = new SequentialImpulseConstraintSolver();
            m_dynamicsWorld    = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);

            float         mass           = 0f;
            IndexedMatrix startTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(2, -2, 0));


            startTransform = IndexedMatrix.Identity;
            staticBody     = LocalCreateRigidBody(mass, ref startTransform, groundShape);

            staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_KINEMATIC_OBJECT);            //STATIC_OBJECT);

            //enable custom material callback
            staticBody.SetCollisionFlags(staticBody.GetCollisionFlags() | CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);

            //m_raycastBar = new btRaycastBar (m_debugDraw,4000.0f, 0.0f,-1000,30);
            m_raycastBar       = new btRaycastBar(m_debugDraw, 300.0f, 0.0f, -1000, 200, worldMin.X, worldMax.X);
            m_raycastBar.min_x = -100;
            m_raycastBar.max_x = -100;

            ClientResetScene();
        }
Esempio n. 11
0
        //----------------------------------------------------------------------------------------------------------------

        public override void InitializeDemo()
        {
            CollisionShape groundShape = new BoxShape(new IndexedVector3(50, 0.1f, 50));

            IndexedVector3 wheelDimensions = new IndexedVector3(wheelWidth, wheelRadius, wheelRadius);

            m_wheelShape = new CylinderShapeX(ref wheelDimensions);

            m_collisionShapes.Add(groundShape);
            m_collisionConfiguration = new DefaultCollisionConfiguration();
            m_dispatcher             = new CollisionDispatcher(m_collisionConfiguration);
            IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000);
            IndexedVector3 worldMax = new IndexedVector3(1000, 1000, 1000);

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

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

            IndexedMatrix tr = IndexedMatrix.CreateTranslation(0, -10, 0);

            LocalCreateRigidBody(0f, ref tr, groundShape);

#if true
            CollisionShape chassisShape = new BoxShape(new IndexedVector3(1.0f, 0.5f, 2.0f));
            //CollisionShape chassisShape = new BoxShape(new IndexedVector3(1.0f, 0.5f, 1.0f));
            m_collisionShapes.Add(chassisShape);

            CompoundShape compound = new CompoundShape();
            m_collisionShapes.Add(compound);
            //localTrans effectively shifts the center of mass with respect to the chassis
            IndexedMatrix localTrans = IndexedMatrix.CreateTranslation(0, 1, 0);

            compound.AddChildShape(ref localTrans, chassisShape);

            {
                CollisionShape suppShape = new BoxShape(new IndexedVector3(0.5f, 0.1f, 0.5f));
                //localTrans effectively shifts the center of mass with respect to the chassis
                IndexedMatrix suppLocalTrans = IndexedMatrix.CreateTranslation(0f, 1.0f, 2.5f);
                compound.AddChildShape(ref suppLocalTrans, suppShape);
            }

            tr._origin = IndexedVector3.Zero;

            m_carChassis = LocalCreateRigidBody(800f, ref tr, compound);//chassisShape);
#endif

            {
#if true
                CollisionShape liftShape = new BoxShape(new IndexedVector3(0.5f, 2.0f, 0.05f));
                m_collisionShapes.Add(liftShape);
                m_liftStartPos = new IndexedVector3(0.0f, 2.5f, 3.05f);
                IndexedMatrix liftTrans = IndexedMatrix.CreateTranslation(m_liftStartPos);
                m_liftBody = LocalCreateRigidBody(10f, ref liftTrans, liftShape);

                IndexedMatrix localA = MathUtil.SetEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f);
                localA._origin = new IndexedVector3(0f, 1.0f, 3.05f);

                IndexedMatrix localB = MathUtil.SetEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f);
                localB._origin = new IndexedVector3(0f, -1.5f, -0.05f);

                m_liftHinge = new HingeConstraint(m_carChassis, m_liftBody, ref localA, ref localB);
                MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "hinge aFrame", m_liftHinge.GetAFrame());
                MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, "hinge bFrame", m_liftHinge.GetBFrame());

                m_liftHinge.SetLimit(0.0f, 0.0f);
                m_dynamicsWorld.AddConstraint(m_liftHinge, true);

                CollisionShape forkShapeA = new BoxShape(new IndexedVector3(1.0f, 0.1f, 0.1f));
                m_collisionShapes.Add(forkShapeA);
                CompoundShape forkCompound = new CompoundShape();
                m_collisionShapes.Add(forkCompound);
                IndexedMatrix forkLocalTrans = IndexedMatrix.Identity;
                forkCompound.AddChildShape(ref forkLocalTrans, forkShapeA);

                CollisionShape forkShapeB = new BoxShape(new IndexedVector3(0.1f, 0.02f, 0.6f));
                m_collisionShapes.Add(forkShapeB);
                forkLocalTrans = IndexedMatrix.CreateTranslation(-0.9f, -0.08f, 0.7f);
                forkCompound.AddChildShape(ref forkLocalTrans, forkShapeB);

                CollisionShape forkShapeC = new BoxShape(new IndexedVector3(0.1f, 0.02f, 0.6f));
                m_collisionShapes.Add(forkShapeC);
                forkLocalTrans = IndexedMatrix.CreateTranslation(0.9f, -0.08f, 0.7f);
                forkCompound.AddChildShape(ref forkLocalTrans, forkShapeC);

                m_forkStartPos = new IndexedVector3(0.0f, 0.6f, 3.2f);
                IndexedMatrix forkTrans = IndexedMatrix.CreateTranslation(m_forkStartPos);

                m_forkBody = LocalCreateRigidBody(5f, ref forkTrans, forkCompound);

                localA = IndexedMatrix.Identity;
                localB = IndexedMatrix.Identity;
                localA._basis.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI);
                localA._origin = new IndexedVector3(0.0f, -1.9f, 0.05f);
                localB._basis.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI);
                localB._origin = new IndexedVector3(0.0f, 0.0f, -0.1f);

                m_forkSlider = new SliderConstraint(m_liftBody, m_forkBody, ref localA, ref localB, true);
                m_forkSlider.SetLowerLinLimit(0.1f);
                m_forkSlider.SetUpperLinLimit(0.1f);
                //		m_forkSlider.setLowerAngLimit(-LIFT_EPS);
                //		m_forkSlider.setUpperAngLimit(LIFT_EPS);
                m_forkSlider.SetLowerAngLimit(0.0f);
                m_forkSlider.SetUpperAngLimit(0.0f);
                m_dynamicsWorld.AddConstraint(m_forkSlider, true);
#endif
#if true
                CompoundShape loadCompound = new CompoundShape(false);
                m_collisionShapes.Add(loadCompound);
                CollisionShape loadShapeA = new BoxShape(new IndexedVector3(2.0f, 0.5f, 0.5f));
                m_collisionShapes.Add(loadShapeA);
                IndexedMatrix loadTrans = IndexedMatrix.Identity;
                loadCompound.AddChildShape(ref loadTrans, loadShapeA);
                CollisionShape loadShapeB = new BoxShape(new IndexedVector3(0.1f, 1.0f, 1.0f));
                m_collisionShapes.Add(loadShapeB);
                loadTrans = IndexedMatrix.CreateTranslation(2.1f, 0.0f, 0.0f);
                loadCompound.AddChildShape(ref loadTrans, loadShapeB);
                CollisionShape loadShapeC = new BoxShape(new IndexedVector3(0.1f, 1.0f, 1.0f));
                m_collisionShapes.Add(loadShapeC);
                loadTrans = IndexedMatrix.CreateTranslation(-2.1f, 0.0f, 0.0f);
                loadCompound.AddChildShape(ref loadTrans, loadShapeC);
                m_loadStartPos = new IndexedVector3(0.0f, -3.5f, 7.0f);
                loadTrans      = IndexedMatrix.CreateTranslation(m_loadStartPos);

                m_loadBody = LocalCreateRigidBody(4f, ref loadTrans, loadCompound);
#endif
            }
            //m_carChassis.setDamping(0.2f, 0.2f);

            ClientResetScene();

            /// create vehicle
            {
                m_vehicleRayCaster = new DefaultVehicleRaycaster(m_dynamicsWorld);
                m_vehicle          = new RaycastVehicle(m_tuning, m_carChassis, m_vehicleRayCaster);

                ///never deactivate the vehicle
                m_carChassis.SetActivationState(ActivationState.DISABLE_DEACTIVATION);

                m_dynamicsWorld.AddVehicle(m_vehicle);

                float connectionHeight = 1.2f;

                bool isFrontWheel = true;

                //choose coordinate system
                m_vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex);

                IndexedVector3 connectionPointCS0 = IndexedVector3.Zero;
                //connectionPointCS0 = new IndexedVector3(CUBE_HALF_EXTENTS, connectionHeight, CUBE_HALF_EXTENTS);
                //m_vehicle.addWheel(ref connectionPointCS0, ref wheelDirectionCS0, ref wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);

                connectionPointCS0 = new IndexedVector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), connectionHeight, 2.0f * CUBE_HALF_EXTENTS - wheelRadius);
                m_vehicle.AddWheel(ref connectionPointCS0, ref wheelDirectionCS0, ref wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);

                connectionPointCS0 = new IndexedVector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), connectionHeight, 2.0f * CUBE_HALF_EXTENTS - wheelRadius);
                m_vehicle.AddWheel(ref connectionPointCS0, ref wheelDirectionCS0, ref wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);

                //isFrontWheel = false;
                connectionPointCS0 = new IndexedVector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), connectionHeight, -2.0f * CUBE_HALF_EXTENTS + wheelRadius);
                m_vehicle.AddWheel(ref connectionPointCS0, ref wheelDirectionCS0, ref wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);

                connectionPointCS0 = new IndexedVector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), connectionHeight, -2.0f * CUBE_HALF_EXTENTS + wheelRadius);
                m_vehicle.AddWheel(ref connectionPointCS0, ref wheelDirectionCS0, ref wheelAxleCS, suspensionRestLength, wheelRadius, m_tuning, isFrontWheel);

                for (int i = 0; i < m_vehicle.GetNumWheels(); i++)
                {
                    WheelInfo wheel = m_vehicle.GetWheelInfo(i);
                    wheel.m_suspensionStiffness      = suspensionStiffness;
                    wheel.m_wheelsDampingRelaxation  = suspensionDamping;
                    wheel.m_wheelsDampingCompression = suspensionCompression;
                    wheel.m_frictionSlip             = wheelFriction;
                    wheel.m_rollInfluence            = rollInfluence;
                }
            }

            SetCameraDistance(36.0f);
            SetTexturing(true);
            SetShadows(true);
        }
Esempio n. 12
0
        public override void InitializeDemo()
        {
            m_collisionConfiguration = new DefaultCollisionConfiguration();
            m_dispatcher             = new CollisionDispatcher(m_collisionConfiguration);
            IndexedVector3 worldMin = new IndexedVector3(-1000, -1000, -1000);
            IndexedVector3 worldMax = new IndexedVector3(1000, 1000, 1000);

            m_broadphase       = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false);
            m_constraintSolver = new SequentialImpulseConstraintSolver();
            m_dynamicsWorld    = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);
            m_dynamicsWorld.SetDebugDrawer(m_debugDraw);

            SetCameraDistance(26f);

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

            m_collisionShapes.Add(groundShape);
            IndexedMatrix groundTransform = IndexedMatrix.Identity;

            groundTransform._origin = new IndexedVector3(0, -56, 0);
            RigidBody groundBody = LocalCreateRigidBody(0, ref groundTransform, groundShape);

            CollisionShape shape = new BoxShape(new IndexedVector3(CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS));

            m_collisionShapes.Add(shape);
            IndexedMatrix trans = IndexedMatrix.Identity;

            trans._origin = new IndexedVector3(0, 20, 0);

            float mass = 1f;

        #if true
            //point to point constraint (ball socket)
            //SEEMS OK
            {
                RigidBody body0 = LocalCreateRigidBody(mass, ref trans, shape);
                trans._origin = new IndexedVector3(2 * CUBE_HALF_EXTENTS, 20, 0);

                mass = 1f;
                RigidBody body1 = null;        //localCreateRigidBody( mass,trans,shape);

                IndexedVector3 pivotInA = new IndexedVector3(CUBE_HALF_EXTENTS, -CUBE_HALF_EXTENTS, -CUBE_HALF_EXTENTS);
                IndexedVector3 axisInA  = new IndexedVector3(0, 0, 1);

                IndexedVector3 pivotInB = body1 != null?body1.GetCenterOfMassTransform().Inverse() * (body0.GetCenterOfMassTransform() * (pivotInA)) : pivotInA;

                IndexedVector3 axisInB = body1 != null ? (body1.GetCenterOfMassTransform()._basis.Inverse() * (body1.GetCenterOfMassTransform()._basis *axisInA)) :
                                         body0.GetCenterOfMassTransform()._basis *axisInA;

                HingeConstraint hinge = new HingeConstraint(body0, ref pivotInA, ref axisInA, false);

                float targetVelocity  = 1f;
                float maxMotorImpulse = 1.0f;
                hinge.EnableAngularMotor(true, targetVelocity, maxMotorImpulse);

                m_dynamicsWorld.AddConstraint(hinge);        //p2p);
                hinge.SetDbgDrawSize(5f);
            }
        #endif

#if true
            //create a slider, using the generic D6 constraint
            // SEEMS OK
            {
                mass = 1f;
                IndexedVector3     sliderWorldPos    = new IndexedVector3(0, 10, 0);
                IndexedVector3     sliderAxis        = new IndexedVector3(1, 0, 0);
                float              angle             = 0f;//SIMD_RADS_PER_DEG * 10.f;
                IndexedBasisMatrix sliderOrientation = new IndexedBasisMatrix(Quaternion.CreateFromAxisAngle(sliderAxis.ToVector3(), angle));
                trans         = IndexedMatrix.Identity;
                trans._origin = sliderWorldPos;
                //trans.setBasis(sliderOrientation);
                sliderTransform = trans;

                d6body0 = LocalCreateRigidBody(mass, ref trans, shape);
                d6body0.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                RigidBody fixedBody1 = LocalCreateRigidBody(0, ref trans, null);
                m_dynamicsWorld.AddRigidBody(fixedBody1);

                IndexedMatrix frameInA, frameInB;
                frameInA         = IndexedMatrix.Identity;
                frameInB         = IndexedMatrix.Identity;
                frameInA._origin = new IndexedVector3(0, 5, 0);
                frameInB._origin = new IndexedVector3(0, 5, 0);

                //		bool useLinearReferenceFrameA = false;//use fixed frame B for linear llimits
                bool useLinearReferenceFrameA = true;        //use fixed frame A for linear llimits
                spSlider6Dof = new Generic6DofConstraint(fixedBody1, d6body0, ref frameInA, ref frameInB, useLinearReferenceFrameA);
                spSlider6Dof.SetLinearLowerLimit(ref lowerSliderLimit);
                spSlider6Dof.SetLinearUpperLimit(ref hiSliderLimit);

                //range should be small, otherwise singularities will 'explode' the constraint
                IndexedVector3 angularLower = new IndexedVector3(-1.5f, 0, 0);
                IndexedVector3 angularUpper = -angularLower;
                spSlider6Dof.SetAngularLowerLimit(ref angularLower);
                spSlider6Dof.SetAngularUpperLimit(ref angularUpper);
                //		slider.setAngularLowerLimit(IndexedVector3(0,0,0));
                //		slider.setAngularUpperLimit(IndexedVector3(0,0,0));

                spSlider6Dof.GetTranslationalLimitMotor().m_enableMotor[0] = true;
                spSlider6Dof.GetTranslationalLimitMotor().m_targetVelocity.X = -5.0f;
                spSlider6Dof.GetTranslationalLimitMotor().m_maxMotorForce.X = 0.1f;


                m_dynamicsWorld.AddConstraint(spSlider6Dof);
                spSlider6Dof.SetDbgDrawSize(5f);
            }
#endif
#if true
            {     // create a door using hinge constraint attached to the world
                CollisionShape pDoorShape = new BoxShape(new IndexedVector3(2.0f, 5.0f, 0.2f));
                m_collisionShapes.Add(pDoorShape);
                IndexedMatrix doorTrans = IndexedMatrix.Identity;
                doorTrans._origin = new IndexedVector3(-5.0f, -2.0f, 0.0f);
                RigidBody pDoorBody = LocalCreateRigidBody(1.0f, ref doorTrans, pDoorShape);
                pDoorBody.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                IndexedVector3 btPivotA = new IndexedVector3(10f + 2.1f, -2.0f, 0.0f);   // right next to the door slightly outside
                IndexedVector3 btAxisA  = new IndexedVector3(0.0f, 1.0f, 0.0f);          // pointing upwards, aka Y-axis

                spDoorHinge = new HingeConstraint(pDoorBody, ref btPivotA, ref btAxisA, false);

                spDoorHinge.SetLimit(-MathUtil.SIMD_PI * 0.25f, MathUtil.SIMD_PI * 0.25f);
                m_dynamicsWorld.AddConstraint(spDoorHinge);
                spDoorHinge.SetDbgDrawSize(5.0f);
            }
#endif
#if true
            { // create a generic 6DOF constraint
                // SEEMS OK - But debug draw a bit wrong?
                IndexedMatrix tr = IndexedMatrix.Identity;
                tr._origin = new IndexedVector3(10f, 6f, 0f);
                //tr.getBasis().setEulerZYX(0,0,0);
                //		RigidBody pBodyA = localCreateRigidBody( mass, tr, shape);
                RigidBody pBodyA = LocalCreateRigidBody(0.0f, ref tr, shape);
                //		RigidBody pBodyA = localCreateRigidBody( 0.0, tr, 0);
                pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION);

                tr         = IndexedMatrix.Identity;
                tr._origin = new IndexedVector3(0f, 6f, 0f);
                //tr.getBasis().setEulerZYX(0,0,0);
                RigidBody pBodyB = LocalCreateRigidBody(mass, ref tr, shape);
                pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION);

                IndexedMatrix frameInA, frameInB;
                frameInA = IndexedMatrix.CreateTranslation(-5, 0, 0);
                frameInB = IndexedMatrix.CreateTranslation(5, 0, 0);

                Generic6DofConstraint pGen6DOF = new Generic6DofConstraint(pBodyA, pBodyB, ref frameInA, ref frameInB, true);
                //		btGeneric6DofConstraint* pGen6DOF = new btGeneric6DofConstraint(*pBodyA, *pBodyB, frameInA, frameInB, false);
                IndexedVector3 linearLower = new IndexedVector3(-10, -2, -1);
                pGen6DOF.SetLinearLowerLimit(ref linearLower);
                IndexedVector3 linearUpper = new IndexedVector3(10, 2, 1);
                pGen6DOF.SetLinearUpperLimit(ref linearUpper);
                // ? why again?
                //linearLower = new IndexedVector3(-10,0,0);
                //pGen6DOF.setLinearLowerLimit(ref linearLower);
                //		pGen6DOF.setLinearUpperLimit(IndexedVector3(10., 0., 0.));
                //		pGen6DOF.setLinearLowerLimit(IndexedVector3(0., 0., 0.));
                //		pGen6DOF.setLinearUpperLimit(IndexedVector3(0., 0., 0.));

                //		pGen6DOF.getTranslationalLimitMotor().m_enableMotor[0] = true;
                //		pGen6DOF.getTranslationalLimitMotor().m_targetVelocity[0] = 5.0f;
                //		pGen6DOF.getTranslationalLimitMotor().m_maxMotorForce[0] = 0.1f;


                //		pGen6DOF.setAngularLowerLimit(IndexedVector3(0., SIMD_HALF_PI*0.9, 0.));
                //		pGen6DOF.setAngularUpperLimit(IndexedVector3(0., -SIMD_HALF_PI*0.9, 0.));
                //		pGen6DOF.setAngularLowerLimit(IndexedVector3(0., 0., -SIMD_HALF_PI));
                //		pGen6DOF.setAngularUpperLimit(IndexedVector3(0., 0., SIMD_HALF_PI));

                IndexedVector3 angularLower = new IndexedVector3(-MathUtil.SIMD_HALF_PI * 0.5f, -0.75f, -MathUtil.SIMD_HALF_PI * 0.8f);
                IndexedVector3 angularUpper = -angularLower;
                pGen6DOF.SetAngularLowerLimit(ref angularLower);
                pGen6DOF.SetAngularUpperLimit(ref angularUpper);
                //		pGen6DOF.setAngularLowerLimit(IndexedVector3(0.f, -0.75, SIMD_HALF_PI * 0.8f));
                //		pGen6DOF.setAngularUpperLimit(IndexedVector3(0.f, 0.75, -SIMD_HALF_PI * 0.8f));
                //		pGen6DOF.setAngularLowerLimit(IndexedVector3(0.f, -SIMD_HALF_PI * 0.8f, SIMD_HALF_PI * 1.98f));
                //		pGen6DOF.setAngularUpperLimit(IndexedVector3(0.f, SIMD_HALF_PI * 0.8f,  -SIMD_HALF_PI * 1.98f));



                //		pGen6DOF.setAngularLowerLimit(IndexedVector3(-0.75,-0.5, -0.5));
                //		pGen6DOF.setAngularUpperLimit(IndexedVector3(0.75,0.5, 0.5));
                //		pGen6DOF.setAngularLowerLimit(IndexedVector3(-0.75,0., 0.));
                //		pGen6DOF.setAngularUpperLimit(IndexedVector3(0.75,0., 0.));

                m_dynamicsWorld.AddConstraint(pGen6DOF, true);
                pGen6DOF.SetDbgDrawSize(5.0f);
            }
#endif
#if true
            { // create a ConeTwist constraint
                IndexedMatrix tr = IndexedMatrix.CreateTranslation(-10, 5, 0);

                RigidBody pBodyA = LocalCreateRigidBody(1.0f, ref tr, shape);
                pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION);

                tr = IndexedMatrix.CreateTranslation(-10, -5, 0);

                RigidBody pBodyB = LocalCreateRigidBody(0.0f, ref tr, shape);

                IndexedMatrix frameInA, frameInB;
                frameInA         = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI);
                frameInA._origin = new IndexedVector3(0, -5, 0);
                frameInB         = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI);
                frameInB._origin = new IndexedVector3(0, 5, 0);

                ConeTwistConstraint pCT = new ConeTwistConstraint(pBodyA, pBodyB, ref frameInA, ref frameInB);
                pCT.SetLimit(MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_PI * 0.8f, 1.0f, 0.3f, 1.0f);       // soft limit == hard limit
                m_dynamicsWorld.AddConstraint(pCT, true);
                pCT.SetDbgDrawSize(5.0f);
            }
#endif
#if true
            { // Hinge connected to the world, with motor (to hinge motor with new and old constraint solver)
                // WORKS OK
                IndexedMatrix tr    = IndexedMatrix.Identity;
                RigidBody     pBody = LocalCreateRigidBody(1.0f, ref tr, shape);
                pBody.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                IndexedVector3 btPivotA = new IndexedVector3(10.0f, 0.0f, 0.0f);
                IndexedVector3 btAxisA  = new IndexedVector3(0.0f, 0.0f, 1.0f);

                HingeConstraint pHinge = new HingeConstraint(pBody, ref btPivotA, ref btAxisA, false);
                //		pHinge.enableAngularMotor(true, -1.0, 0.165); // use for the old solver
                pHinge.EnableAngularMotor(true, -1.0f, 1.65f);         // use for the new SIMD solver
                m_dynamicsWorld.AddConstraint(pHinge);
                pHinge.SetDbgDrawSize(5.0f);
            }
#endif
#if true
            {
                // WORKS OK
                // create a universal joint using generic 6DOF constraint
                // create two rigid bodies
                // static bodyA (parent) on top:
                IndexedMatrix tr     = IndexedMatrix.CreateTranslation(20, 4, 0);
                RigidBody     pBodyA = LocalCreateRigidBody(0.0f, ref tr, shape);
                pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                // dynamic bodyB (child) below it :
                tr = IndexedMatrix.CreateTranslation(20, 0, 0);
                RigidBody pBodyB = LocalCreateRigidBody(1.0f, ref tr, shape);
                pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                // add some (arbitrary) data to build constraint frames
                IndexedVector3 parentAxis = new IndexedVector3(1.0f, 0.0f, 0.0f);
                IndexedVector3 childAxis  = new IndexedVector3(0.0f, 0.0f, 1.0f);
                IndexedVector3 anchor     = new IndexedVector3(20.0f, 2.0f, 0.0f);

                UniversalConstraint pUniv = new UniversalConstraint(pBodyA, pBodyB, ref anchor, ref parentAxis, ref childAxis);
                pUniv.SetLowerLimit(-MathUtil.SIMD_HALF_PI * 0.5f, -MathUtil.SIMD_HALF_PI * 0.5f);
                pUniv.SetUpperLimit(MathUtil.SIMD_HALF_PI * 0.5f, MathUtil.SIMD_HALF_PI * 0.5f);
                // add constraint to world
                m_dynamicsWorld.AddConstraint(pUniv, true);
                // draw constraint frames and limits for debugging
                pUniv.SetDbgDrawSize(5.0f);
            }
#endif

#if true
            // WORKS OK
            { // create a generic 6DOF constraint with springs
                IndexedMatrix tr = IndexedMatrix.CreateTranslation(-20f, 16f, 0f);
                //tr.setIdentity();
                //tr.setOrigin(btVector3(btScalar(-20.), btScalar(16.), btScalar(0.)));
                //tr.getBasis().setEulerZYX(0,0,0);
                RigidBody pBodyA = LocalCreateRigidBody(0.0f, ref tr, shape);
                pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION);

                //tr.setIdentity();
                //tr.setOrigin(btVector3(btScalar(-10.), btScalar(16.), btScalar(0.)));
                //tr.getBasis().setEulerZYX(0,0,0);
                tr = IndexedMatrix.CreateTranslation(-10, 16, 0);
                RigidBody pBodyB = LocalCreateRigidBody(1.0f, ref tr, shape);
                pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION);

                IndexedMatrix frameInA = IndexedMatrix.CreateTranslation(10f, 0f, 0f);
                IndexedMatrix frameInB = IndexedMatrix.CreateTranslation(0f, 0f, 0f);

                Generic6DofSpringConstraint pGen6DOFSpring = new Generic6DofSpringConstraint(pBodyA, pBodyB, ref frameInA, ref frameInB, true);
                pGen6DOFSpring.SetLinearUpperLimit(new IndexedVector3(5f, 0f, 0f));
                pGen6DOFSpring.SetLinearLowerLimit(new IndexedVector3(-5f, 0f, 0f));

                pGen6DOFSpring.SetAngularLowerLimit(new IndexedVector3(0f, 0f, -1.5f));
                pGen6DOFSpring.SetAngularUpperLimit(new IndexedVector3(0f, 0f, 1.5f));

                m_dynamicsWorld.AddConstraint(pGen6DOFSpring, true);
                pGen6DOFSpring.SetDbgDrawSize(5.0f);

                pGen6DOFSpring.EnableSpring(0, true);
                pGen6DOFSpring.SetStiffness(0, 39.478f);
                pGen6DOFSpring.SetDamping(0, 0.5f);
                pGen6DOFSpring.EnableSpring(5, true);
                pGen6DOFSpring.SetStiffness(5, 39.478f);
                pGen6DOFSpring.SetDamping(0, 0.3f);
                pGen6DOFSpring.SetEquilibriumPoint();
            }
#endif
#if true
            {
                // WORKS OK
                // create a Hinge2 joint
                // create two rigid bodies
                // static bodyA (parent) on top:
                IndexedMatrix tr = IndexedMatrix.CreateTranslation(-20f, 4f, 0f);

                RigidBody pBodyA = LocalCreateRigidBody(0.0f, ref tr, shape);
                pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                // dynamic bodyB (child) below it :
                tr = IndexedMatrix.CreateTranslation(-20f, 0f, 0f);
                RigidBody pBodyB = LocalCreateRigidBody(1.0f, ref tr, shape);
                pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                // add some data to build constraint frames
                IndexedVector3   parentAxis = new IndexedVector3(0.0f, 1.0f, 0.0f);
                IndexedVector3   childAxis  = new IndexedVector3(1.0f, 0.0f, 0.0f);
                IndexedVector3   anchor     = new IndexedVector3(-20.0f, 0.0f, 0.0f);
                Hinge2Constraint pHinge2    = new Hinge2Constraint(pBodyA, pBodyB, ref anchor, ref parentAxis, ref childAxis);
                pHinge2.SetLowerLimit(-MathUtil.SIMD_HALF_PI * 0.5f);
                pHinge2.SetUpperLimit(MathUtil.SIMD_HALF_PI * 0.5f);
                // add constraint to world
                m_dynamicsWorld.AddConstraint(pHinge2, true);
                // draw constraint frames and limits for debugging
                pHinge2.SetDbgDrawSize(5.0f);
            }
#endif
#if true
            {
                // WORKS OK
                // create a Hinge joint between two dynamic bodies
                // create two rigid bodies
                // static bodyA (parent) on top:
                IndexedMatrix tr     = IndexedMatrix.CreateTranslation(-20f, -2f, 0f);
                RigidBody     pBodyA = LocalCreateRigidBody(1.0f, ref tr, shape);
                pBodyA.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                // dynamic bodyB:
                tr = IndexedMatrix.CreateTranslation(-30f, -2f, 0f);
                RigidBody pBodyB = LocalCreateRigidBody(10.0f, ref tr, shape);
                pBodyB.SetActivationState(ActivationState.DISABLE_DEACTIVATION);
                // add some data to build constraint frames
                IndexedVector3 axisA  = new IndexedVector3(0.0f, 1.0f, 0.0f);
                IndexedVector3 axisB  = new IndexedVector3(0.0f, 1.0f, 0.0f);
                IndexedVector3 pivotA = new IndexedVector3(-5.0f, 0.0f, 0.0f);
                IndexedVector3 pivotB = new IndexedVector3(5.0f, 0.0f, 0.0f);

                spHingeDynAB = new HingeConstraint(pBodyA, pBodyB, ref pivotA, ref pivotB, ref axisA, ref axisB);
                spHingeDynAB.SetLimit(-MathUtil.SIMD_HALF_PI * 0.5f, MathUtil.SIMD_HALF_PI * 0.5f);
                // add constraint to world
                m_dynamicsWorld.AddConstraint(spHingeDynAB, true);
                // draw constraint frames and limits for debugging
                spHingeDynAB.SetDbgDrawSize(5.0f);
            }
#endif
        }