Sign in to follow this  
monstro281

Need some input: bullet physics and Android

Recommended Posts

I managed to compile the bullet physics libraries for android using the android NDK...now I am in need of some direction regarding rendering. Android supports opengl, but does not have any GLUT libraries...which I noticed are used quite a bit in the bullet physics demos. My question is...what would be the best approach for rendering an object (say...a cube) dropped under gravity and colliding with the ground? I have written a simple Java app for android that draws a cube in 3 space and textures it with sides of a dice..and rotates it. I would like to hook this up to bullet and watch the dice bounce around. It seems like I should change the rendering from Java to C++...do I simply create the object in bullet and somehow export the vertices to opengl? Keep in mind I am a newbie at all this...

Share this post


Link to post
Share on other sites
bzroom...that wasn't my question.

My question is related to bullet...how do I attach bullet to opengl without using GLUT? Since I am not familiar with either one, is it simply a matter of taking the vertexes of the cube from bullet and rendering in openGL, or is some transformation needed?

Share this post


Link to post
Share on other sites
Quote:
My question is related to bullet...how do I attach bullet to opengl without using GLUT? Since I am not familiar with either one, is it simply a matter of taking the vertexes of the cube from bullet and rendering in openGL, or is some transformation needed?
You're talking about three different things here: a physics engine, a graphics API, and a windowing/events API. None of these is really *attached* to the others in any special way; in fact, they're all pretty much orthogonal to each other, and you could easily swap one of them out without affecting the others. (For example, you could swap GLUT for SDL and get basically the same results.)

The way objects in a physics simulation are typically linked to their visual representations is as follows: you acquire the object's transform from the physics engine via the physics engine's API, and then pass that transform to the rendering system. The details of each step depend of course on the respective APIs.

I'm not that familiar with Android, so I don't think I can offer much in the way of specifics. Maybe someone else will be able to though.

Share this post


Link to post
Share on other sites
You need to create a function in your graphics code that looks like this:

void DrawCube( float transform[16] )
{
glPushMatrix( ); glMultMatrixf( GL_MODELVIEW_MATRIX, transform );
//vertex cube code from the link i gave you
glPopMatrix( );
}


Then in your simulation loop you need something like this:

void Step( float dt )
{
bulletWorld.Step( dt );

float *tranform = myBulletBoxObject.getWorldTransform( ).getOpenglMatrix( );
DrawCube( transform );
}


Bullet and your rendering will not share the same vertex data. Bullet will use a box primitive, which does not have vertices. It is represented simply by an extents vector. you'll need to make sure that you create your bullet box representation the same size as you create our graphics representation. Then when you apply the bullet transform to the graphics, it will appear as if they are sharing the same data.

Share this post


Link to post
Share on other sites
bzroom is correct, bullet has nothing to do with OpenGL you can use whatever rendering you like to draw whatever you want. I am not familiar with bullet, but it can't be much different from any other major physics engine. With that said I would assume that after each simulation step, all you have to do is obtain the rigid body transform and apply it to the object that you are simulating and the draw..

Share this post


Link to post
Share on other sites
To get debug rendering from Bullet, you'll need to derive from btIDebugDraw and implement the appropriate methods, then call btCollisionWorld::setDebugDrawer, passing in an instance if your debug drawer.

You can rip a lot of this debug rendering straight from the bullet samples; the debug drawer in there doesn't rely on anything GLUT specific as far as I can remember. 'btIDebugDraw' is what you'll want to search for.

Share this post


Link to post
Share on other sites
Quote:
Original post by cgrant
bzroom is correct, bullet has nothing to do with OpenGL you can use whatever rendering you like to draw whatever you want. I am not familiar with bullet, but it can't be much different from any other major physics engine. With that said I would assume that after each simulation step, all you have to do is obtain the rigid body transform and apply it to the object that you are simulating and the draw..


Dude...I didn't say they were related...it is simply MY preferred method of rendering from bullet on Android...and bzroom didn't answer the question...he stated something that I already said I had done in Java for the android.

Regarding the second half of your post...now you are actually helping. That was what I was wondering...now I have to look at the API and understand how to transform the object for openGl..

Share this post


Link to post
Share on other sites
Quote:
Original post by bzroom
You need to create a function in your graphics code that looks like this:

void DrawCube( float transform[16] )
{
glPushMatrix( ); glMultMatrixf( GL_MODELVIEW_MATRIX, transform );
//vertex cube code from the link i gave you
glPopMatrix( );
}


Then in your simulation loop you need something like this:

void Step( float dt )
{
bulletWorld.Step( dt );

float *tranform = myBulletBoxObject.getWorldTransform( ).getOpenglMatrix( );
DrawCube( transform );
}


Bullet and your rendering will not share the same vertex data. Bullet will use a box primitive, which does not have vertices. It is represented simply by an extents vector. you'll need to make sure that you create your bullet box representation the same size as you create our graphics representation. Then when you apply the bullet transform to the graphics, it will appear as if they are sharing the same data.


Awesome...thanks, this is exactly what I am looking for!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this