I was just wondering whether there is a way to apply bullet physics to opengl drawn objects (created using glVertex3f or triangle mesh with glVertexAttribPointer). I am currently using jogl and jbullet to apply physics to my 3D objects. Specifically if I give a buffer of vertices for a triangle mesh shape for the 3d object. I need Bullet to create a CollisionShape based on the triangle mesh shape, and apply the physics to it, which at the same time apply physics to the drawn opengl objects. At the moment, the physical collision shape may move (in bullet), but the drawn opengl shape is not.
Otherwise, can I create a collision shape, get the vertices of the collision shape after the physics has been applied after each simulation step, and then draw the object based on the location of the vertices. I have looked at the Hello world example for bullet but it only help me apply physics on the position of the opengl object (based on the z,y,x axis_ and not cool things like for example a corner of the cube hitting a plane starts rolling and spinning.
It would be great if someone can give me some code or demo that can do this. Or give me some hints as to how I can make this work. I already looked at this tutorial on bullet: http://www.raywenderlich.com/53077/bullet-physics-tutorial-getting-started. But I can't seem to find the information to how bullet is applied to opengl objects.
Physics engines don’t know anything about OpenGL; and in fact, all of them can run without any 3D visualization at all. So you can’t directly give Bullet your VBO. You have to add a Rigid Body in the simulation instead. Notice that the Rigid Body use the Collision Shape to determine its shape.
After you downloaded Bullet Physics SDK, look the file GL_ShapeDrawer.cpp,you will find some interresting functions such like drawSphere, drawCylinder,drawOpenGl.. the last one i mentionned lets you draw any type of suported shape : Each type of shape from shape->getShapeType () has its own dedicated function for rendering with opengl
Bullet is independent of OpenGL, it's up to you to apply the transformation to your geometry. You can store your transforms into separate objects instead of modifying your vertices.
There is not any function in openGl that allow you to apply rotation and translation to any entire shape because in opengl you just manipulate vertices, so i think you need to create your own graphics shape class. This class must at least contain all the vertices used to represent your graphics shape.
After you downloaded Bullet Physics SDK, look the file GL_ShapeDrawer.cpp,you will find some interresting functions such like drawSphere, drawCylinder,drawOpenGl.. the last one i mentionned lets you draw any type of suported shape :
Each type of shape from shape->getShapeType() has its own dedicated function for rendering with opengl
But my method involves to
Personnaly, i'm using Irrlicht because Irrlicht is the "write less,do more" solution of opengl :p
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With