Archived

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

Erkki

Metric units -> pixels

Recommended Posts

Erkki    122
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 this post


Link to post
Share on other sites
AN_D_K    158
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 this post


Link to post
Share on other sites
Erkki    122
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 this post


Link to post
Share on other sites
Raloth    379
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 this post


Link to post
Share on other sites
Erkki    122
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.

Share this post


Link to post
Share on other sites