Box2D Coordinate Conversion

Hi Everyone,

I am trying to implement some Box2D physics into a JUCE project by following the tutorial here, which is done in the Java framework Processing. Converting to JUCE terms hasn’t been hard but they have a helper module for converting from Processing coordinates, which are the same as JUCE’s – (0,0) is the top-left and it goes rightwards and downwards in pixels – to Box2D coordinates, which start at the center and are apparently done in meters, (!!) because physics.

I have two questions here. Does anyone know if JUCE’s Box2DRenderer class is doing this kind of coordinate conversion for you? and if not…

Does anyone knows of an existing C++ helper library for Box2D that converts the JUCE-style coordinate system to the Box2D system and vice-versa?

Thanks!

–Marc

I’ve worked with box2d and I don’t know of such. Some simple arithmetic should get the job done. Just know the size of your Box2d window and add half to your JUCE coordinates. Make sure your component edges line up, or know the margin you use in your calculations.

1 Like

Cool thanks!