but I have some strange problems with shapes that are not spheres.
Here you can see the problem: https://www.youtube.com/watch?v=vmJkckITt6w
The problem is with the cube, it acts kinda strange (stands on a edge / ruberbands etc.)
Here is the function that creates the rigid body:
Code: Select all
int addConvexHullRigidDynamic(btCollisionShape* colShape)
{
int id = rigidBodies.size();
btTransform transf;
transf.setIdentity();
btMotionState* motionState = new btDefaultMotionState(transf);
btScalar mass = 10.0f;
btVector3 inertia(0, 0, 0);
colShape->calculateLocalInertia(mass, inertia);
btRigidBody::btRigidBodyConstructionInfo convexHullInfo = btRigidBody::btRigidBodyConstructionInfo(mass, motionState, colShape, inertia);
btRigidBody* rigidBody = new btRigidBody(convexHullInfo);
bltDynamicsWorld->addRigidBody(rigidBody);
rigidBodies.push_back(rigidBody);
return id;
}
The collision shape is created from a simpler convex hull shape that represents the triangle mesh that is rendered by OpenGL (I use blender to create the mesh for OpenGL
and then generate simpler convex hull shape from the mesh using a plugin in blender).
Here is a snippet how I create the shape for bullet in my app:
Code: Select all
btTriangleMesh* trimesh = new btTriangleMesh();
btVector3 triangleV1 = btVector3();
btVector3 triangleV2 = btVector3();
btVector3 triangleV3 = btVector3();
for (int i = 0; i < elements.size(); i++)
{
glmVec4TobtVec3(vertices[elements[i][0]], triangleV1);
glmVec4TobtVec3(vertices[elements[i][3]], triangleV2);
glmVec4TobtVec3(vertices[elements[i][6]], triangleV3);
trimesh->addTriangle(triangleV1, triangleV2, triangleV3);
}
btCollisionShape* collisionShape = 0;
collisionShape = new btConvexTriangleMeshShape(trimesh);