Game Development Reference
In-Depth Information
Building a custom motion state
The entire code for our custom motion state can be found in a single header file
OpenGLMotionState.h . The only interesting function is GetWorldTransform() ,
which takes an array of btScalars (16 of them to be precise, representing a 4 x 4
matrix), and performs a little math to return the same data in a format that OpenGL
understands. getOpenGLMatrix() is a helper function built into btTransform that
does this for us. OpenGL and Bullet are used together so often ( the open source
graphics library used together with the open source physics engine; who would have
guessed?) that the developers of Bullet felt it was prudent to do this.
Tip
btScalar is a simple float by default, but could also be a double if #define
BT_USE_DOUBLE_PRECISION is placed somewhere in the code. We'll continue
to use floats for this project.
It is a clean and efficient process to feed data between Bullet and OpenGL because
they both use right-handed coordinate systems, which defines how the x , y , and z
axes relate to one another. If we used a different physics and/or graphics library, we
might find that our objects move or render backwards on one of the axes. In that case
we may have a disconnection between our coordinate systems, and we would need
to determine which axis has been flipped, and make the necessary adjustments. The
following diagram shows the difference between the left-handed and right-handed co-
ordinate systems:
Search WWH ::




Custom Search