How to draw physics bodies/shapes in OpenGL ES 2.0

TheKeiron
Posts: 2
Joined: Thu Aug 16, 2012 1:38 pm

How to draw physics bodies/shapes in OpenGL ES 2.0

Post by TheKeiron »

I'm trying to display the actual bodies/shapes in my world in C++ with openGL ES 2.0 but I'm having trouble working out how to do it; I can grab the vertex points and normals from a shape with:

Code: Select all

        btVector3** vertices= myShape->getVertices();//myShape is a btBox2dShape
	btVector3**normals = myShape->getNormals();
but there is no way to grab the indices to tell opengl which order to draw the vertex points in! Is there a way to get these? Or is it possible to programmatically calculate the indices?
warmi
Posts: 5
Joined: Tue Nov 18, 2008 8:06 pm

Re: How to draw physics bodies/shapes in OpenGL ES 2.0

Post by warmi »

You can just either send vertices without indices if you don't care about perfomance ( which you shouldn't really since this is just for debugging) or , as you mentioned, you can calculate indices programatically.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: How to draw physics bodies/shapes in OpenGL ES 2.0

Post by Flix »

For polyhedral convex shapes (such as box, convex hull shapes and a few others), you can make Bullet calculate the indices for you (see btPolyhedralConvexShape::initializePolyhedralFeatures() and the classes btPolyhedralConvexShape.h and btConvexPolyhedron.h).

You can also use btShapeHull and btConvexHullComputer (inside LinearMath) to perform the same task (btConvexHullComputer gives better results).

For other shapes (sphere, capsule, cylinder, multisphere, cone) you can't use this method and you should draw them manually using the shape parameters (radius, height, etc.).

However, as warmi said, this kind of drawing shapes is usually done just for debugging: in real applications you want to display real meshes instead of the "default shapes": that's why some people could think of just relying on the debug drawer (that can do some "raw" wireframe rendering (inaccurate for some shapes like multisphere)) or raycast screenshots, without writing any code for displaying shapes.

Additionally, even if you target openGLES, for problems related to the mesh topology you can still take a look at the code in libOpenGLSupport (the basic brick of all the Bullet demos).

P.S: I usually calculate the normals myself from the vetices/indices, but if you're able to obtain them in some other way it might work as well.
TheKeiron
Posts: 2
Joined: Thu Aug 16, 2012 1:38 pm

Re: How to draw physics bodies/shapes in OpenGL ES 2.0

Post by TheKeiron »

Thanks for the pointers guys, as you both pointed out I should have looked at the debugging functionality in the first place, I've created my own DebugDraw class (implementing the btIDebugDraw interface) and have it drawing my wireframe physics world correctly :)
khoowaikeong
Posts: 43
Joined: Fri Jun 15, 2012 7:11 am

Re: How to draw physics bodies/shapes in OpenGL ES 2.0

Post by khoowaikeong »

i set debug mode to 1(wireframe) and it only draw the transformation (3 line axis)
how can i make it draw the shape?