Results 1 to 5 of 5

Thread: Change OpenGL coordinate system?

  1. #1
    Join Date
    Jan 2008
    Location
    Whenever the food is.
    Beans
    1,203
    Distro
    Kubuntu

    Change OpenGL coordinate system?

    I don't like the retarded 3D coordinate system of OpenGL. I never get used to it.

    I want to change it to like this:


    In the picture, Z gets larger at near, and XY coords are similar to 2D, like in GIMP.

    But I still want to keep 3d perspective and depth testing. How is this done?


    And I also want to make the units smaller, like 50.0 matching ~50-60 pixels.

    With default settings, 50.0 will be far outside screen.
    Last edited by crazyfuturamanoob; February 7th, 2009 at 06:46 PM.
    Keyboard not found!

    Press any key to continue...

  2. #2

    Re: Change OpenGL coordinate system?

    Quote Originally Posted by crazyfuturamanoob View Post
    I don't like the retarded 3D coordinate system of OpenGL. I never get used to it.

    I want to change it to like this:


    In the picture, Z gets larger at near, and XY coords are similar to 2D, like in GIMP.

    But I still want to keep 3d perspective and depth testing. How is this done?


    And I also want to make the units smaller, like 50.0 matching ~50-60 pixels.

    With default settings, 50.0 will be far outside screen.
    Invert the Y and Z acsiss of your coordinate system before passing to OpenGL.

    It is not possible to make the coordinates equal to some pixel value unless you are using an orthographic projection, in which case you can:

    Code:
    	float proj_bot = 0 - (screen_res.Y / 2);
    	float proj_top = 0 + (screen_res.Y / 2);
    	float proj_lef = 0 - (screen_res.X / 2);
    	float proj_rig = 0 + (screen_res.X / 2);
    
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    
    	glOrtho(proj_lef, proj_rig, proj_bot, proj_top, 0.1, 200.0);
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    im dyslexic, please don't comment on my spelling
    blender 3d artist, visit my portfolio
    Quad-Ren, Open source, resolution independent 2D graphics engine
    Screen space is a precious resource, don't waste it

  3. #3
    Join Date
    Jan 2008
    Location
    Whenever the food is.
    Beans
    1,203
    Distro
    Kubuntu

    Re: Change OpenGL coordinate system?

    Quote Originally Posted by hessiess View Post
    Invert the Y and Z acsiss of your coordinate system before passing to OpenGL.
    Is it possible to inverse them with gl translate/rotate/scale functions or viewport/matrix/camera settings?
    Keyboard not found!

    Press any key to continue...

  4. #4

    Re: Change OpenGL coordinate system?

    Quote Originally Posted by crazyfuturamanoob View Post
    Is it possible to inverse them with gl translate/rotate/scale functions or viewport/matrix/camera settings?
    You should be able to scale to -1 along the Y and Z assess. Though I was thinking more along the lines of calculating:

    vertex. y = 0 - (vertex.y * 2)
    vertex.z = 0 - (vertex.z * 2)

    right before you pass the veracities to OpenGL, though both methods will also invert the face vertex order, so you may end up with all the polygon normals pointing the wrong way.
    im dyslexic, please don't comment on my spelling
    blender 3d artist, visit my portfolio
    Quad-Ren, Open source, resolution independent 2D graphics engine
    Screen space is a precious resource, don't waste it

  5. #5
    Join Date
    Jan 2008
    Location
    Whenever the food is.
    Beans
    1,203
    Distro
    Kubuntu

    Re: Change OpenGL coordinate system?

    I was messing up with projection code and found this working:
    Code:
    glRotatef( 180.0, 0, 1, 0 );
    It does exactly what I want, with minimal work.

    Edit: Doesn't seem to work correctly.
    Edit2: Works with this:*
    Code:
    glScalef( -1, 1, 1 );

    And the scale of units can be changed by translating away:
    Code:
    glTranslatef( 0, 0, 125 );
    Last edited by crazyfuturamanoob; February 7th, 2009 at 08:35 PM.
    Keyboard not found!

    Press any key to continue...

Bookmarks

Posting Permissions

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