virtual void createBodyForCompoundShape(btCompoundShape* compoundTmpShape,bool addConstraint, const btTransform& worldTransform, btScalar mass) { btDefaultMotionState* myMotionState= 0; btVector3 aabbMin,aabbMax; compoundTmpShape->getAabb(btTransform::getIdentity(),aabbMin,aabbMax); int numSpheres = compoundTmpShape->getNumChildShapes(); btAssert(numSpheres>0); if (numSpheres>8) { printf("error: exceeded 8 spheres\n"); return; } btVector3* positions = new btVector3[numSpheres]; btScalar* radii = new btScalar[numSpheres]; for (int i=0;i<numSpheres;i++) { btAssert(compoundTmpShape->getChildShape(i)->getShapeType()== SPHERE_SHAPE_PROXYTYPE); btSphereShape* sphereShape = (btSphereShape*)compoundTmpShape->getChildShape(i); radii[i]=sphereShape->getRadius(); positions[i] = compoundTmpShape->getChildTransform(i).getOrigin(); } btMultiSphereShape* multiSphere = new btMultiSphereShape(positions,radii,numSpheres); m_demo->addCollisionShape(multiSphere); btVector3 localInertia(0,0,0); if (mass) { myMotionState = new btDefaultMotionState(worldTransform); multiSphere->calculateLocalInertia(mass,localInertia); } //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btRigidBody* body = new btRigidBody(mass,myMotionState,multiSphere,localInertia); body->setLinearFactor(btVector3(1,1,0)); body->setAngularFactor(btVector3(0,0,1)); body->setWorldTransform(worldTransform); m_demo->getDynamicsWorld()->addRigidBody(body); if (addConstraint) { btVector3 pivotInA(0,0,0); btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body,pivotInA); m_demo->getDynamicsWorld()->addConstraint(p2p); } }
int main(int argc, char* argv[]) { #ifdef __APPLE__ MacOpenGLWindow* window = new MacOpenGLWindow(); #else Win32OpenGLWindow* window = new Win32OpenGLWindow(); #endif btgWindowConstructionInfo wci(g_OpenGLWidth,g_OpenGLHeight); wci.m_openglVersion = 2; window->createWindow(wci); window->setWindowTitle("MyTest"); #ifdef _WIN32 glewInit(); #endif window->startRendering(); float color[4] = {1,1,1,1}; // prim.drawRect(0,0,200,200,color); window->endRendering(); window->setKeyboardCallback(MyKeyboardCallback); { BasicDemo* demo = new BasicDemo; demo->myinit(); demo->initPhysics(); do { window->startRendering(); demo->clientMoveAndDisplay(); render.init(); render.renderPhysicsWorld(demo->getDynamicsWorld()); window->endRendering(); } while (!window->requestedExit()); demo->exitPhysics(); delete demo; } window->closeWindow(); delete window; return 0; }
int main(int argc,char** argv) { GLDebugDrawer gDebugDrawer; ///testing the btHashMap btHashMap<btHashKey<OurValue>,OurValue> map; OurValue value1(btVector3(2,3,4)); btHashKey<OurValue> key1(value1.getUid()); map.insert(key1,value1); OurValue value2(btVector3(5,6,7)); btHashKey<OurValue> key2(value2.getUid()); map.insert(key2,value2); { OurValue value3(btVector3(7,8,9)); btHashKey<OurValue> key3(value3.getUid()); map.insert(key3,value3); } map.remove(key2); const OurValue* ourPtr = map.find(key1); for (int i=0;i<map.size();i++) { OurValue* tmp = map.getAtIndex(i); //printf("tmp value=%f,%f,%f\n",tmp->m_position.getX(),tmp->m_position.getY(),tmp->m_position.getZ()); } BasicDemo ccdDemo; ccdDemo.initPhysics(); ccdDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer); #ifdef CHECK_MEMORY_LEAKS ccdDemo.exitPhysics(); #else return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bullet.sf.net",&ccdDemo); #endif //default glut doesn't return from mainloop return 0; }