Hi,
im new with Bullet, and i have already made a series of primitive collision shapes collide in my project, like spheres and boxes, but now im trying to have random meshes to take part too, like for example, the bigbunny mesh as a rigid body to collide with rigid spheres. Is this possible with bullet?
Thanx.
Random mesh collision. [Solved]
-
- Posts: 5
- Joined: Tue Apr 12, 2011 3:23 am
Random mesh collision. [Solved]
Last edited by 88Alex88 on Mon May 30, 2011 6:49 pm, edited 1 time in total.
-
- Posts: 237
- Joined: Tue Jun 29, 2010 10:27 pm
Re: Random mesh collision.
Create a rigid body using btGImpactMeshShape, which takes in whatever triangle mesh data you want. You also need to make sure to register the gimpact algorithm (for proper mesh collision detection) by calling the following code after you create your world (or at least the dispatcher your world uses):
Code: Select all
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher)
-
- Posts: 5
- Joined: Tue Apr 12, 2011 3:23 am
Re: Random mesh collision.
Thanx for the fast reply, i have read about btGImpactMeshShape, and i guess i have to provide my mesh to it in the constructor, by giving a filled btStridingMeshInterface, but i dont really know how to do this. Can anyone help me with that? if I have my data into
Vector3* vertex;
unsigned long* indices;
How can i fill a btGImpactMeshShape with it?
Thanx
Vector3* vertex;
unsigned long* indices;
How can i fill a btGImpactMeshShape with it?
Thanx
-
- Posts: 77
- Joined: Thu Nov 26, 2009 6:32 pm
Re: Random mesh collision.
Just get the pointer to vertex indices and pointer to vertices and pass it to the following function. m_world is nothing but pointer to btDynamicsWorld.
Hope this helps.
Hope this helps.
Code: Select all
btRigidBody* addConcaveMesh(int numTriangles, int *indices, int numVertices, float *verts,
btVector3 &position, btVector3 &inertia, btScalar mass, btScalar restitution, bool collision)
{
// create trimesh
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(numTriangles,
indices,
3*sizeof(int),
numVertices, verts, 3*sizeof(float));
btGImpactMeshShape * trimesh = new btGImpactMeshShape(indexVertexArrays);
trimesh->setLocalScaling(btVector3(1.f,1.f,1.f));
trimesh->updateBound();
btCollisionShape *m_trimeshShape = trimesh;
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_world->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
/////
btTransform trans;
trans.setIdentity();
if (!mass)
trans.setRotation(btQuaternion(btVector3(1,0.0,0.0),3.14));
trans.setOrigin( position );
inertia.setZero();
m_trimeshShape->calculateLocalInertia( mass, inertia );
btDefaultMotionState* motionstate = new btDefaultMotionState( trans );
btRigidBody* body = new btRigidBody( mass, motionstate, m_trimeshShape, inertia );
// body->setRestitution( restitution );
m_world->addRigidBody( body );
// body->setActivationState(ACTIVE_TAG);
// body->setDamping(0.1,0.5);
if( collision )
m_collisionShapes.push_back(m_trimeshShape);
return body;
}
-
- Posts: 5
- Joined: Tue Apr 12, 2011 3:23 am
Re: Random mesh collision.
That totally did the job. Thanx a lot winspear and dphil