pixel to centimeter

Started by
2 comments, last by haegarr 14 years, 1 month ago
Hi I have a simple problem but i don't know how to solve it! i am developing a simulator with opengl and everything is ok but i need to measure my distances in centimeter but in opengl everything is pixel so i want to know how to convert them at different resolution and monitors! thanks a lot!
Advertisement
If you refer to the mapping of pixels on the screen, to the corresponding size in real world units as appearing on the screen, then you need to look into your platform API and search for functions to determine the physical size of the screen. It is not related to OpenGL in any way though.
Under Windows there's not really any way to do this - the user could be running at 1024x768 on a 14 inch monitor and get 1cm = 50 pixels, or they might be running on a 52 inch screen where 1cm = 2 pixels, and there's no API to tell you the physical of the screen.
Quote:Original post by shafiee01
...but in opengl everything is pixel...
Nope. The pixels are just the last step when computing distances:

1st you have to decide on the world length unit. This is freely chooseable, let's say 1m. This is to be considered when importing meshes. E.g. the mesh of a human should then be scaled on import so that it is approx. 1.7 units high.

2nd you have the extent of what I call the "nominal view", i.e. the size of the view plane in world units. Unfortunately, the view plane's size is constant only for parallel projections; it is depth dependent for perspective projections.

3rd you have to consider the angle with which the projectors hit the view plane. The factor is sin( α ) where α denotes the angle in the respective dimension (w.r.t. the camera space). E.g. for orthogonal projections the factor is 1.

4th you have a scaling factor incorporated into the VIEW portion of the MODELVIEW matrix. This scaling denotes the zoom of the virtual camera.

The above defines the viewing volume. Now comes the screen into play:

5th the view volume is projected onto a plane, and the plane is sampled. Each sample is then typically displayed on the screen with a 1:1 relationship to pixels. That is what I call the actual view. It has a (physical) size corresponding to the amount of pixel columns/rows multiplied by the screen resolution.

That said, you can sensefully measure distances just under special conditions. E.g. using parallel projection, or else measuring only between points that have the same depth _and_ this depth is known (e.g. on the view plane when those is defined to do a 1:1 projection).

It can be senseful to define a viewing system based on the above. However, IMHO the only senseful way to measure distances is to let the user pick 2 points (typically vertices) and to compute the distance in 3D, multiply that with the length unit chosen under point 1, and display that as text.

This topic is closed to new replies.

Advertisement