0
\$\begingroup\$

I made an OpenGL 3.x renderer for Box2D's debug draw (b2Draw base class). Unfortunately I've tried for a while now to convert the box2D units, which are meters to my internal units which are pixels. I make 1 meter == 50 px, I set the sizes and positions just fine. It's only the debug renderer that is giving me trouble, because I don't know how to set the ortho and view matrix properly.

Basically I've got a camera which I center on the player's position each tick, the player's position being in pixels..so it could be say 2500x, 3200y. So the camera's view mat4 would be centered on that and the ortho is just set to the size of the screen.

So somehow I need to be able to turn this so that the position and the sizes are properly set. I'm using GLM for my matrix handling.

For example, I will see the physics debug data on screen if i set the ortho to be PIXELS_PER_METER (which is 50) for both x and y. But obviously this wouldn't map to worldspace, so my actual sprites won't have the physics bodies rendered where they are.

I've tried several things, including glm::scale, glm::translate with all kinds of different values and now I'm just out of ideas. Anything else I try results in no physics data to be drawn..

\$\endgroup\$
1
\$\begingroup\$

well, turns out my real issue is not using meters as my internal units..that should solve everything.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.