I'm building a 3d car game on the iphone platform using sio2 game engine. I've implemented a third person cam mode. However, i'm finding it difficult to orient my car properly whenever my car comes in contact with a hill/slope.
Please see this (u'll kno wat i mean)->http://www.youtube.com/watch?v=E5p1yHWdpDQ
as you can see my car doesnt change its orientation watsoever. sio2 game engine has been integrated with Bullet, so i can use Bullet to do all that for me.
I've written this code to get the normals at contact points. I'm trying to find the average Normal and use this for my car orientation. (i have no idea wat im doing is even correct!)
This is executed whenever a collision occurs between the car and the terrain
Code: Select all
btRigidBody *_btRigidBody = NULL;
btVector3 avgNormal(0,0,0);
unsigned int i = 0,
j;
while( i != sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getDispatcher()->getNumManifolds() )
{
btPersistentManifold *_btPersistentManifold = sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getDispatcher()->getManifoldByIndexInternal( i );
j = 0;
while( j != _btPersistentManifold->getNumContacts() )
{
_btRigidBody = ( btRigidBody * )_btPersistentManifold->getBody0();
_btPersistentManifold->getContactPoint(j).m_localPointA.normalize();
avgNormal += _btPersistentManifold->getContactPoint(j).m_localPointA;
++j;
}
avgNormal /= j;
++i;
}
My car(single mesh, ie no separate wheels) is a RigidBody (sphere shape) and the terrain is a static triangle mesh.
I'd be glad if someone could help me out. Any code contribution is welcome
