• 11
• 15
• 19
• 27
• 9

# Box2D Pixel to Meter conversion problem

This topic is 2935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on learning Box2D but since it works in meters and centers of mass, it is a bit confusing to say the least especially when it comes to placing objects with SFML graphics, although I can get it to work, it takes a lot of trial and error figuring things out. So when you create a world,
//Create the size of the world
b2AABB worldAABB;

//Upper left corner of the world
worldAABB.lowerBound.Set(-3000, -3000);

//Lower right corner of the world
worldAABB.upperBound.Set( 3000,  3000);


Now I know, I know it is confusing lowerBound is actually the upper left corner and the upperBound is the lower right corner for specifying the world size. Now I was thinking what is the conversion rate between pixels = 1 meter, I read somewhere it was 30 pixels to 1 Meter in Box2D so if that is the case I could do something like,
//Variables for Pixel to Meter ratio
const int RATIO = 30;


So in theory I should be able to divide the -3000 and 3000 by RATIO, to looks like this.
//Upper left corner of the world
worldAABB.lowerBound.Set(-3000 / RATIO, -3000 / RATIO);

//Lower right corner of the world
worldAABB.upperBound.Set( 3000 / RATIO,  3000 / RATIO);


So my question, would that world properly for being able to draw in so if I wanted to draw a shape at X and Y pixels like (10, 10) I could do this to figure out the world position in Box2D (10 / RATIO, 10 / RATIO) is this correct? Or do I do (10 * RATIO, 10 * RATIO)? Would either of these work out how I am explaining?