PDA

View Full Version : y coordinate flipped opposite of windows for a good reason?

AE
04-15-2006, 06:29 PM
Right now I'm working on a game and we have the coordinates flipped so that they are from the upper-left corner instead of opengl's lower-left.

Right now I have a Ken sprite from Street Fighter 2 walking accross the board with all of the animated sprites of him walking from the game. The problem I'm having (I assume because the coords are flipped) is that Ken does a little hop when he walks and also crouches down a little and that causes walking to look un-natural because his feet go below the level plane.

If I were to draw with Opengl's default coordinate system, would that solve this issue? In other words, would I draw from y from the bottom of the sprite rather than the top?

http://www.merge3d.com/forum/viewtopic.php?p=8918#8918
to see exactly what I'm talking about.

AE
04-17-2006, 08:14 PM
Should I clarify more?

songho
04-17-2006, 09:23 PM
I believe that the way (bottom-left origin in 2D) is the simplest and effortless method in order to switch between 3D and 2D. You don't need a specific coordinates system or matrix for only 2D. These are shared on both 2D and 3D, and z-coords are simply set to 0 for 2D.

How did you flip the orientation? Did you use glPixelZoom(1,-1)? You can draw an image from top to bottom with this function, but you have to set the raster position to the top of the image.
==song==

AE
04-19-2006, 08:33 AM
All I did was switch around the glOrtho top and bottom coords and everything works just as I expected. Thanks!

AE
05-03-2006, 11:25 AM
//glOrtho params are: left right bottom top
//I have them switched to make origin bottom-left:
glOrtho(left, right, top, bottom, 0, 1);
//rather than upper-left:
glOrtho(left, right, bottom, top, 0, 1);

Is this the wrong way to flip coordinates? Because everything is severely messed up when the origin is at the bottom-left for some graphics cards (ATI I think). On most it seems to work fine though.

What is the correct way to flip coordinates?

AE
05-07-2006, 07:55 PM
Anyone know?

songho
05-07-2006, 09:23 PM
AE,
Leave the projection matrix as it is, and try to modify the modelview matrix instead. In order to flip Y-axis, use the following for viewing matrix;

[1 0 0 0]
[0 -1 0 0]
[0 0 1 0]
[0 0 0 1]The second row, (0,-1,0,0) means that the up vector is now pointing to negative Y-axis, so the Y value of a vertex will be flipped (negated). However, if you are using glDrawPixels() to draw 2D images, use glPixelZoom() as I mentioned earlier.
==song==

AE
07-12-2006, 12:06 PM
I've been looking online for what function(s) to call to set the viewing matrix. All I can come up with is gluLookAt. But it only takes 9 parameters. The example above takes 16.

How do I do that?

Overmind
07-12-2006, 01:18 PM
It's a matrix, you have to put it in glMultMatrix (or glLoadMatrix).

But for this particular matrix, you can also use glScalef(1.0, -1.0, 1.0);