I need help with btGImpactMeshShape, my mesh won't move.

seb
Posts: 1
Joined: Fri Feb 20, 2009 9:09 am

I need help with btGImpactMeshShape, my mesh won't move.

Post by seb »

Hello everyone.
I'm new to Bullet so please forgive my stupid questions :wink:

I'm trying to use Bullet Engine in my app, but I'm having some problems.

I create btTriangleIndexVertexArray and btGImpactShape using vertex and index arrays (I know they're ok, I use them to draw my shape with glVertexPointer() etc...), like this:

Code: Select all

btTriangleIndexVertexArray * vert = new btTriangleIndexVertexArray
											( myShape->numberOfTriangles(),
											  &myShape->indices[0],
											  3*sizeof(int),
											  myShape->numberOfVertices(),
											  &myShape->vertices[0].position[0],
											  sizeof(MyVertex)  );
btGImpactMeshShape * impact_shape = new btGImpactMeshShape( vert );
Then I do something like this:

Code: Select all

impact_shape->setLocalScaling(btVector3(1.,1.,1.));
impact_shape->setMargin(0.07f);
impact_shape->updateBound();
And finally:

Code: Select all

btVector3 localInertia;
btScalar mass(1.0f);
btTransform startTransform;
startTransform.setOrigin( btVector3(center.data[0],center.data[1],center.data[2]) ); //center is myShape's center
impact_shape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* motionState = new btDefaultMotionState(startTransform);
btRigidBody * rig = new btRigidBody(mass,motionState,impact_shape,localInertia);
g_dynamicsWorld->addRigidBody(rig);
When I call these functions each frame:

Code: Select all

g_dynamicsWorld->stepSimulation(1.f/60.f,10);
g_dynamicsWorld->applyGravity(); //do i have to call this function? or is it called by stepSimulation() ?
my meshes won't move...
But when I print out :

Code: Select all

for (int j=g_dynamicsWorld->getNumCollisionObjects()-1; j>=0 ;j--)
{
	btCollisionObject* obj = g_dynamicsWorld->getCollisionObjectArray()[j];
	btRigidBody* body = btRigidBody::upcast(obj);
	if (body && body->getMotionState())
	{
		btTransform trans;
		body->getMotionState()->getWorldTransform(trans);
		printf("%i: world pos = %f,%f,%f\n",j,float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
	}
}
I can see that they're falling down ( Y-coordinate is decreasing ).

Please can you tell me what am I doing wrong?
Thanks in advance.

Regards
seb

---------- edit ----------

Oh, and here is my init. function:

Code: Select all

g_collisionConfiguration = new btDefaultCollisionConfiguration();
g_dispatcher = new btCollisionDispatcher( g_collisionConfiguration );
g_worldMin = btVector3(-500,-500,-500);
g_worldMin = btVector3(500,500,500);
g_maxProxies = 1024;
g_overlappingPairCache = new btAxisSweep3(g_worldMin,g_worldMax,g_maxProxies);
g_solver = new btSequentialImpulseConstraintSolver();
g_dynamicsWorld = new btDiscreteDynamicsWorld( g_dispatcher,
									   g_overlappingPairCache,
									   g_solver,
									   g_collisionConfiguration );
g_dynamicsWorld->setGravity( btVector3(0,-9.81,0) );
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(g_dynamicsWorld ->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);