Results 1 to 8 of 8

Thread: Ortho and Perspective

  1. #1
    Member Contributor
    Join Date
    Oct 2006
    Posts
    83

    Ortho and Perspective

    Does anybody know of some simple tutorial and/or code that allows the user to switch back and forth (on the same Model) between Perspective and Orthogonal. I am fairly new to OpenGL and so don't know all the particulars, however any help would be great.

    Thanks in advance.

  2. #2
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Ortho and Perspective

    May I ask why would you want it?

    The simplest way is just set up the matrix you need prior to rendering a particular part of the scene. There should be no performance hit if you jus treset the matrix several times every frame.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: Ortho and Perspective

    Does anybody know of some simple tutorial and/or code that allows the user to switch back and forth (on the same Model) between Perspective and Orthogonal.
    I don't know if there are any tutorials on it. Most tutorials tend to be focused pretty specifically on one or the other.

    In general, this is the sort of thing that if you don't have an intimate grasp of how the two kinds of projection matrices work, you need to actually try stuff and see how it breaks/doesn't work, then ask a specific about why it broke like that.

    May I ask why would you want it?
    For a model viewer, maybe? And that's just the first thing that jumped off the top of my head.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2007
    Location
    sweden
    Posts
    1

    Re: Ortho and Perspective

    Originally posted by Zengar:
    May I ask why would you want it?

    The simplest way is just set up the matrix you need prior to rendering a particular part of the scene. There should be no performance hit if you jus treset the matrix several times every frame.
    Zengar: What does performance have to do with this?

    Actualy i have the same problem rendering transformation gizmos in my editor. My aproach is to scale the gizmo by the distance to the camera to make it look the same no mater the camera_z_position. But it would be alot nicer if the gizmos could be rendered in ortho mode like a on screen hud.

  5. #5
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Ortho and Perspective

    Why not something like this?

    Code :
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       glFrustum(-w, w, -h, h, near, far);
       DrawScene();
     
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       glOrtho(-w, 2, -h, h, near, far);
       DrawGizmos();

  6. #6
    Member Contributor
    Join Date
    Nov 2006
    Location
    Peru
    Posts
    95

    Re: Ortho and Perspective

    Zengar is right.
    Also you need a flag, lets say "char projection_mode", and every time you detect an event just change it.
    Also you have to know that most window system tell you specify Projection matrix inside the callback windowsResized(). The coordinates for the frustrum and other parameters, like zoom, must be visible for this function and also for the eventhandler.

    Bye!

  7. #7
    Member Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Ortho and Perspective

    Thanks for all the suggestions. I will give it a try and see what happens.

  8. #8
    Member Contributor
    Join Date
    Oct 2006
    Posts
    83

    Re: Ortho and Perspective

    I still keep having issues with the ortho and perspective views. The major problem is that the views keep getting clipped in the front. Can someone take a look at the following code and tell me if there is something obvious I am overlooking?

    Code :
    if (isPerspec) {
      gl.glViewport(0, 0, width, height);
      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      float aspect = (float)width/(float)height;
      glu.gluPerspective(45, aspect, 1, 1000);
      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();
      drawModel();
    else {
      gl.glViewport(0, 0, width, height);
      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      gl.glOrtho(-width, width, -height, height, 1, 1000);
      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();
      drawModel();
    }
    The 1 and 1000 for the Z-Near and Z-Far respectively I know encompass the Model. I just hope that it is something obvious.

    Thanks in advance.

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2015, 07:35 AM
  2. ortho + perspective + ortho
    By mithun_daa in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-09-2004, 07:54 AM
  3. Perspective vs. Ortho
    By stout in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-26-2003, 12:05 AM
  4. perspective to ortho?
    By c_olin in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-08-2003, 12:53 PM
  5. changing from perspective to ortho back to perspective
    By crappy04 in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-19-2001, 09:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean