Some people have asked for Box2D to use pixels instead of meters. Please voice your opinion in this poll.
Length Units
General Discussionwould 2.0 pixel units solve the HUEG torque numbers and such issue or would that still be there?
Actually I think from what Erin was saying it would make it even worse!
For example a 1m x 10m box would probably have dimensions of
something larger like 10px x 100px. So I guess all the torques would multiply as well?
Wow. I'm surprised so many meters vs pixels. I guess people are somehow using
meters in their graphics libraries.
Mike
For example a 1m x 10m box would probably have dimensions of
something larger like 10px x 100px. So I guess all the torques would multiply as well?
Wow. I'm surprised so many meters vs pixels. I guess people are somehow using
meters in their graphics libraries.
Mike
I prefer MKS units as the "native" format for a physics engine, with scale factors to convert between application units and physics units. I'm not sure how to handle the "ZOMG HUEG!" forces and torques when dealing with large scale factors, but maybe an appropriate mass scale (distance scale squared) would help keep object masses sensible.
As an easy example, suppose I set 64 pixels per meter. With a mass scale of 4096, a 64x64 pixel box with density 1 would end up with mass 1, just just like a 1x1 meter box with density 1. I don't know if that will actually solve the problem, as I haven't tried it.
As an easy example, suppose I set 64 pixels per meter. With a mass scale of 4096, a 64x64 pixel box with density 1 would end up with mass 1, just just like a 1x1 meter box with density 1. I don't know if that will actually solve the problem, as I haven't tried it.
mike950 wrote:
Wow. I'm surprised so many meters vs pixels. I guess people are somehow using
meters in their graphics libraries.
Mike
meters in their graphics libraries.
Mike
It took a little getting used to (I'm used to pixels), but OpenGL handles meters just fine. Just gotta use a smaller viewport, that's all.
I like being able to specify numbers in units that I can understand. 9.8 m/s^2 makes sense... 100 pixlels/sec... just seems arbitrary.
Plus, at least for what I'm doing, I'm going to allow zooming in and out, so "pixels" wouldn't really make sense either.
I think meters make much more sense than pixels because of a few things. First of all, as already stated by previous poster, it's much easier to deal with something that is common such as meters, physics wise. I know that many people would prefer pixels so they can directly translate the physics engine positions/sizes into screen coordinates, but many games don't even "lock" the game resolution to a certain size. Furthermore dynamically changing the physics engine units according to a resolution would give funny results, and while you could develop your engine in a "default" resolution size, and just stretch the game to fit another resolutions, it'd really be same as using meters.
Assume that someone is developing a game in 640x480 resolution, and someone else is doing a similiar game in a 800x600. Let's say that both of them want the character to be 1/20 of the screen size horizontally. You probably see where I'm going with this. The sizes would mismatch, and I think it'd be difficult to choose the "right" pixel size for Box2D. Also remember that pixels are relative units, their length depends on the resolution of the device they're rendered on, while meters are absolute units and much easier to work with in a physics engine. To convert from meters to your game coordinates all you have to do is define a function to translate the meters to the pixels. All you have to do is define how long is your game area in meters. Taking the previous example, let's say that the game area size is 10 meters x 7.5 meters and thus your character size is 0.5 meters x 1 meter (or so). Getting the player width in pixels is as simple as doing (in 640x480): 0.5*(640/10) = 32.
And as someone already stated, some APIs can work just fine with meters as scale, I'm doing the exact same thing in OpenGL as well (I define an orthographic projection using meters as unit).
Assume that someone is developing a game in 640x480 resolution, and someone else is doing a similiar game in a 800x600. Let's say that both of them want the character to be 1/20 of the screen size horizontally. You probably see where I'm going with this. The sizes would mismatch, and I think it'd be difficult to choose the "right" pixel size for Box2D. Also remember that pixels are relative units, their length depends on the resolution of the device they're rendered on, while meters are absolute units and much easier to work with in a physics engine. To convert from meters to your game coordinates all you have to do is define a function to translate the meters to the pixels. All you have to do is define how long is your game area in meters. Taking the previous example, let's say that the game area size is 10 meters x 7.5 meters and thus your character size is 0.5 meters x 1 meter (or so). Getting the player width in pixels is as simple as doing (in 640x480): 0.5*(640/10) = 32.
And as someone already stated, some APIs can work just fine with meters as scale, I'm doing the exact same thing in OpenGL as well (I define an orthographic projection using meters as unit).
How about using cm?
So with the dimensions you mentioned
10 meters x 7.5 meters = 1000cm x 750cm (or you could just as easily say 1000px by 750px no conversion necessary)
character size is 0.5 meters x 1 meter = 50cm x 100cm (or again 50px by 100px)
So it seems to me cm is ideal since you can use them for pixels or meters without any
need for conversions. Just depends on what you want to label the units at that point.
Mike
So with the dimensions you mentioned
10 meters x 7.5 meters = 1000cm x 750cm (or you could just as easily say 1000px by 750px no conversion necessary)
character size is 0.5 meters x 1 meter = 50cm x 100cm (or again 50px by 100px)
So it seems to me cm is ideal since you can use them for pixels or meters without any
need for conversions. Just depends on what you want to label the units at that point.
Mike
Flash uses pixel units, but I still think Box2D should use meters.
Even if it did use pixels, it would need some kind of scale because 1 meter might be 100 pixels in one game, and 10 in another, so you might as well just use meters and let the end user handle the scale on application to application basis.
One way to get the best of both worlds, would be to extend the use of b2_lengthUnitsPerMeter, so that users can set that to whatever scale they want, say 30 units(pixels) per meter, and then just use that scale in everything they do, e.g make a box 30 units wide and let the engine scale values down 30 times when body is created, and scale them back up when you retrieve position data for rendering.
Might be a bit messy though, this really should be up to the end user to manage anyway.
So as far as I'm concerned meters are fine and nothing needs to be changed or added.
Even if it did use pixels, it would need some kind of scale because 1 meter might be 100 pixels in one game, and 10 in another, so you might as well just use meters and let the end user handle the scale on application to application basis.
One way to get the best of both worlds, would be to extend the use of b2_lengthUnitsPerMeter, so that users can set that to whatever scale they want, say 30 units(pixels) per meter, and then just use that scale in everything they do, e.g make a box 30 units wide and let the engine scale values down 30 times when body is created, and scale them back up when you retrieve position data for rendering.
Might be a bit messy though, this really should be up to the end user to manage anyway.
So as far as I'm concerned meters are fine and nothing needs to be changed or added.
skatehead wrote:
Even if it did use pixels, it would need some kind of scale because 1 meter might be 100 pixels in one game, and 10 in another, so you might as well just use meters and let the end user handle the scale on application to application basis.
But if it used pixels then there wouldn't be any meters to scale I would think. I must be a very confused
individual since so many people prefer meters. At least units of centimeters are close enough to pixels
you could just say 1cm = 1px and not need to do any scaling.
Based on the poll results I will stick with meters as the primary unit used in Box2D. You can still use other units, but it will take more effort on your part to make sure you have b2Settings.h adjusted correctly.
This topic is now locked.
This topic is now locked.
Original thread: https://box2d.org/forum/viewtopic.php?t=173