#### Archived

This topic is now archived and is closed to further replies.

# Metric units -> pixels

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

## Recommended Posts

In my 2D engine, I want to use metric units to define distances, object sizes and locations in my project. Mostly for clarity, and to support multiple resolutions. But I don''t know where I should do the conversion to pixels. 1) I could do it in the renderer, but I''m concerned it will affect speed (doing conversions for every coordinate). 2) I could do it while loading the world, but I''d like the scripts and other systems to also use metric units so I''d have to do conversions every time a game objects position is manipulated. I''m confused, and afraid the whole system will become very complicated.

##### Share on other sites
Why would it get complicated? Just use the same coordinates throughout.. What am I missing?

##### Share on other sites
Just make sure that all your 3D model''s coordinates are in scale with each other. Then you won''t have to do any messy and expensive scaling in your program.

##### Share on other sites
But my game is not 3D. It''s 2D.

I personally would prefer to use metric units everywhere, except when I finally draw them on screen, I would convert them to pixels, based on the current resolution.
But that means I would maybe have to scale every 2D sprite on every rendering. Well, I want to support zooming anyway, so I''d probably have to do it anyway.

Ok, another question then:
Would it be wiser to use integers or floats for metric coordinates?
10.5 = 10.5 m
1050 = 10.5 m (I don''t need any more precision)

##### Share on other sites
If you use Direct3D or OpenGL you can simply set up an orthogonal projection with 1,1 as the lower right corner. That way you can give your positions in fractions of a screen and it will be the same on any resolution.

##### Share on other sites
Thanx, I''ll try that. I have no experience with OpenGL or D3D, but there are some tutorials on how to do 2D in them and I think and it would also make zooming / rotating easier.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002234
×