Vehicle falling through terrain

pcg
Posts: 4
Joined: Wed Jun 10, 2009 2:42 pm

Vehicle falling through terrain

Post by pcg »

Hi all,

I've difficulties in getting my vehicle to stay on the terrain which uses btBvhTriangleMeshShape. I'm using Bullet with OpenSceneGraph and btBvhTriangleMeshShape is constructed from btTriangleMesh as follows:

Code: Select all

btTriangleMesh* mesh = new btTriangleMesh;

for( size_t i = 0; i + 3 < vertices->size(); i += 3 )
{
	osg::Vec3& p1 = ( *vertices )[ i ];
	osg::Vec3& p2 = ( *vertices )[ i + 1 ];
	osg::Vec3& p3 = ( *vertices )[ i + 2 ];
	mesh->addTriangle( btVector3( p1.x(), p1.y(), p1.z() ), btVector3( p2.x(), p2.y(), p2.z() ), btVector3( p3.x(), p3.y(), p3.z() ) );
}

btBvhTriangleMeshShape* meshShape = new btBvhTriangleMeshShape( mesh, true );
vertices are extracted from an OpenFlt file with x, y and z starting from 14000, 2000 and 30 respectively. I use the example from Forliftdemo to construct my vehicle's physics and it doesn't interact with the loaded terrain, it just fall through the terrain. However, if I construct the terrain with x (-100 to 100), y (-100 to 100) and z (0), my vehicle will clamp on the terrain nicely. Why is that so?

For setCenterOfMassTransform function, why must we pass in btTransform::getIdentity() in order to get it working?

Thanks,
CG
pcg
Posts: 4
Joined: Wed Jun 10, 2009 2:42 pm

Re: Vehicle falling through terrain

Post by pcg »

Hi all,

I managed to solve it by finding the lowest X and Y values of my terrain and use it to construct the btBvhTriangleMeshShape so that X and Y in the physics world start from 0. Is it a must for X and Y values of the terrain (Z is up axis) to start from 0?

Thanks,
CG