PDA

View Full Version : Scale bar - Computation of a good initial value

youpi1
01-26-2013, 09:04 PM
Hi,

I developed a program which models the dynamics of a stellar disk. Rendering is done in 3D with rotation and zoom functionalities. Here's an image at the start of the simulation :

http://i.imgur.com/wWEGyYY.png

You can see on top the different statistics. My problem is about the initial value of the scale (100 kpc). Indeed, I use for initialization a perspective projection this way :

if (isDisplayFirst)
{
isDisplayFirst = false;

// Initialize View
glViewport(0, 0, w_width, w_height);

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix

/* perspective */
gluPerspective(45.0f, (float)w_width / w_height, g_nearPlane, g_farPlane);

/* distance z = 3 */
gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

/* zoom out = 100/3 */
glScalef(0.03f, 0.03f, 0.03f);
}

My widget has the following dimensions :

w_width = w_height = 600

So, from a simple computation, I think that I can have :

Scale_value_Init = tan(45) * distance * zoom_out = 3*100/3 = 100

with

distance = 3 and zoom_out = 100/3

To display the HUD (Head Up Display), I use a orthogonal projection and I draw a line of 100 pixels.

When I compare the "Scale_value_init" value with the average position values of each particle, I can see this initial value is a little too big.

There must be an arror in this initial value computation for scale bar.

Unities used in this program are "kpc" (kilo parsec) and I have set : 1 pixel = 1 kpc.

I just want to get a good value which gives a distance scale in (xy) plane.

Could you tell me why this calculus is wrong and give me some clues to get a good estimation ?

tonyo_au
01-26-2013, 11:30 PM
I don't understand what you are trying to achieve. Are you trying to draw a fixed line on the screen and then say how many kpc that represents?

youpi1
01-27-2013, 01:11 AM
I don't understand what you are trying to achieve. Are you trying to draw a fixed line on the screen and then say how many kpc that represents?

yes, I draw a fixed line of 100 pixel and I would like to put the distance that it represents in kpc

tonyo_au
01-27-2013, 04:55 PM
Given that you are rendering a 3D object in perspective view, this length only has meaning at a certain distance from the eye point so 100 pixels on the screen can similtaneously be 2 meters close to the camera and 10000 meters a long way from it; so it is never "right" or "wrong".

youpi1
02-03-2013, 06:00 PM
Given that you are rendering a 3D object in perspective view, this length only has meaning at a certain distance from the eye point so 100 pixels on the screen can similtaneously be 2 meters close to the camera and 10000 meters a long way from it; so it is never "right" or "wrong".

I would like this scale bar (located at z=100) represents the distance in (xy) plane for the objects at z=0, could you help me please

tonyo_au
02-04-2013, 11:11 PM
objects at z=0

Do you mean at the camera eye point or do you mean at the near plane. The scale of something at the camera eye point cannot really be calculated. Have you looked at what the prespective matrix actually is see http://www.songho.ca/opengl/gl_transform.html