Jump to content

  • Log In with Google      Sign In   
  • Create Account


zooming with glortho should be same as with glPerspective?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 luckyyyyyy   Members   -  Reputation: 144

Like
0Likes
Like

Posted 04 March 2012 - 06:45 AM

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..



Sponsor:

#2 Lee A. Stripp   Members   -  Reputation: 373

Like
0Likes
Like

Posted 04 March 2012 - 08:19 AM

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


#3 luckyyyyyy   Members   -  Reputation: 144

Like
0Likes
Like

Posted 04 March 2012 - 02:09 PM

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?

#4 sjaakiejj   Members   -  Reputation: 130

Like
0Likes
Like

Posted 04 March 2012 - 03:14 PM

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)

#5 Lee A. Stripp   Members   -  Reputation: 373

Like
0Likes
Like

Posted 04 March 2012 - 08:57 PM

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


#6 haegarr   Crossbones+   -  Reputation: 3750

Like
0Likes
Like

Posted 05 March 2012 - 02:03 AM

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.

#7 luckyyyyyy   Members   -  Reputation: 144

Like
0Likes
Like

Posted 05 March 2012 - 03:17 AM

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.

#8 sjaakiejj   Members   -  Reputation: 130

Like
0Likes
Like

Posted 05 March 2012 - 04:08 AM

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.

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.

Yeah, that should be gluLookAt, not gluPerspective Posted Image

#9 Brother Bob   Moderators   -  Reputation: 7781

Like
0Likes
Like

Posted 05 March 2012 - 04:35 AM

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.

#10 sjaakiejj   Members   -  Reputation: 130

Like
0Likes
Like

Posted 05 March 2012 - 04:38 AM


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.


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 :)

#11 Trienco   Crossbones+   -  Reputation: 2051

Like
0Likes
Like

Posted 05 March 2012 - 11:41 PM

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 Posted Image


Considering how orthogonal projection works you must realize that distance will not change how large the object appears, right? So as long as your object is perfectly centered, you can translate back and forth as much as you like without seeing any difference. Until the object gets clipped against the near and far plane.

If you want to zoom, just decrease your fov or limit your ortho projection to a smaller area. You don't run into clipping issues and it's a lot less messy.

You will still not find a simple relationship for perspective and ortho zoom without considering the objects distance to the camera in your calculation. Even if you find that matching set of zoom factors, where the object appears equally large in both projections... move it closer or farther away and your numbers won't work anymore.
f@dzhttp://festini.device-zero.de

#12 sjaakiejj   Members   -  Reputation: 130

Like
0Likes
Like

Posted 06 March 2012 - 06:21 AM


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 Posted Image


Considering how orthogonal projection works you must realize that distance will not change how large the object appears, right? So as long as your object is perfectly centered, you can translate back and forth as much as you like without seeing any difference. Until the object gets clipped against the near and far plane.

Yes, due to the fact the view frustrum is in fact a cube/rectangle (e.g. near and far plane are of equal size)

If you want to zoom, just decrease your fov or limit your ortho projection to a smaller area. You don't run into clipping issues and it's a lot less messy.

You will still not find a simple relationship for perspective and ortho zoom without considering the objects distance to the camera in your calculation. Even if you find that matching set of zoom factors, where the object appears equally large in both projections... move it closer or farther away and your numbers won't work anymore.

As mentioned before, I mainly looked at replacing the glTranslate function. As I never use Orthographic views myself, I didn't really think too much about what translation means in such a projection.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS