b3ThreadSupportInterface* createUDPThreadSupport(int numThreads) { b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("UDPThread", UDPThreadFunc, UDPlsMemoryFunc, numThreads); b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); return threadSupport; }
btThreadSupportInterface* createSolverThreadSupport(int maxNumThreads) { #define SEQUENTIAL #ifdef SEQUENTIAL SequentialThreadSupport::SequentialThreadConstructionInfo tci("solverThreads",SolverThreadFunc,SolverlsMemoryFunc); SequentialThreadSupport* threadSupport = new SequentialThreadSupport(tci); threadSupport->startSPU(); #else #ifdef _WIN32 Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("solverThreads",SolverThreadFunc,SolverlsMemoryFunc,maxNumThreads); Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo); threadSupport->startSPU(); #elif defined (USE_PTHREADS) PosixThreadSupport::ThreadConstructionInfo solverConstructionInfo("solver", SolverThreadFunc, SolverlsMemoryFunc, maxNumThreads); PosixThreadSupport* threadSupport = new PosixThreadSupport(solverConstructionInfo); #else SequentialThreadSupport::SequentialThreadConstructionInfo tci("solverThreads",SolverThreadFunc,SolverlsMemoryFunc); SequentialThreadSupport* threadSupport = new SequentialThreadSupport(tci); threadSupport->startSPU(); #endif #endif return threadSupport; }
b3ThreadSupportInterface* createMotionThreadSupport(int numThreads) { b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("MotionThreads",MotionThreadFunc,MotionlsMemoryFunc,numThreads); b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); return threadSupport; }
b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) { b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",ExampleBrowserThreadFunc,ExampleBrowserMemoryFunc,numThreads); b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); return threadSupport; }
btThreadSupportInterface* createThreadSupport(int numThreads) { Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads); Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo); return threadSupport; }
//#define SEQUENTIAL btThreadSupportInterface* createSolverThreadSupport(int maxNumThreads) { #ifdef SEQUENTIAL SequentialThreadSupport::SequentialThreadConstructionInfo tci("solverThreads", SolverThreadFunc, SolverlsMemoryFunc); SequentialThreadSupport* threadSupport = new SequentialThreadSupport(tci); threadSupport->startSPU(); #else Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("solverThreads", SolverThreadFunc, SolverlsMemoryFunc, maxNumThreads); Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo); threadSupport->startSPU(); #endif return threadSupport; }
btThreadSupportInterface* jmePhysicsSpace::createDispatchThreadSupport(int maxNumThreads) { #ifdef _WIN32 Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("solverThreads", processCollisionTask, createCollisionLocalStoreMemory, maxNumThreads); Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo); threadSupport->startSPU(); #elif defined (USE_PTHREADS) PosixThreadSupport::ThreadConstructionInfo solverConstructionInfo("solver", processCollisionTask, createCollisionLocalStoreMemory, maxNumThreads); PosixThreadSupport* threadSupport = new PosixThreadSupport(solverConstructionInfo); threadSupport->startSPU(); #else SequentialThreadSupport::SequentialThreadConstructionInfo tci("solverThreads", processCollisionTask, createCollisionLocalStoreMemory); SequentialThreadSupport* threadSupport = new SequentialThreadSupport(tci); threadSupport->startSPU(); #endif return threadSupport; }
btThreadSupportInterface* jmePhysicsSpace::createSolverThreadSupport(int maxNumThreads) { #ifdef _WIN32 Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("solverThreads", SolverThreadFunc, SolverlsMemoryFunc, maxNumThreads); Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo); threadSupport->startSPU(); #elif defined (USE_PTHREADS) PosixThreadSupport::ThreadConstructionInfo constructionInfo("collision", SolverThreadFunc, SolverlsMemoryFunc, maxNumThreads); PosixThreadSupport* threadSupport = new PosixThreadSupport(constructionInfo); threadSupport->startSPU(); #else SequentialThreadSupport::SequentialThreadConstructionInfo tci("solverThreads", SolverThreadFunc, SolverlsMemoryFunc); SequentialThreadSupport* threadSupport = new SequentialThreadSupport(tci); threadSupport->startSPU(); #endif return threadSupport; }
void BasicDemo3D::initPhysics() { setTexturing(true); setShadows(false); // setCameraDistance(btScalar(SCALING*50.)); #if LARGE_DEMO setCameraDistance(btScalar(SCALING*50.)); #else setCameraDistance(btScalar(SCALING*20.)); #endif m_cameraTargetPosition.setValue(START_POS_X, -START_POS_Y-20, START_POS_Z); m_azi = btScalar(0.f); m_ele = btScalar(0.f); ///collision configuration contains default setup for memory, collision setup btDefaultCollisionConstructionInfo dci; dci.m_defaultMaxPersistentManifoldPoolSize=100000; dci.m_defaultMaxCollisionAlgorithmPoolSize=100000; dci.m_customCollisionAlgorithmMaxElementSize = sizeof(SpuContactManifoldCollisionAlgorithm); ///SpuContactManifoldCollisionAlgorithm is larger than any of the other collision algorithms //@@ dci.m_customMaxCollisionAlgorithmSize = sizeof(SpuContactManifoldCollisionAlgorithm); m_collisionConfiguration = new btDefaultCollisionConfiguration(dci); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) //m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); #ifndef WIN32 m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); #else unsigned int maxNumOutstandingTasks =4; //createCollisionLocalStoreMemory(); //processSolverTask Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("narrowphase_multi",processCollisionTask,createCollisionLocalStoreMemory,maxNumOutstandingTasks); class btThreadSupportInterface* threadInterface = new Win32ThreadSupport(threadConstructionInfo); m_dispatcher = new SpuGatheringCollisionDispatcher(threadInterface,maxNumOutstandingTasks,m_collisionConfiguration); #endif //SINGLE_THREADED_NARROWPHASE //## m_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,new btEmptyAlgorithm::CreateFunc); //## m_dispatcher->registerCollisionCreateFunc(CUSTOM_CONVEX_SHAPE_TYPE,CUSTOM_CONVEX_SHAPE_TYPE,new btBox2dBox2dCollisionAlgorithm::CreateFunc); // m_broadphase = new btDbvtBroadphase(); //## gPairCache = new (btAlignedAlloc(sizeof(btCudaDemoPairCache),16)) btCudaDemoPairCache(MAX_PROXIES, 24, MAX_SMALL_PROXIES); // gPairCache = NULL; gPairCache = new (btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache(); //m_broadphase = new btSimpleBroadphase(16384, gPairCache); /* btCudaBroadphase::btCudaBroadphase( btOverlappingPairCache* overlappingPairCache, const btVector3& worldAabbMin,const btVector3& worldAabbMax, int gridSizeX, int gridSizeY, int gridSizeZ, int maxSmallProxies, int maxLargeProxies, int maxPairsPerBody, int maxBodiesPerCell, btScalar cellFactorAABB) */ // btVector3 numOfCells = (gWorldMax - gWorldMin) / (2. * SCALING * 0.7); btVector3 numOfCells = (gWorldMax - gWorldMin) / (2. * SCALING); int numOfCellsX = (int)numOfCells[0]; int numOfCellsY = (int)numOfCells[1]; int numOfCellsZ = (int)numOfCells[2]; // m_broadphase = new bt3DGridBroadphase(gPairCache, gWorldMin, gWorldMax,numOfCellsX, numOfCellsY, numOfCellsZ,MAX_SMALL_PROXIES,10,8,8,1./1.5); //#define USE_CUDA_BROADPHASE 1 #ifdef USE_CUDA_BROADPHASE m_broadphase = new btCudaBroadphase(gPairCache, gWorldMin, gWorldMax,numOfCellsX, numOfCellsY, numOfCellsZ,MAX_SMALL_PROXIES,20,18,8,1./1.5); #else #if DBVT btDbvtBroadphase* dbvt = new btDbvtBroadphase(gPairCache); m_broadphase = dbvt; dbvt->m_deferedcollide=false; dbvt->m_prediction = 0.f; #else m_broadphase = new btAxisSweep3(gWorldMin,gWorldMax,32000,gPairCache,true);//(btDbvtBroadphase(gPairCache); #endif //DBVT #endif // create solvers for tests ///the default constraint solver sConstraintSolvers[0] = new btSequentialImpulseConstraintSolver(); /* sConstraintSolvers[1] = new btParallelBatchConstraintSolver(); sConstraintSolvers[2] = new btCudaConstraintSolver(); sConstraintSolvers[3] = new btParallelBatchConstraintSolver2(); sConstraintSolvers[4] = new btParallelBatchConstraintSolver3(); sConstraintSolvers[5] = new btCudaConstraintSolver3(); sConstraintSolvers[6] = new btParallelBatchConstraintSolver4(); sConstraintSolvers[7] = new btCudaConstraintSolver4(); sConstraintSolvers[8] = new btParallelBatchConstraintSolver5(); sConstraintSolvers[9] = new btParallelBatchConstraintSolver6(); sConstraintSolvers[10] = new btCudaConstraintSolver6(); */ sCurrSolverIndex = 0; m_solver = sConstraintSolvers[sCurrSolverIndex]; printf("\nUsing %s\n", sConstraintSolverNames[sCurrSolverIndex]); // sCudaMotionInterface = new btCudaMotionInterface(MAX_PROXIES); // m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration, sCudaMotionInterface); // m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); //## btCudaDemoDynamicsWorld* pDdw = new btCudaDemoDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); btCudaDemoDynamicsWorld3D* pDdw = new btCudaDemoDynamicsWorld3D(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); m_dynamicsWorld = pDdw; pDdw->getDispatchInfo().m_enableSPU=true; pDdw->getSimulationIslandManager()->setSplitIslands(sCurrSolverIndex == 0); pDdw->setObjRad(SCALING); pDdw->setWorldMin(gWorldMin); pDdw->setWorldMax(gWorldMax); #ifdef BT_USE_CUDA gUseCPUSolver = false; #else gUseCPUSolver = true; #endif pDdw->setUseCPUSolver(gUseCPUSolver); // pDdw->setUseSolver2(gUseSolver2); // m_dynamicsWorld->setGravity(btVector3(0,0,0)); m_dynamicsWorld->setGravity(btVector3(0.f,-10.f,0.f)); m_dynamicsWorld->getSolverInfo().m_numIterations = 4; { //create a few dynamic rigidbodies // Re-using the same collision is better for memory usage and performance //btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,0.1));//SCALING*1)); //## btCollisionShape* colShape = new btBox2dShape(btVector3(SCALING*.7,SCALING*.7,0.1));//SCALING*1)); btCollisionShape* colShape = new btBoxShape(btVector3(SCALING*.7,SCALING*.7, SCALING*.7)); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); m_collisionShapes.push_back(colShape); /// Create Dynamic Objects btTransform startTransform; startTransform.setIdentity(); btScalar mass(1.f); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) colShape->calculateLocalInertia(mass,localInertia); #if (!SPEC_TEST) float start_x = START_POS_X - ARRAY_SIZE_X * SCALING; float start_y = START_POS_Y - ARRAY_SIZE_Y * SCALING; float start_z = START_POS_Z - ARRAY_SIZE_Z * SCALING; 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.setOrigin(SCALING*btVector3( 2.0*SCALING*i + start_x, 2.0*SCALING*k + start_y, 2.0*SCALING*j + start_z)); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects //btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,0,colShape,localInertia); rbInfo.m_startWorldTransform=startTransform; btRigidBody* body = new btRigidBody(rbInfo); m_dynamicsWorld->addRigidBody(body); } } } #else // narrowphase test - 2 bodies at the same position float start_x = START_POS_X; float start_y = START_POS_Y; float start_z = START_POS_Z; // startTransform.setOrigin(SCALING*btVector3(start_x,start_y-14.f,start_z)); startTransform.setOrigin(SCALING*btVector3(start_x,start_y-11.f,start_z)); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,0,colShape,localInertia); rbInfo.m_startWorldTransform=startTransform; btRigidBody* body = new btRigidBody(rbInfo); m_dynamicsWorld->addRigidBody(body); // startTransform.setOrigin(SCALING*btVector3(start_x+1.2f,start_y+1.4f-14.f,start_z)); startTransform.setOrigin(SCALING*btVector3(start_x,start_y + 1.5f -11.f, start_z)); rbInfo.m_startWorldTransform=startTransform; body = new btRigidBody(rbInfo); m_dynamicsWorld->addRigidBody(body); #endif } #if 0 ///create a few basic rigid bodies // btCollisionShape* groundShape = new btBox2dShape(btVector3(btScalar(50.),btScalar(1.),btScalar(50.))); // btCollisionShape* groundShape = new btBox2dShape(btVector3(btScalar(228.),btScalar(1.),btScalar(228.))); // btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(228.),btScalar(1.),btScalar(228.))); // btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); // btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); btCollisionShape* groundShape = new btBoxShape(btVector3(POS_OFFS_X, btScalar(1.), POS_OFFS_Z)); m_collisionShapes.push_back(groundShape); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0, gWorldMin[1], 0)); // groundTransform.setOrigin(btVector3(0,-5,0)); // groundTransform.setOrigin(btVector3(0,-50,0)); //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here: { btScalar mass(0.); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) groundShape->calculateLocalInertia(mass,localInertia); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia); btRigidBody* body = new btRigidBody(rbInfo); //add the body to the dynamics world m_dynamicsWorld->addRigidBody(body); } #endif //clientResetScene(); }