public bool m_needcleanup; // Need to run cleanup? public DbvtBroadphase(IOverlappingPairCache paircache) { for (int i = 0; i < m_sets.Length; i++) m_sets[i] = new Dbvt(); m_deferedcollide = false; m_needcleanup = true; m_releasepaircache = (paircache != null) ? false : true; m_prediction = 0; m_stageCurrent = 0; m_fixedleft = 0; m_fupdates = 1; m_dupdates = 0; m_cupdates = 10; m_newpairs = 1; m_updates_call = 0; m_updates_done = 0; m_updates_ratio = 0; m_paircache = (paircache != null) ? paircache : new HashedOverlappingPairCache(); m_gid = 0; m_pid = 0; m_cid = 0; for (int i = 0; i <= STAGECOUNT; ++i) { m_stageRoots[i] = null; } #if DBVT_BP_PROFILE clear(m_profiling); #endif }
public DbvtBroadphase(IOverlappingPairCache paircache) { m_sets[0] = new Dbvt(); m_sets[1] = new Dbvt(); m_deferedcollide = false; m_needcleanup = true; m_releasepaircache = (paircache != null) ? false : true; m_prediction = 0; m_stageCurrent = 0; m_fixedleft = 0; m_fupdates = 1; m_dupdates = 0; m_cupdates = 10; m_newpairs = 1; m_updates_call = 0; m_updates_done = 0; m_updates_ratio = 0; m_paircache = paircache != null ? paircache : new HashedOverlappingPairCache(); m_gid = 0; m_pid = 0; m_cid = 0; #if DBVT_BP_PROFILE m_profiling = new ProfileBlock(); m_profiling.clear(); #endif }
public ClosestNotMeConvexResultCallback(CollisionObject me, ref Vector3 fromA, ref Vector3 toA, IOverlappingPairCache pairCache, IDispatcher dispatcher) : base(ref fromA, ref toA) { m_allowedPenetration = 0.0f; m_me = me; m_pairCache = pairCache; m_dispatcher = dispatcher; }
public MultiSapBroadphase(int maxProxies,IOverlappingPairCache pairCache) { m_overlappingPairs = pairCache; m_optimizedAabbTree = null; m_ownsPairCache = false; m_invalidPair = 0; if (m_overlappingPairs == null) { m_ownsPairCache = true; m_overlappingPairs = new SortedOverlappingPairCache(); } m_filterCallback = new MultiSapOverlapFilterCallback(); m_overlappingPairs.SetOverlapFilterCallback(m_filterCallback); // mem = btAlignedAlloc(sizeof(btSimpleBroadphase),16); // m_simpleBroadphase = new (mem) btSimpleBroadphase(maxProxies,m_overlappingPairs); }
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 override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(SCALING * 50f); //string filename = @"e:\users\man\bullet\xna-largemesh-output.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(IndexedVector3.Up, 50); CollisionShape groundShape = BuildLargeMesh(); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, 0, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); //IndexedMatrix rotateMatrix = IndexedMatrix.CreateFromYawPitchRoll(0, MathUtil.SIMD_PI / 2.0f, 0); //IndexedMatrix rotateMatrix = IndexedMatrix.Identity; IndexedMatrix rotateMatrix = IndexedMatrix.Identity; rotateMatrix._basis.SetEulerZYX(0, 0, MathUtil.SIMD_PI * 0.7f); rotateMatrix._origin = IndexedVector3.Zero; float mass = 0f; LocalCreateRigidBody(mass, ref rotateMatrix, groundShape); CollisionShape boxShape = new BoxShape(new IndexedVector3(0.2f, 0.2f, 0.2f)); //CollisionShape boxShape = new SphereShape(0.2f); //CollisionShape boxShape = new CylinderShapeX(new IndexedVector3(0.2f, 0.4f, 0.2f)); //CollisionShape boxShape = new CapsuleShape(0.2f, 0.4f); IndexedMatrix boxTransform = IndexedMatrix.Identity; boxTransform._basis.SetEulerZYX(MathUtil.SIMD_PI * 0.2f, MathUtil.SIMD_PI * 0.4f, MathUtil.SIMD_PI * 0.7f); boxTransform._origin = new IndexedVector3(0.0f, 5.0f, 0.0f); LocalCreateRigidBody(1.25f, boxTransform, boxShape); ClientResetScene(); }
public AxisSweep3(btVector3 worldAabbMin, btVector3 worldAabbMax, ushort maxHandles, IOverlappingPairCache pairCache, bool disableRaycastAccelerator) { Debug.Assert(maxHandles > 1 && maxHandles < 32767); Constructor(worldAabbMin, worldAabbMax, 0xfffe, 0xffff, maxHandles, pairCache, disableRaycastAccelerator); }
public CleanPairCallback(BroadphaseProxy cleanProxy, IOverlappingPairCache pairCache, IDispatcher dispatcher) { m_cleanProxy = cleanProxy; m_pairCache = pairCache; m_dispatcher = dispatcher; }
public AxisSweep3(btVector3 worldAabbMin, btVector3 worldAabbMax, ushort maxHandles, IOverlappingPairCache pairCache) { Debug.Assert(maxHandles > 1 && maxHandles < 32767); Constructor(worldAabbMin, worldAabbMax, 0xfffe, 0xffff, maxHandles, pairCache, false); }
public ClosestNotMeConvexResultCallback(CollisionObject me, Vector3 fromA, Vector3 toA, IOverlappingPairCache pairCache, IDispatcher dispatcher) : this(me, ref fromA, ref toA, pairCache, dispatcher) { }
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(); }
public void Constructor(btVector3 worldAabbMin, btVector3 worldAabbMax, UInt16 handleMask, UInt16 handleSentinel, UInt16 userMaxHandles, IOverlappingPairCache pairCache, bool disableRaycastAccelerator) { m_bpHandleMask = handleMask; m_handleSentinel = handleSentinel; m_pairCache = pairCache; m_userPairCallback = null; //m_ownsPairCache=false; m_invalidPair = 0; m_raycastAccelerator = null; UInt16 maxHandles = (ushort)(userMaxHandles + 1);//need to add one sentinel handle if (m_pairCache == null) { m_pairCache = new HashedOverlappingPairCache(); //m_ownsPairCache = true; } if (!disableRaycastAccelerator) { m_nullPairCache = new NullPairCache(); m_raycastAccelerator = new DbvtBroadphase(m_nullPairCache);//m_pairCache); m_raycastAccelerator.m_deferedcollide = true;//don't add/remove pairs } // init bounds m_worldAabbMin = worldAabbMin; m_worldAabbMax = worldAabbMax; btVector3 aabbSize = m_worldAabbMax - m_worldAabbMin; UInt16 maxInt = m_handleSentinel; m_quantize = new btVector3(maxInt, maxInt, maxInt) / aabbSize; // allocate handles buffer, using btAlignedAlloc, and put all handles on free list m_pHandles = new Handle[maxHandles]; for (int i = 0; i < maxHandles; i++) m_pHandles[i] = new Handle(); //m_maxHandles = maxHandles; m_numHandles = 0; // handle 0 is reserved as the null index, and is also used as the sentinel m_firstFreeHandle = 1; { for (UInt16 i = m_firstFreeHandle; i < m_pHandles.Length; i++) m_pHandles[i].SetNextFree((ushort)(i + 1)); m_pHandles[m_pHandles.Length - 1].SetNextFree(0); } { // allocate edge buffers for (int i = 0; i < 3; i++) { m_pEdges[i] = new Edge[maxHandles * 2]; } } //removed overlap management // make boundary sentinels m_pHandles[0].m_clientObject = null; for (int axis = 0; axis < 3; axis++) { m_pHandles[0].m_minEdges[axis] = 0; m_pHandles[0].m_maxEdges[axis] = 1; m_pEdges[axis][0].m_pos = 0; m_pEdges[axis][0].m_handle = 0; m_pEdges[axis][1].m_pos = m_handleSentinel; m_pEdges[axis][1].m_handle = 0; #if DEBUG_BROADPHASE debugPrintAxis(axis); #endif //DEBUG_BROADPHASE } }
public virtual void DispatchAllCollisionPairs(IOverlappingPairCache pairCache, DispatcherInfo dispatchInfo, IDispatcher dispatcher) { m_collisionCallback.Initialize(dispatchInfo, this); pairCache.ProcessAllOverlappingPairs(m_collisionCallback, dispatcher); m_collisionCallback.cleanup(); }
//public AxisSweep3Internal(ref Vector3 worldAabbMin,ref Vector3 worldAabbMax, int handleMask, int handleSentinel, int maxHandles = 16384, OverlappingPairCache* pairCache=0,bool disableRaycastAccelerator = false); public AxisSweep3Internal(ref Vector3 worldAabbMin, ref Vector3 worldAabbMax, int handleMask, ushort handleSentinel, ushort userMaxHandles, IOverlappingPairCache pairCache, bool disableRaycastAccelerator) { m_bpHandleMask = (handleMask); m_handleSentinel = (handleSentinel); m_pairCache = (pairCache); m_userPairCallback = null; m_ownsPairCache = (false); m_invalidPair = 0; m_raycastAccelerator = null; ushort maxHandles = (ushort)(userMaxHandles+1);//need to add one sentinel handle if (m_pairCache == null) { m_pairCache = new HashedOverlappingPairCache(); m_ownsPairCache = true; } if (!disableRaycastAccelerator) { m_nullPairCache = new NullPairCache(); m_raycastAccelerator = new DbvtBroadphase(m_nullPairCache);//m_pairCache); m_raycastAccelerator.m_deferedcollide = true;//don't add/remove pairs } //btAssert(bounds.HasVolume()); // init bounds m_worldAabbMin = worldAabbMin; m_worldAabbMax = worldAabbMax; Vector3 aabbSize = m_worldAabbMax - m_worldAabbMin; int maxInt = m_handleSentinel; m_quantize = new Vector3((float)maxInt,(float)maxInt,(float)maxInt) / aabbSize; // allocate handles buffer, using btAlignedAlloc, and put all handles on free list m_pHandles = new Handle[maxHandles]; for (int i = 0; i < m_pHandles.Length; ++i) { m_pHandles[i] = new Handle(); } m_maxHandles = maxHandles; m_numHandles = 0; // handle 0 is reserved as the null index, and is also used as the sentinel m_firstFreeHandle = 1; { for (ushort i = m_firstFreeHandle; i < maxHandles; i++) { ushort nextFree = (ushort)(i + (ushort)1); m_pHandles[i].SetNextFree(nextFree); } m_pHandles[maxHandles - 1].SetNextFree(0); } { m_pEdges = new Edge[3, (maxHandles * 2)]; // allocate edge buffers for (int i = 0; i < 3; i++) { for (int j = 0; j < maxHandles * 2; ++j) { m_pEdges[i,j] = new Edge(); } } } //removed overlap management // make boundary sentinels m_pHandles[0].SetClientObject(null); for (int axis = 0; axis < 3; axis++) { m_pHandles[0].m_minEdges[axis] = 0; m_pHandles[0].m_maxEdges[axis] = 1; m_pEdges[axis,0].m_pos = 0; m_pEdges[axis,0].m_handle = 0; m_pEdges[axis,1].m_pos = m_handleSentinel; m_pEdges[axis,1].m_handle = 0; #if DEBUG_BROADPHASE debugPrintAxis(axis); #endif //DEBUG_BROADPHASE } }
//public AxisSweep3Internal(ref IndexedVector3 worldAabbMin,ref IndexedVector3 worldAabbMax, int handleMask, int handleSentinel, int maxHandles = 16384, OverlappingPairCache* pairCache=0,bool disableRaycastAccelerator = false); public AxisSweep3Internal(ref IndexedVector3 worldAabbMin, ref IndexedVector3 worldAabbMax, int handleMask, ushort handleSentinel, ushort userMaxHandles, IOverlappingPairCache pairCache, bool disableRaycastAccelerator) { m_bpHandleMask = (handleMask); m_handleSentinel = (handleSentinel); m_pairCache = (pairCache); m_userPairCallback = null; m_ownsPairCache = (false); m_invalidPair = 0; m_raycastAccelerator = null; ushort maxHandles = (ushort)(userMaxHandles + 1);//need to add one sentinel handle if (m_pairCache == null) { m_pairCache = new HashedOverlappingPairCache(); m_ownsPairCache = true; } if (!disableRaycastAccelerator) { m_nullPairCache = new NullPairCache(); m_raycastAccelerator = new DbvtBroadphase(m_nullPairCache); //m_pairCache); m_raycastAccelerator.m_deferedcollide = true; //don't add/remove pairs } //btAssert(bounds.HasVolume()); // init bounds m_worldAabbMin = worldAabbMin; m_worldAabbMax = worldAabbMax; IndexedVector3 aabbSize = m_worldAabbMax - m_worldAabbMin; int maxInt = m_handleSentinel; m_quantize = new IndexedVector3((float)maxInt) / aabbSize; // allocate handles buffer, using btAlignedAlloc, and put all handles on free list m_pHandles = new Handle[maxHandles]; for (int i = 0; i < m_pHandles.Length; ++i) { m_pHandles[i] = new Handle(); } m_maxHandles = maxHandles; m_numHandles = 0; // handle 0 is reserved as the null index, and is also used as the sentinel m_firstFreeHandle = 1; { for (ushort i = m_firstFreeHandle; i < maxHandles; i++) { ushort nextFree = (ushort)(i + (ushort)1); m_pHandles[i].SetNextFree(nextFree); } m_pHandles[maxHandles - 1].SetNextFree(0); } { m_pEdges = new Edge[3, (maxHandles * 2)]; // allocate edge buffers for (int i = 0; i < 3; i++) { for (int j = 0; j < maxHandles * 2; ++j) { m_pEdges[i, j] = new Edge(); } } } //removed overlap management // make boundary sentinels m_pHandles[0].SetClientObject(null); for (int axis = 0; axis < 3; axis++) { m_pHandles[0].m_minEdges[axis] = 0; m_pHandles[0].m_maxEdges[axis] = 1; m_pEdges[axis, 0].m_pos = 0; m_pEdges[axis, 0].m_handle = 0; m_pEdges[axis, 1].m_pos = m_handleSentinel; m_pEdges[axis, 1].m_handle = 0; #if DEBUG_BROADPHASE debugPrintAxis(axis); #endif //DEBUG_BROADPHASE } }
public override void InitializeDemo() { SetCameraDistance(30f); //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, -50, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); float mass = 0f; LocalCreateRigidBody(mass, ref groundTransform, groundShape); { int numBlocksTall = 10; //18; //How many 'stories' tall. float blockWidth = 6f; //Total width/length of the tower. float blockHeight = 2f; //create a few dynamic rigidbodies IndexedVector3 extents = new IndexedVector3(blockWidth / 3, blockHeight, blockWidth); IndexedVector3 boxHalfExtents = extents * 0.5f; CollisionShape colShape = new BoxShape(boxHalfExtents); //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); } //The default number of iterations is 10, which works fine, but this demo //is all about stability (it's jenga!). Increase the iterations a bit. //Even though it's using twice as many iterations, it will early-out //before reaching the limit MOST of the time. //It's still pretty playable at around 7-8 max iterations, though. IndexedMatrix transform = IndexedMatrix.Identity; for (int i = 0; i < numBlocksTall; i++) { if (i % 2 == 0) { for (int j = 0; j < 3; j++) { transform = IndexedMatrix.Identity; IndexedVector3 position = new IndexedVector3(j * (blockWidth / 3) - blockWidth / 3, blockHeight / 2 + i * (blockHeight), 0); //position += boxHalfExtents; transform._origin = position; RigidBody rb = LocalCreateRigidBody(mass, transform, colShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } else { transform = IndexedMatrix.CreateRotationY(MathUtil.SIMD_HALF_PI); for (int j = 0; j < 3; j++) { IndexedVector3 position = new IndexedVector3(0, blockHeight / 2 + (i) * (blockHeight), j * (blockWidth / 3) - blockWidth / 3f); transform._origin = position; //position += boxHalfExtents; transform._origin = position; RigidBody rb = LocalCreateRigidBody(mass, transform, colShape); rb.SetActivationState(ActivationState.ISLAND_SLEEPING); } } } //game.Camera.Position = new Vector3(0, 5, 15); } ClientResetScene(); }
public void Constructor(BroadphaseProxy cleanProxy, IOverlappingPairCache pairCache, IDispatcher dispatcher) { m_cleanProxy = cleanProxy; m_pairCache = pairCache; m_dispatcher = dispatcher; }
public virtual void Cleanup() { if (m_raycastAccelerator != null) { m_nullPairCache.Cleanup(); m_nullPairCache = null; m_raycastAccelerator.Cleanup(); m_raycastAccelerator = null; } for (int i = 0; i < m_pHandles.Length; ++i) { m_pHandles[i].Cleanup(); } m_pHandles = null; if (m_ownsPairCache) { m_pairCache = null; } }
} // for pool public ClosestNotMeConvexResultCallback(CollisionObject me, IndexedVector3 fromA, IndexedVector3 toA, IOverlappingPairCache pairCache, IDispatcher dispatcher) : this(me, ref fromA, ref toA, pairCache, dispatcher) { }
public virtual void Initialize(CollisionObject me, IndexedVector3 fromA, IndexedVector3 toA, IOverlappingPairCache pairCache, IDispatcher dispatcher) { base.Initialize(ref fromA, ref toA); m_allowedPenetration = 0.0f; m_me = me; m_pairCache = pairCache; m_dispatcher = dispatcher; }
public ClosestNotMeConvexResultCallback(CollisionObject me, ref IndexedVector3 fromA, ref IndexedVector3 toA, IOverlappingPairCache pairCache, IDispatcher dispatcher) : base(ref fromA, ref toA) { m_allowedPenetration = 0.0f; m_me = me; m_pairCache = pairCache; m_dispatcher = dispatcher; }
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(); }
public virtual void dispatchAllCollisionPairs(IOverlappingPairCache pairCache, DispatcherInfo dispatchInfo, IDispatcher dispatcher) { collisionCallback.Constructor(dispatchInfo, this); pairCache.processAllOverlappingPairs(collisionCallback, dispatcher); }