Skip to main content
GameDev.net gamedev.net
🔒 Locked

[DX9] pixel - meter conversion

Started by miloszmaki Mar 3, 2011 at 5:50 PM 2 replies 1.8k views
Original Post
miloszmaki
miloszmaki
Hi,
I must figure out some factor, so I could do the following conversion:
pixels = meters * factor
meters = pixels / factor
I need it, because I have to set near / far plane or scale models to appropriate size. For example: if I had 1x1x1m cube and the factor was 2.0, the cube's model dimmensions would be 2x2x2.
It's quite problematic to choose good factor - if too small or too big then I'll get some numerical errors and visual artifacts (e.g. z-fighting).
I also have to set up gravity force in my physics engine, so it would be something like:
gravity = 9.81f * factor
Velocity, position, distances and other things depend on the factor as well.
Again, too small or too big factor will cause problems with stability and accuracy of physics engine.
What should be the factor ? What values do you use for near / far plane ?
Tom
Tom
It depends entirely on the size of your models. If a model is supposed to be 2m tall and is 200 units in your editor, the factor is 200 units/m.
GDNet+. It's only $5 a month. You know you want it.
miloszmaki
miloszmaki

It depends entirely on the size of your models. If a model is supposed to be 2m tall and is 200 units in your editor, the factor is 200 units/m.


OK. But I can scale my models, so they will fit the desired size of the virtual world. I'm just wondering what this world's size should be, because small or big values might produce numerical errors. For example, I cannot place all game world's objects in 0...1 range, cause it'd be poorly precise, conversely, if the world's size was 0...10^18, large values would produce errors and loss of precision (e.g. when multiplying them).
Zakwayda
Zakwayda
If the simulation is 2-d and uses perspective projection, pixels don't really figure into it, I don't think (and similarly if the game is 2-d but supports multiple resolutions).

I cannot place all game world's objects in 0...1 range, cause it'd be poorly precise[/quote]
For what it's worth, floats are at their maximum precision, more or less, in the range [-1, 1] (IINM). But, compressing the entire simulation into that range probably wouldn't be very convenient.

If you want to use a real-world scale, I'd just go with 1 unit = 1 meter, set the near and far plane distances to the largest and smallest suitable values (respectively), and see how that works out. (I doubt you'd run into problems with that unless you're working with very large environments.)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.