|
some information :
I init the bullet engine : // Build the broadphase int maxProxies=1024; btVector3 worldAabbMin(-2000,-2000,-1000); btVector3 worldAabbMax(2000,2000,1000); m_broadphase=new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);// Sweep and Prune Standard algo
// Set up the collision configuration and dispatcher m_collisionConfiguration=new btDefaultCollisionConfiguration(); m_dispatcher=new btCollisionDispatcher(m_collisionConfiguration); // btCollisionDispatcher : handle Convex-Concave and Convex-Convex Collision
// The actual physics solver m_solver=new btSequentialImpulseConstraintSolver;
// The Dynamic world. m_dynamicsWorld=new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); m_dynamicsWorld->setGravity(btVector3(0,-10,0)); // Ground m_groundShape=new btStaticPlaneShape(btVector3(0,1,0),1); btDefaultMotionState* groundMotionState=new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0))); // Mass : Zero (static), shape : Plane , Inertial Tensor : Null btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,m_groundShape,btVector3(0,0,0)); m_groundRigidBody=new btRigidBody(groundRigidBodyCI); dynamicsWorld()->addRigidBody(m_groundRigidBody);//,COL_GROUND,COL_SHAPE|COL_GROUND);
// Constraint to Z=0 plan m_zerobody=new btRigidBody(0,NULL,NULL); dynamicsWorld()->addRigidBody(m_zerobody); m_zerobody->setActivationState(DISABLE_DEACTIVATION);
//register algorithm btCollisionDispatcher * dispatcher=static_cast<btCollisionDispatcher*>(m_dynamicsWorld->getDispatcher()); btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
// Then each time I add a shape to my engine :
btTriangleMesh *triangleMesh=new btTriangleMesh(); int i; PointVert *tpoint1,*tpoint2,*tpoint3; for(i=0;i<vectlist.count();i+=3) { tpoint1=vectlist.value(i); tpoint2=vectlist.value(i+1); tpoint3=vectlist.value(i+2); triangleMesh->addTriangle(btVector3(tpoint1->val[0],tpoint1->val[1],tpoint1->val[2]),btVector3(tpoint2->val[0],tpoint2->val[1],tpoint2->val[2]),btVector3(tpoint3->val[0],tpoint3->val[1],tpoint3->val[2])); }
// Create Shape btConvexTriangleMeshShape* gimpact=new btConvexTriangleMeshShape(triangleMesh); btShapeHull* triHull=new btShapeHull(gimpact); btScalar margin=gimpact->getMargin(); triHull->buildHull(margin); btConvexHullShape* simplifiedShape=new btConvexHullShape(); for (i=0;i<triHull->numVertices();i++) { simplifiedShape->addPoint(triHull->getVertexPointer()[i]); } m_physicShape=simplifiedShape;
// DELETE UNUSED SHAPE !!!!!! TO ADD !!!!! delete gimpact; delete triHull;
// Set Motion State btMotionState* MotionState=new OgreMotionState(m_node); // Create Rigid Body btScalar mass=1000; btScalar restitution=1; btScalar friction=0; btVector3 localInertia(0,0,0); m_physicShape->calculateLocalInertia(mass,localInertia); // Mass : mass, shape : , Inertial Tensor : Null btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass,MotionState,m_physicShape,localInertia); m_rigidBody=new btRigidBody(rigidBodyCI); m_rigidBody->setRestitution(restitution); m_rigidBody->setFriction(friction); m_rigidBody->setActivationState(DISABLE_DEACTIVATION); layer()->dynamicsWorld()->addRigidBody(m_rigidBody);//,COL_SHAPE,COL_SHAPE|COL_GROUND);
// Constraint m_constrict=new btGeneric6DofConstraint(*m_rigidBody,*layer()->zeroBody(),btTransform::getIdentity(),btTransform::getIdentity(),false); // Use limit(axis, a, b) where a>b to disable limits on that axis m_constrict->setLinearLowerLimit(btVector3(-2000,-2000,0.00001)); m_constrict->setLinearUpperLimit(btVector3(2000,2000,0)); m_constrict->setAngularLowerLimit(btVector3(0.00001,0.00001,0.00001)); m_constrict->setAngularUpperLimit(btVector3(0,0,0)); layer()->dynamicsWorld()->addConstraint(m_constrict,true);
|