Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: y coordinate flipped opposite of windows for a good reason?

  1. #1
    Intern Newbie
    Join Date
    Mar 2005
    Posts
    40

    y coordinate flipped opposite of windows for a good reason?

    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?

    You can download the source and binary here:
    http://www.merge3d.com/forum/viewtopic.php?p=8918#8918
    to see exactly what I'm talking about.

  2. #2
    Intern Newbie
    Join Date
    Mar 2005
    Posts
    40

    Re: y coordinate flipped opposite of windows for a good reason?

    Should I clarify more?

  3. #3
    Junior Member Regular Contributor songho's Avatar
    Join Date
    May 2003
    Location
    Canada
    Posts
    242

    Re: y coordinate flipped opposite of windows for a good reason?

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

  4. #4
    Intern Newbie
    Join Date
    Mar 2005
    Posts
    40

    Re: y coordinate flipped opposite of windows for a good reason?

    All I did was switch around the glOrtho top and bottom coords and everything works just as I expected. Thanks!

  5. #5
    Intern Newbie
    Join Date
    Mar 2005
    Posts
    40

    Re: y coordinate flipped opposite of windows for a good reason?

    //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?

  6. #6
    Intern Newbie
    Join Date
    Mar 2005
    Posts
    40

    Re: y coordinate flipped opposite of windows for a good reason?

    Anyone know?

  7. #7
    Junior Member Regular Contributor songho's Avatar
    Join Date
    May 2003
    Location
    Canada
    Posts
    242

    Re: y coordinate flipped opposite of windows for a good reason?

    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;
    Code :
    [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==

  8. #8
    Intern Newbie
    Join Date
    Mar 2005
    Posts
    40

    Re: y coordinate flipped opposite of windows for a good reason?

    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?

  9. #9
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: y coordinate flipped opposite of windows for a good reason?

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •