예제 #1
0
        public SimpleBroadphase(int maxProxies, IOverlappingPairCache overlappingPairCache)
        {
            if (overlappingPairCache == null)
            {
                overlappingPairCache = new HashedOverlappingPairCache();
                m_ownsPairCache      = true;
            }
            m_pHandles        = new SimpleBroadphaseProxy[maxProxies];
            m_pairCache       = overlappingPairCache;
            m_maxHandles      = maxProxies;
            m_numHandles      = 0;
            m_firstFreeHandle = 0;
            m_LastHandleIndex = -1;

            for (int i = m_firstFreeHandle; i < maxProxies; i++)
            {
                m_pHandles[i] = new SimpleBroadphaseProxy(i);
                m_pHandles[i].SetNextFree(i + 1);
                m_pHandles[i].m_uniqueId = ++m_proxyCounter;; //any UID will do, we just avoid too trivial values (0,1) for debugging purposes
            }
            m_pHandles[maxProxies - 1].SetNextFree(0);
        }
        public SimpleBroadphase(int maxProxies, IOverlappingPairCache overlappingPairCache)
        {
            if (overlappingPairCache == null)
            {
                overlappingPairCache = new HashedOverlappingPairCache();
                m_ownsPairCache = true;
            }
            m_pHandles = new SimpleBroadphaseProxy[maxProxies];
            m_pairCache = overlappingPairCache;
            m_maxHandles = maxProxies;
            m_numHandles = 0;
            m_firstFreeHandle = 0;
            m_LastHandleIndex = -1;

            for (int i = m_firstFreeHandle; i < maxProxies; i++)
            {
                m_pHandles[i] = new SimpleBroadphaseProxy(i);
                m_pHandles[i].SetNextFree(i + 1);
                m_pHandles[i].m_uniqueId = ++m_proxyCounter; ;//any UID will do, we just avoid too trivial values (0,1) for debugging purposes
            }
            m_pHandles[maxProxies - 1].SetNextFree(0);

        }
 public PairCachingGhostObject()
 {
     m_hashPairCache = new HashedOverlappingPairCache();
 }
예제 #4
0
 public PairCachingGhostObject()
 {
     m_hashPairCache = new HashedOverlappingPairCache();
 }
예제 #5
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);


            //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(BulletXNA.LinearMath.DebugDrawModes.DBG_DrawAabb | BulletXNA.LinearMath.DebugDrawModes.DBG_DrawNormals | BulletXNA.LinearMath.DebugDrawModes.DBG_DrawContactPoints);
            m_dynamicsWorld.SetDebugDrawer(BulletGlobals.gDebugDraw);

            //ClientResetScene();
        }