Help getting started with bullet in my application

Warpedstone
Posts: 2
Joined: Mon Jan 31, 2011 6:04 am

Help getting started with bullet in my application

Post by Warpedstone »

Hello everyone,

I have successfully installed bullet and compiled the helloworld example. Now what? How do I interface bullet with another 3D world? There doesn't seem to be any examples of anyone doing this. How do I get bullet to respond to the 3D world I have and move the objects in it.

Thanks for any help,
Warped
winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm

Re: Help getting started with bullet in my application

Post by winspear »

Create the graphics and the physics objects separately. Then while drawing the graphics objects, just get the motion state transform from physics and push it in to the graphics object. Thats it :D

For example: This is to create a simple cube of side 1.0

Physics object creation:

Code: Select all

btRigidBody* addPhysicsBox( btVector3 &boxHalfExtends, btVector3 &position, btVector3 &inertia, btScalar mass, btScalar restitution, bool collision ){
	btTransform trans;
	trans.setIdentity();
	trans.setOrigin( position );
	
	btCollisionShape *geom = new btBoxShape ( boxHalfExtends );
	geom->calculateLocalInertia( mass, inertia );

	btDefaultMotionState* motionstate = new btDefaultMotionState( trans );
	btRigidBody* body = new btRigidBody( mass, motionstate, geom, inertia );

	m_world->addRigidBody( body );
	
	if( collision )
		m_collisionShapes.push_back(geom);

	return body;
}

btRigidBody* boxActor;

boxActor = addPhysicsBox(btVector3(0.5,0.5,0.5),btVector3(0.0,5.0,0.0),
			btVector3(0.0,0.0,0.0),1.0,0.2,true);
Graphics object display:

Code: Select all

void renderCube(float m_Side, btTransform &boxTransform)
{
	GLfloat tempForm[16];
	boxTransform.getOpenGLMatrix(tempForm);

	glPushMatrix();

	glMultMatrixf(tempForm);

        glutSolidCube(m_Side);

	glPopMatrix();
}

renderCube(1.0, boxActor->getWorldTransform());
To get Motion state transform:

Code: Select all

void getBulletTransform(btRigidBody* rigidBody) 
{
	btMotionState* shapeMotionTransform;
	shapeMotionTransform = rigidBody->getMotionState();
	float openGLTransform[16];
	btTransform worldTransform;
	shapeMotionTransform->getWorldTransform(worldTransform);
	worldTransform.getOpenGLMatrix(openGLTransform);

     //Return the motion state opengl transform however you want

}
Warpedstone
Posts: 2
Joined: Mon Jan 31, 2011 6:04 am

Re: Help getting started with bullet in my application

Post by Warpedstone »

Thanks winspear! I should be able to figure it out from here. If I run into anymore problems I will let you know. I can't believe there wasn't already several posts asking how to get started.

Anyway, thanks again,
Warped