Results 1 to 5 of 5

Thread: Tiny difference in Z coordinate

  1. #1
    Member Contributor
    Join Date
    Oct 2011
    Posts
    72

    Tiny difference in Z coordinate

    Hi there,

    I'm doing a project using the perspective projection. I've a camera located at (20, 20, 20) looking at (0, 0, 0).

    When I try to get the coordinates in the nearest plane using gluUnproject(mouseX, height - mouseY, 0, ...) I get (someX, someY, 19.5).

    The question is why I get in Z some slightly difference? I was expecting to get 20 in Z because it must be the nearest plane.

    Can someone explain me why I get such difference?

    Thanks.

  2. #2
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: Tiny difference in Z coordinate

    You'll probably need to take the near plane distance into account, if you're looking for the world position coinciding with the camera position, say, with a winz of 0.

  3. #3
    Member Contributor
    Join Date
    Oct 2011
    Posts
    72

    Re: Tiny difference in Z coordinate

    You'll probably need to take the near plane distance into account, if you're looking for the world position coinciding with the camera position, say, with a winz of 0.
    Yes, that's what I'm doing; the third parameter in gluUnproject is zero (WinZ) in the example I posted before

    Code :
    gluUnproject(mouseX, height - mouseY, 0, ...)

    But I'm getting some difference in Z. It looks like the camera is a little behind the frustrum but I don't know if it's ok.

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Tiny difference in Z coordinate

    How do you set up modelview and projection matrices?
    gluUnproject returns coordinates in object space. You may have to transform again these coordinates by the modelview matrix to get coordinates in eye space.

  5. #5
    Member Contributor
    Join Date
    Oct 2011
    Posts
    72

    Re: Tiny difference in Z coordinate

    Hi dletozeun,

    Here's my code

    Code :
    // Set Viewport to window dimensions
    Gl.glViewport(0, 0, width, height);
    // Reset projection matrix stack
    Gl.glMatrixMode(Gl.GL_PROJECTION);
    glLoadIdentity();
    // Establish the projection
    if (width > height)
       gluPerspective(fovY * height / width, width / height, nearPlane, farPlane);
    else
       gluPerspective(fovY, width / height, nearPlane, farPlane);
    // Reset Model view matrix stack
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    // Set the camera's position
    gluLookAt(30, 20, 20, 0, 0, 0, 0, 0, 1)

    Thanks in advance

Similar Threads

  1. Tiny application, 0 FPS bug with nVidia drivers
    By zsolt.ero in forum OpenGL: Drivers
    Replies: 1
    Last Post: 08-03-2012, 04:47 AM
  2. tiny surface visualization problem
    By mckkv in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-25-2005, 02:37 AM
  3. tiny stupid NV_vertex_program doesn't work :(
    By JanHH in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 05-25-2004, 03:50 PM
  4. Switched to glortho, now textures are TINY!? Help!
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-05-2002, 03:59 AM
  5. Tiny
    By Blza in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-11-2000, 09:10 PM

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