Skip to main content
GameDev.net gamedev.net
🔒 Locked

Modelview/Projection matrices for basic mapping?

Started by SSNTails Feb 9, 2010 at 8:24 AM 0 replies 400+ views
Original Post
SSNTails
SSNTails
I'm working on a basic mapping program (kind of like Google Maps but a billion times simpler) using OpenGL. I have given the user the capability to pan and zoom. However, I'm not sure how to properly set up the modelview and projection matrices to handle this. I've been able to get panning working, but when I zoom, it scales the map from 0,0 instead of from the center of your current view. Any help on how to set up the matrices would be much appreciated, thanks!

// basex/basey = initial translation offset
// basescale = initial scale factor

            glViewport(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width, ClientRectangle.Height);
            glMatrixMode(gl.GL_MODELVIEW);
            glLoadIdentity();
            glMatrixMode(gl.GL_PROJECTION);
            glLoadIdentity();
            glOrthof(0, ClientSize.Width, 0, ClientSize.Height, 1.0f, -1.0f);
            glTranslatef(basex + xpos, basex + ypos, 0.0f); // This works!
            glScalef(basescale * xscale, basescale * yscale, 1.0f); // Oh no!


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.