To give some background on the issue I am using Box2D and am trying to use the built in debug draw functionality to create a debug overlay that will allow me to see the physics bodys’ actual shapes over the game’s graphics. The issue arises in the combination of a moving view system implemented by translating and rotating the modelview matrix before rendering the scene and the fact that Box2D coordinates are a smaller scale factor of screen coordinates (in the case of the current project I am multiplying screen coordinates by .05 to get box2D coordinates). Both features work correctly independently.
When it is time to use Box2D’s debug rendering I can make the scaling work easily by scaling the modelview matrix but only if it has not already be transformed at all by the view system. After that if I apply the same transformations to the scaled modelview as I did to the original using the view system I get the correct results. I know how I can make it work in a rather costly way but it would be a lot easier if there was some way to insert the transformation (aka use prefix multiplication instead of the usual postfix) in OpenGL.
I am using the old OpenGL built in matrices without shaders, so I am only manipulating matrices using functions like glTranslate and glRotate. Is there a way of directly reading/writing the values in the matrix or else some sort of OpenGL setting for how to apply transformations?
Yes there is
glGetDoublev(I recommend using double precision for this) which can query the current matrices on the individual stacks. See http://www.opengl.org/sdk/docs/man2/xhtml/glGet.xmlThen you can use
To apply your own transformation before what was on the stack. Use
glPopMatrixto clean up after yourself.