void SpheresGridDemo::clientResetScene() { static bool bFirstCall = true; DemoApplication::clientResetScene(); if(m_demoType != DEMO_INTEGRATION) { setRandomZCoordinate((m_demoType == DEMO_OE_CAKE_3D) ? 1.f : 0.f); } else { #if(!USE_BULLET_BODIES) init_scene_directly(); #endif } if(bFirstCall) { bFirstCall = false; } else { #ifdef SPHERES_DEMO m_pWorldS->grabSimulationData(); #endif//#ifdef SPHERES_DEMO #ifdef INTEGRATION_DEMO m_pWorldI->grabSimulationData(); #endif } }
void ParticlesDemo::clientResetScene() { static bool bFirstCall = true; DemoApplication::clientResetScene(); init_scene_directly(); if(bFirstCall) { bFirstCall = false; } else { m_pWorld->grabSimulationData(); } }
void ParticlesDemo::initPhysics() { setTexturing(false); setShadows(false); // setCameraDistance(80.f); setCameraDistance(3.0f); // m_cameraTargetPosition.setValue(50, 10, 0); m_cameraTargetPosition.setValue(0, 0, 0); // m_azi = btScalar(0.f); // m_ele = btScalar(0.f); m_azi = btScalar(45.f); m_ele = btScalar(30.f); setFrustumZPlanes(0.1f, 10.f); ///collision configuration contains default setup for memory, collision setup btDefaultCollisionConstructionInfo dci; dci.m_defaultMaxPersistentManifoldPoolSize=50000; dci.m_defaultMaxCollisionAlgorithmPoolSize=50000; 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); m_pairCache = new (btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16))btHashedOverlappingPairCache(); // m_broadphase = new btDbvtBroadphase(m_pairCache); m_broadphase = new btNullBroadphase(); ///the default constraint solver m_solver = new btSequentialImpulseConstraintSolver(); m_pWorld = new btParticlesDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration, 65536); m_dialogDynamicsWorld = new GL_DialogDynamicsWorld(); GL_DialogWindow* settings = m_dialogDynamicsWorld->createDialog(50,0,280,280,"CPU fallback"); m_pWorld->m_useCpuControls[0] = 0; GL_ToggleControl* ctrl = 0; m_pWorld->m_useCpuControls[SIMSTAGE_INTEGRATE_MOTION] = m_dialogDynamicsWorld->createToggle(settings,"Integrate Motion"); m_pWorld->m_useCpuControls[SIMSTAGE_COMPUTE_CELL_ID] = m_dialogDynamicsWorld->createToggle(settings,"Compute Cell ID"); m_pWorld->m_useCpuControls[SIMSTAGE_SORT_CELL_ID] = m_dialogDynamicsWorld->createToggle(settings,"Sort Cell ID"); m_pWorld->m_useCpuControls[SIMSTAGE_FIND_CELL_START] = m_dialogDynamicsWorld->createToggle(settings,"Find Cell Start"); m_pWorld->m_useCpuControls[SIMSTAGE_COLLIDE_PARTICLES] = m_dialogDynamicsWorld->createToggle(settings,"Collide Particles"); for(int i = 1; i < SIMSTAGE_TOTAL; i++) { m_pWorld->m_useCpuControls[i]->m_active = false; } #if defined(CL_PLATFORM_MINI_CL) // these kernels use barrier() m_pWorld->m_useCpuControls[SIMSTAGE_SORT_CELL_ID]->m_active = true; m_pWorld->m_useCpuControls[SIMSTAGE_FIND_CELL_START]->m_active = true; #endif #if defined(CL_PLATFORM_AMD) // these kernels use barrier() m_pWorld->m_useCpuControls[SIMSTAGE_SORT_CELL_ID]->m_active = true; m_pWorld->m_useCpuControls[SIMSTAGE_FIND_CELL_START]->m_active = true; #endif m_dynamicsWorld = m_pWorld; m_pWorld->getSimulationIslandManager()->setSplitIslands(true); m_pWorld->setGravity(btVector3(0,-10.,0)); m_pWorld->getSolverInfo().m_numIterations = 4; { // btCollisionShape* colShape = new btSphereShape(btScalar(1.0f)); /* btCollisionShape* colShape = new btSphereShape(DEF_PARTICLE_RADIUS); m_collisionShapes.push_back(colShape); btTransform startTransform; startTransform.setIdentity(); btScalar mass(1.f); btVector3 localInertia(0,0,0); colShape->calculateLocalInertia(mass,localInertia); float start_x = START_POS_X - ARRAY_SIZE_X * DIST * btScalar(0.5f); float start_y = START_POS_Y - ARRAY_SIZE_Y * DIST * btScalar(0.5f); float start_z = START_POS_Z - ARRAY_SIZE_Z * DIST * btScalar(0.5f); startTransform.setOrigin(btVector3(start_x, start_y, start_z)); btRigidBodyConstructionInfo rbInfo(mass,0,colShape,localInertia); rbInfo.m_startWorldTransform = startTransform; btRigidBody* body = new btRigidBody(rbInfo); m_pWorld->addRigidBody(body); */ init_scene_directly(); } clientResetScene(); m_pWorld->initDeviceData(); }
void SpheresGridDemo::initPhysics() { setTexturing(false); setShadows(false); setCameraDistance(80.); m_cameraTargetPosition.setValue(50, 10, 0); m_azi = btScalar(0.f); m_ele = btScalar(0.f); ///collision configuration contains default setup for memory, collision setup btDefaultCollisionConstructionInfo dci; dci.m_defaultMaxPersistentManifoldPoolSize=50000; dci.m_defaultMaxCollisionAlgorithmPoolSize=50000; 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); m_pairCache = new (btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16))btHashedOverlappingPairCache(); // m_broadphase = new btDbvtBroadphase(m_pairCache); m_broadphase = new btNullBroadphase(); ///the default constraint solver m_solver = new btSequentialImpulseConstraintSolver(); #ifdef INTEGRATION_DEMO m_pWorldI = new btIntegrationDemoDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration, 65536); #endif #ifdef SPHERES_DEMO m_pWorldS = new btSpheresGridDemoDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration, 65536); #endif #ifdef SPHERES_DEMO m_dialogDynamicsWorld = new GL_DialogDynamicsWorld(); GL_DialogWindow* settings = m_dialogDynamicsWorld->createDialog(50,0,280,280,"CPU fallback"); m_pWorldS->m_useCpuControls[0] = 0; GL_ToggleControl* ctrl = 0; m_pWorldS->m_useCpuControls[SIMSTAGE_APPLY_GRAVITY] = m_dialogDynamicsWorld->createToggle(settings,"Apply Gravity"); m_pWorldS->m_useCpuControls[SIMSTAGE_COMPUTE_CELL_ID] = m_dialogDynamicsWorld->createToggle(settings,"Compute Cell ID"); m_pWorldS->m_useCpuControls[SIMSTAGE_SORT_CELL_ID] = m_dialogDynamicsWorld->createToggle(settings,"Sort Cell ID"); m_pWorldS->m_useCpuControls[SIMSTAGE_FIND_CELL_START] = m_dialogDynamicsWorld->createToggle(settings,"Find Cell Start"); m_pWorldS->m_useCpuControls[SIMSTAGE_FIND_PAIRS] = m_dialogDynamicsWorld->createToggle(settings,"Find Pairs"); m_pWorldS->m_useCpuControls[SIMSTAGE_SCAN_PAIRS] = m_dialogDynamicsWorld->createToggle(settings,"Scan Pairs"); m_pWorldS->m_useCpuControls[SIMSTAGE_COMPACT_PAIRS] = m_dialogDynamicsWorld->createToggle(settings,"Compact Pairs"); m_pWorldS->m_useCpuControls[SIMSTAGE_COMPUTE_BATCHES] = m_dialogDynamicsWorld->createToggle(settings,"Compute Batches"); m_pWorldS->m_useCpuControls[SIMSTAGE_COMPUTE_CONTACTS] = m_dialogDynamicsWorld->createToggle(settings,"Compute Contacts"); m_pWorldS->m_useCpuControls[SIMSTAGE_SOLVE_CONSTRAINTS] = m_dialogDynamicsWorld->createToggle(settings,"Solve Constraints"); m_pWorldS->m_useCpuControls[SIMSTAGE_INTEGRATE_TRANSFORMS] = m_dialogDynamicsWorld->createToggle(settings,"Integrate Transforms"); m_pWorldS->m_useCpuControls[SIMSTAGE_KERNEL_COLLIDE_SPHERE_WALLS] = m_dialogDynamicsWorld->createToggle(settings,"Collide Sphere Walls"); for(int i = 1; i < SIMSTAGE_TOTAL; i++) { m_pWorldS->m_useCpuControls[i]->m_active = false; } #if defined(CL_PLATFORM_MINI_CL) m_pWorldS->m_useCpuControls[SIMSTAGE_SCAN_PAIRS]->m_active = true; m_pWorldS->m_useCpuControls[SIMSTAGE_SORT_CELL_ID]->m_active = true; m_pWorldS->m_useCpuControls[SIMSTAGE_COMPUTE_CONTACTS]->m_active = true; #endif #if defined(CL_PLATFORM_AMD) m_pWorldS->m_useCpuControls[SIMSTAGE_SORT_CELL_ID]->m_active = true; // sloooow, incorrect, crashes application m_pWorldS->m_useCpuControls[SIMSTAGE_FIND_CELL_START]->m_active = true; // run-time error "Unimplemented" m_pWorldS->m_useCpuControls[SIMSTAGE_SCAN_PAIRS]->m_active = true; // works, but very slow (up to 100 times) m_pWorldS->m_useCpuControls[SIMSTAGE_COMPUTE_BATCHES]->m_active = true; // run-time error "Unimplemented" #endif #endif //#ifdef SPHERES_DEMO if(m_demoType == DEMO_INTEGRATION) { #ifdef INTEGRATION_DEMO m_dynamicsWorld = m_pWorldI; #endif } else { #ifdef SPHERES_DEMO m_dynamicsWorld = m_pWorldS; #endif //#ifdef SPHERES_DEMO } #ifdef INTEGRATION_DEMO m_pWorldI->getSimulationIslandManager()->setSplitIslands(true); m_pWorldI->setGravity(btVector3(0,-10.,0)); m_pWorldI->getSolverInfo().m_numIterations = 4; #endif //INTEGRATION_DEMO #ifdef SPHERES_DEMO m_pWorldS->getSimulationIslandManager()->setSplitIslands(true); m_pWorldS->setGravity(btVector3(0,-10.,0)); m_pWorldS->getSolverInfo().m_numIterations = 4; #endif //#ifdef SPHERES_DEMO { btCollisionShape* colShape = new btSphereShape(btScalar(1.0f)); m_collisionShapes.push_back(colShape); btTransform startTransform; startTransform.setIdentity(); btScalar mass(1.f); btVector3 localInertia(0,0,0); colShape->calculateLocalInertia(mass,localInertia); float start_x = START_POS_X - ARRAY_SIZE_X * DIST * btScalar(0.5f); float start_y = START_POS_Y - ARRAY_SIZE_Y * DIST * btScalar(0.5f); float start_z = START_POS_Z - ARRAY_SIZE_Z * DIST * btScalar(0.5f); #if USE_BULLET_BODIES // may be very slow for > 10K bodies printf("\nGenerating bodies ...\n"); int total = ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z; int done = 0; 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(btVector3( DIST*i + start_x, DIST*k + start_y, DIST*j + start_z)); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,0,colShape,localInertia); rbInfo.m_startWorldTransform = startTransform; btRigidBody* body = new btRigidBody(rbInfo); m_pWorldI->addRigidBody(body); done++; } } printf("%6d of %6d\r", done, total); fflush(stdout); } printf("\n... Done!\n"); #else // add just one sphere #ifdef INTEGRATION_DEMO startTransform.setOrigin(btVector3(start_x, start_y, start_z)); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,0,colShape,localInertia); rbInfo.m_startWorldTransform = startTransform; btRigidBody* body = new btRigidBody(rbInfo); m_pWorldI->addRigidBody(body); #endif // now fill m_hPos and m_hLinVel directly init_scene_directly(); #endif } btDynamicsWorld* tmpW = m_dynamicsWorld; #ifdef SPHERES_DEMO m_dynamicsWorld = m_pWorldS; SpheresGridDemoOecakeLoader loader(this); //loader.processFile("test1.oec"); #if 1 /// stress test btCompoundShape* compound = new btCompoundShape(); btSphereShape* sphere = new btSphereShape(1.f); btTransform localTrans; localTrans.setIdentity(); localTrans.setOrigin(btVector3(0,0,0)); compound->addChildShape(localTrans,sphere); //localTrans.setOrigin(btVector3(-1,0,0)); //compound->addChildShape(localTrans,sphere); btTransform trans; trans.setIdentity(); btVector3 offset(0.00001,0.00001,0.00001); for (int j=0;j<STRESS_X;j++) for (int i=0;i<STRESS_Y;i++) { trans.setOrigin(offset*i+btVector3(25+j*6,30+i*3,0.)); loader.createBodyForCompoundShape(compound,false,trans,1.); } #endif m_dynamicsWorld = tmpW; #else m_dynamicsWorld = m_pWorldI; #endif//#ifdef SPHERES_DEMO clientResetScene(); #ifdef INTEGRATION_DEMO m_pWorldI->initDeviceData(); #endif #ifdef SPHERES_DEMO m_pWorldS->initDeviceData(); #endif print_used_device(); }