Jump to content
  • Advertisement
Sign in to follow this  
mark-w

orthograpic zoom

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a scene setup using orthographic projection. I want to support a zooming operation. I use glScale() to do the zoom, then glTranslate() to support panning. All I am drawing to screen is a single texture mapped quad. My problem is that glScale() is scaling the scene from the origin of my viewport, which looks funny. I want to scale from the center of the viewport so it looks like a true zoom. There must be some way I can apply another glTranslate() offset to the scene after scaling to make it look as if I am always zooming in on the center of the viewport, I just can't figure out how to do that. One feature of my app is that when the user moves the mouse over the quad I can display what pixel the mouse is over in the corresponding bitmap easily by just doing:
    int nActualPixX = (mouseLoc.x / zoom) - pan_x;
The desired scaling can be achieved if I ditch glScale() and use glOrtho() instead like:
glOrth(-viewportWidth * zoom,
        viewportWidth * zoom,
       -viewportHeight * zoom,
        viewportHeight * zoom,
       -1,1);
but then I lose my feature of being able to tell what pixel the mouse is over in the texture mapped quad since I'm not sure how glOrtho() is placing my stuff in the scene. Can anyone recommend how to finish this using either solution (glOrth() vs glScale()) Thanks

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
If I remember my 3d graphics math from the course I took, all you should need to do is translate the center of the quad you are rendering to 0,0,0.

This should scale the quad based on the center so it zooms, just remember to reverse the translation after the scale.

There is probably a better way to do this, though this is the one that comes to me off the top of my head. :)

Share this post


Link to post
Share on other sites
Please correct me if I'm wrong, but I thought when glScale() is called, everything drawn afterwards is scaled by that amount, so in my case all the vertices of the quad will just be multiplied by that amount really, there is no actual quad object to move to the origin for scaling:


void OnDraw()
{
glScale();
glTranslate();

glBegin();
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(256.0f, 0.0f, 0.0f);
glVertex3f(256.0f, 256.0f, 0.0f);
glVertex3f(0.0f, 256.0f, 0.0f);
glEnd();
}


I tried creating the quad about the origin, but that just gives the effect of scaling from the center of the quad, when I really want to make it look like I'm zooming in on the center of the viewport.

Share this post


Link to post
Share on other sites

I think the other guy had the right idea, just not quite right. So if I understand right, you have one quad, and pan_x and pan_y to indicate where on that quad the user is centered. In order to zoom on that location, you need to translate your scene by -pan_x and -pan_y. This will place the quad over the origin with your center point directly at 0, 0. Now do your scaling draw the quad. The last thing to do is to translate back to pan_x and pan_y. Experiment with that for a while and see if you can get it to work.

Jake

Share this post


Link to post
Share on other sites
Hi guys,

Yes I finally got it after I understood how this glOrtho() function works. I think I got the right offsets etc to get mapped back to my original pixel locations.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!