I use btGImpactMeshShape. Collision "btGImpactMeshShape"-"ground" is normal (all position) but collision "btGImpactMeshShape"-"btCapsuleShape" is fail (some position).
fail_col.JPG
Create btGImpactMeshShape:
Code: Select all
const int c_vertex = 8;
const int c_tri = 12;
float vertex[c_vertex * 3] = {
-20, -50, 20,
-20, -50, -20,
20, -50, -20,
20, -50, 20,
-20, 50, 20,
-20, 50, -20,
20, 50, -20,
20, 50, 20};
int idx[c_tri * 3] = {
1, 5, 8,
1, 8, 4,
4, 8, 7,
4, 7, 3,
3, 7, 6,
3, 6, 2,
2, 6, 5,
2, 5, 1,
5, 6, 7,
5, 7, 8,
2, 1, 4,
2, 4, 3};
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(
c_tri, idx, 3 * sizeof(int),
c_vertex, vertex, 3 * sizeof(float));
btGImpactMeshShape* trimesh = new btGImpactMeshShape(indexVertexArrays);
trimesh->updateBound();
btScalar mass = 60.0;
btVector3 inertia(0.0, 0.0, 0.0);
trimesh->calculateLocalInertia(mass, inertia);
Vector3 entPos = ph_entities[2]->getParentSceneNode()->_getDerivedPosition();
Quaternion entRot = ph_entities[2]->getParentSceneNode()->_getDerivedOrientation();
btVector3 pos(entPos.x, entPos.y, entPos.z);
btQuaternion rot(entRot.x, entRot.y, entRot.z, entRot.w);
btTransform trans(rot, pos);
btTransform centerOfMass = btTransform::getIdentity();
btDefaultMotionState* mtState = new btDefaultMotionState(trans, centerOfMass);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, mtState, trimesh, inertia);
rbInfo.m_additionalDamping = true;
btRigidBody* body = new btRigidBody(rbInfo);
dynamicsWorld->addRigidBody(body);
Create btCapsuleShape:
Code: Select all
btCollisionShape* shape = new btCapsuleShape(10.0, 80.0);
btScalar mass = 10.0;
btVector3 inertia(0.0, 0.0, 0.0);
shape->calculateLocalInertia(mass, inertia);
Vector3 entPos = ph_entities[0]->getParentSceneNode()->_getDerivedPosition();
Quaternion entRot = ph_entities[0]->getParentSceneNode()->_getDerivedOrientation();
btVector3 pos(entPos.x, entPos.y, entPos.z);
btQuaternion rot(entRot.x, entRot.y, entRot.z, entRot.w);
btTransform trans(rot, pos);
btDefaultMotionState* mtState = new btDefaultMotionState(trans);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, mtState, shape, inertia);
rbInfo.m_additionalDamping = true;
btRigidBody* body = new btRigidBody(rbInfo);
body->setActivationState(DISABLE_DEACTIVATION);
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
//body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
body->setFriction(5.0);
body->setRestitution(0.5);
dynamicsWorld->addRigidBody(body);
Init physic:
Code: Select all
int maxProxies = 1024;
btVector3 worldAabbMin(-100000.0, -100000.0, -100000.0);
btVector3 worldAabbMax(100000.0, 100000.0, 100000.0);
btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies);
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
dispatcher->setNearCallback(MyNearCallback);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
btCollisionDispatcher* dispatcherGI = static_cast<btCollisionDispatcher*>(dynamicsWorld->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
dynamicsWorld->setGravity(btVector3(0, -9.8, 0));
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1),
btVector3(0, -1, 0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
groundRigidBody->setCollisionFlags(groundRigidBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
groundRigidBody->setFriction(5.0);
groundRigidBody->setRestitution(0.6);
dynamicsWorld->addRigidBody(groundRigidBody);
You do not have the required permissions to view the files attached to this post.