zooming with glortho should be same as with glPerspective?

Started by
10 comments, last by sjaakiejj 12 years, 2 months ago
Actually I can zoom in and zoom out with both projections.. but the issue is.. i am unable to manage the similar zoom with glortho.. i mean to say the model must be at the same location when i switch to glortho..

zooming should be equal in glPerspective and glortho..

my switch function..


glViewport(0, 0, WIN_WIDTH, WIN_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if(ortho)
{
double left = -(double)WIN_WIDTH/2.0;
double right = (double)WIN_WIDTH/2.0;
double bottom = -(double)WIN_HEIGHT/2.0;
double top = (double)WIN_HEIGHT/2.0;
float scale = 0.005;
glOrtho(left*scale*(m_zoom+60.0), right*scale*(m_zoom+60.0), bottom*scale*(m_zoom+60.0), top*scale*(m_zoom+60.0), -10000.0, 10000.0);
gluLookAt(0.0, 0.0, 200.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
else
{
gluPerspective(45.0, aspect, 0.1, 10000.0);
gluLookAt(0.0, 0.0, 200.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


in perspective case... i use glTranslatef for zoom in and out...

guide me how can i make same zoom with both..

Advertisement
glTranslatef is not zoom. that is just moving the world..
Add your zoom to the gluPerspective pov, that should help.

Cheers

Lee

Code is Life
C/C++, ObjC Programmer, 3D Artist, Media Production

Website : www.leestripp.com
Skype : lee.stripp@bigpond.com
Gmail : leestripp@gmail.com

No I am not talking about gluPerspective.... I can zoom in and out with above function.. but I want that the model position should be the same when i switch one to another.
I am using glTranslatef on the object.. so i can zoom in and zoom out ...
I want the relationship between glortho and gluPerspective in which whatever i select i just see the effect of projection. but now at this time.. when i press the glOrtho the object moves little bit far but in perspective it moves to near .. it must be at same position. right?
You're not actually zooming in if you're using "Translatef", which is what Lee said. Do you know what the different parameters of gluLookAt do? To zoom in, you can move the eye point closer to the look at point.

I use this for "zooming in" on my system:

void zoomin()
{
int vx = mLookPoint[0] - mPosition[0];
int vy = mLookPoint[1] - mPosition[1];
int vz = mLookPoint[2] - mPosition[2];

mPosition[0] += vx * 0.01;
mPosition[1] += vy * 0.01;
mPosition[2] += vz * 0.01;
}


And then in my rendering call I have


gluPerspective(mPosition[0], mPosition[1], mPosition[2], mLookPoint[0], mLookPoint[1], mLookPoint[2], 0, 1, 0);


you'll probably want to check if you don't arrive 'at' the lookpoint though, as this'll leave you unable to zoom out or in. Changing the near and far plane using glPerspective might give a smoother transition from Ortho to Perspective, though I haven't tried that myself. You'd have to change the angle as well for that matter (e.g., it's pretty much equivalent to ortho if the angle is 0)
To do a perfect zoom I think you'd have to take the Near plane into account and/or the object itself, think how this works. glTranslatef I assume you call before everything else to zoom, but this only moves the world origin, Basically the camera which will mess up Orthographic projection in relation to you Perspective projection.

One is a Cube and one is a pyramid shape. keep at it man, you'll work it out.. Read up on how projections work.

Cheers

Lee

Code is Life
C/C++, ObjC Programmer, 3D Artist, Media Production

Website : www.leestripp.com
Skype : lee.stripp@bigpond.com
Gmail : leestripp@gmail.com

When moving the camera / eye-point closer into the scene you get something that looks like zooming due to the perspective foreshortening. As is already mentioned, this is not a "real" zoom. E.g. you move the clipping volume together with the camera, and hence geometry near to the camera may disappear while geometry far from the camera may pop up. And that this works at all in perspective mode only is already noticed.

Because depth of field is usually neglected anyway, I don't see a reason why zooming is not to be simulated simply by scaling the scene in the horizontal and vertical dimensions of the view space. I.e. if V denotes the view matrix computed like before (from gluLookAt or whatever), then prepending a scaling S to yield in a new view matrix like so
S( z, z, 1 ) * V
where z denotes the zoom factor should do the trick.

The above is independent of the mode of projection. The scaling S may, however, also be attached to the projection, because OpenGL prepends projection matrix P to the view matrix like so
P * ( S( z, z, 1 ) * V )
and due to associativity, that can be computed as
( P * S( z, z, 1 ) ) * V
as well. However, this is a question of optimization only. If the zoom is static, than attaching it to the projection matrix is advantageous. In the more likely situation that the zoom will change frequently, attaching it to the view matrix is more efficient.




You're not actually zooming in if you're using "Translatef", which is what Lee said. Do you know what the different parameters of gluLookAt do? To zoom in, you can move the eye point closer to the look at point.

I use this for "zooming in" on my system:

void zoomin()
{
int vx = mLookPoint[0] - mPosition[0];
int vy = mLookPoint[1] - mPosition[1];
int vz = mLookPoint[2] - mPosition[2];

mPosition[0] += vx * 0.01;
mPosition[1] += vy * 0.01;
mPosition[2] += vz * 0.01;
}


Moving the eye-point is actually a translation. Not only that, it is further a translation at the same stage in processing as the OP already does.


And then in my rendering call I have


gluPerspective(mPosition[0], mPosition[1], mPosition[2], mLookPoint[0], mLookPoint[1], mLookPoint[2], 0, 1, 0);


This is an incorrect combination of a routine name and a set of parameters. You probably mean gluLookAt instead of gluPerspective.
actually my function is working perfectly with both projections if you take individually. but the issue is that when i switch from gluPerspective to glOrtho the model move little far. not at the same position as in perspective view.
I don't why but at zoom factor = 60 the model keeps same position in both projections. In my observation, if the zoom factor in gluPerspective mode is 75 then it must be 45 in the glOrho. but if zoom factor 75 in gluPerspective then the model look bigger but in glOrtho the model moves far... but i want that whatever the situation is the model must be at same zoom level when i press swich mode from gluPers to glOrtho OR glOrtho to gluPerspective.

I need a relationship between both projections, by using that i can have what i want. means how must i need to scale in glOrtho that i can achieve same zoom as in gluPerspective.

When moving the camera / eye-point closer into the scene you get something that looks like zooming due to the perspective foreshortening. As is already mentioned, this is not a "real" zoom. E.g. you move the clipping volume together with the camera, and hence geometry near to the camera may disappear while geometry far from the camera may pop up. And that this works at all in perspective mode only is already noticed.

Because depth of field is usually neglected anyway, I don't see a reason why zooming is not to be simulated simply by scaling the scene in the horizontal and vertical dimensions of the view space. I.e. if V denotes the view matrix computed like before (from gluLookAt or whatever), then prepending a scaling S to yield in a new view matrix like so
S( z, z, 1 ) * V
where z denotes the zoom factor should do the trick.

The above is independent of the mode of projection. The scaling S may, however, also be attached to the projection, because OpenGL prepends projection matrix P to the view matrix like so
P * ( S( z, z, 1 ) * V )
and due to associativity, that can be computed as
( P * S( z, z, 1 ) ) * V
as well. However, this is a question of optimization only. If the zoom is static, than attaching it to the projection matrix is advantageous. In the more likely situation that the zoom will change frequently, attaching it to the view matrix is more efficient.



[quote name='sjaakiejj' timestamp='1330895683' post='4919263']
You're not actually zooming in if you're using "Translatef", which is what Lee said. Do you know what the different parameters of gluLookAt do? To zoom in, you can move the eye point closer to the look at point.

I use this for "zooming in" on my system:

void zoomin()
{
int vx = mLookPoint[0] - mPosition[0];
int vy = mLookPoint[1] - mPosition[1];
int vz = mLookPoint[2] - mPosition[2];

mPosition[0] += vx * 0.01;
mPosition[1] += vy * 0.01;
mPosition[2] += vz * 0.01;
}


Moving the eye-point is actually a translation. Not only that, it is further a translation at the same stage in processing as the OP already does.
[/quote]
Isn't the concept of "zooming in" is itself a translation of the eye-point in the real world? I suppose scaling the scene is a reasonable approximation of the concept as well. The reason I advice gluLookAt for this operation is because it guarantees correct translation of all the objects in the scene, whereas it's easy to go wrong with glTranslate.



And then in my rendering call I have

gluPerspective(mPosition[0], mPosition[1], mPosition[2], mLookPoint[0], mLookPoint[1], mLookPoint[2], 0, 1, 0);


This is an incorrect combination of a routine name and a set of parameters. You probably mean gluLookAt instead of gluPerspective.
[/quote]
Yeah, that should be gluLookAt, not gluPerspective smile.png

Isn't the concept of "zooming in" is itself a translation of the eye-point in the real world? I suppose scaling the scene is a reasonable approximation of the concept as well. The reason I advice gluLookAt for this operation is because it guarantees correct translation of all the objects in the scene, whereas it's easy to go wrong with glTranslate.

Zooming is when you change the field of view. If you have a camera, zooming in or out is when you increase or decrease the focal length to get a narrower or wider angled shot of your object. The reason objects appear larger when you zoom in is because you narrow the field of view so that the object effectively occupies a larger portion of the view volume.

You don't move the camera closer to or further away from the object you're taking a photo of. Your translation method makes the zoom direction dependent; you can only zoom in the direction the camera is facing at the time you do the zoom. If you, after zooming in, you face the camera in the opposite direction, you have zoomed out because you are further away from those ojects, and if you face it perpendicular to the direction of translation, you have a sideways translation instead of a zoom.

[quote name='sjaakiejj' timestamp='1330942122' post='4919405']
Isn't the concept of "zooming in" is itself a translation of the eye-point in the real world? I suppose scaling the scene is a reasonable approximation of the concept as well. The reason I advice gluLookAt for this operation is because it guarantees correct translation of all the objects in the scene, whereas it's easy to go wrong with glTranslate.

Zooming is when you change the field of view. If you have a camera, zooming in or out is when you increase or decrease the focal length to get a narrower or wider angled shot of your object. The reason objects appear larger when you zoom in is because you narrow the field of view so that the object effectively occupies a larger portion of the view volume.

You don't move the camera closer to or further away from the object you're taking a photo of. Your translation method makes the zoom direction dependent; you can only zoom in the direction the camera is facing at the time you do the zoom. If you, after zooming in, you face the camera in the opposite direction, you have zoomed out because you are further away from those ojects, and if you face it perpendicular to the direction of translation, you have a sideways translation instead of a zoom.
[/quote]

Got it. My analogy of the concept was off a bit, and I was taking "zooming in" to be a non-mechanical concept, and the only way I could think of enlarging an object from that standpoint was by translation :)

This topic is closed to new replies.

Advertisement