Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Inncorrect 3D ray created when clicking on the extreams of window?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013

    Inncorrect 3D ray created when clicking on the extreams of window?

    I have run into a bug that I am not sure how to fix. When I click on the window the point in 3D space does not map directly onto the click in the x-axis of the actual window. The discrepancy between the clicked point and the actual creation of the ray in 3D space increases proportionally as you get farther and farther from the middle of the x-axis in the window. The y-axis works fine, it is just the x-axis.

    Here is a picture of squares being created in 3D space where I click the mouse. I clicked only on the edges and moved around the window. (some squares look like hexagons because the camera angle is pointed down, but that is not important, the gap on the left and right is)

    Here is the code I used to create the ray in 3D space from a click in the window:

    GLfloat window_height = 800;
    GLfloat window_width = 800;

    void proccess_Mouse(int button, int state, int x, int y) {
    gluPerspective(camera->getAngle(), window_height / window_width, viewPlane_close, viewPlane_far);

    gluLookAt(camera->getIndex_position(0), camera->getIndex_position(1), camera->getIndex_position(2),
    camera->getIndex_looking(0), camera->getIndex_looking(1), camera->getIndex_looking(2),
    0, -1, 0);

    // matrix information
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];

    GLfloat winX, winY; // clicked coords on the screen
    GLdouble near_x, near_y, near_z; // position of the mouse on the near view plane
    GLdouble far_x, far_y, far_z; // position of the mouse on the far view plane

    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetIntegerv(GL_VIEWPORT, viewport);

    winX = (float)x;
    winY = (float)viewport[3] - (float)y; // window height - click position

    gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &near_x, &near_y, &near_z);
    gluUnProject(winX, winY, 1.0, modelview, projection, viewport, &far_x, &far_y, &far_z);

    Vector3f* near = new Vector3f(near_x, near_y, near_z);
    Vector3f* far = new Vector3f(far_x, far_y, far_z);


    I believe that I have missed something, or forgot something, but I don't see it. Any ideas?
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	TWLaJ6v.jpg 
Views:	347 
Size:	11.0 KB 
ID:	1056  

Tags for this Thread

Posting Permissions

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