How to add static meshes in the scene for collision?

winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm

How to add static meshes in the scene for collision?

Post by winspear »

How do I add static meshes for collision in the scene ?
I need something similar to the NxTriangleMesh shape in Physx.
mspong
Posts: 6
Joined: Tue May 05, 2009 11:25 pm

Re: How to add static meshes in the scene for collision?

Post by mspong »

Add a rigid body with a mass of zero.
winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm

Re: How to add static meshes in the scene for collision?

Post by winspear »

I tried this , but it does not seem to be working.
I got all the vertices from the model in 3 btvector3 arrays and pushed it in to my function.

Code: Select all

btRigidBody* meshActor;
meshActor = addTriangleMesh(*xVerts, *yVerts, *zVerts, btVector3(0.0,0.0,0.0),
		true,btVector3(0.0,0.0,0.0), 0.0, 0.0,true);

btRigidBody* addTriangleMesh( btVector3 &p0, btVector3 &p1, btVector3 &p2,btVector3 &position,
									bool useQuantizedBvhTree,btVector3 &inertia, btScalar mass,
									btScalar restitution, bool collision )
{
	btTriangleMesh* trimesh = new btTriangleMesh();
	trimesh->addTriangle( p0, p1, p2 );
	
	btTransform	trans;
	trans.setIdentity();
	trans.setOrigin( position );

	btCollisionShape* trimeshShape  = new btBvhTriangleMeshShape( trimesh, useQuantizedBvhTree );
	trimeshShape->calculateLocalInertia( mass, inertia ); 
	
	btDefaultMotionState* motionstate = new btDefaultMotionState( trans );

	btRigidBody* body= new btRigidBody( mass, motionstate, trimeshShape, inertia );
	body->setRestitution( restitution );
	
	m_world->addRigidBody( body );
	
	if( collision )
		m_collisionShapes.push_back(trimeshShape);
	
	return body;
}
winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm

Re: How to add static meshes in the scene for collision?

Post by winspear »

I figured the static meshes myself and here is a sneak peak of my first shot at creating something cool using Bullet.
This simulation uses standard btDbvtBroadphase and btSequentialImpulseConstraintSolver. The static mesh also has quantized BVH tree enabled.

A simple video of the the results:

http://somapanam.wordpress.com/2011/02/ ... neth-over/

PS: Probably creating this in Blender is simple but where is the fun in that. Plain old OpenGL and C++ are the best :D