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 10 of 10

Thread: relationship between mouse position and coordinate and normal

  1. #1
    Intern Newbie
    Join Date
    Sep 2002
    Posts
    38

    relationship between mouse position and coordinate and normal

    I want to do something like this:
    when the mouse moves upon a model rendered with openGL, the x,y,x coordinates and normal of the point on the model should be displayed. That is, how to convert from mouse position on the screen to the x,y,x coordinates and how to get the normal of this point?
    Thanks for your direction in advance.

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Italy
    Posts
    21

    Re: relationship between mouse position and coordinate and normal

    Ehehe... try to use glUnProject to retrieve mouse 3d coordinates

  3. #3
    Intern Newbie
    Join Date
    Sep 2002
    Posts
    38

    Re: relationship between mouse position and coordinate and normal

    Thanks!

  4. #4
    Intern Newbie
    Join Date
    Sep 2002
    Posts
    38

    Re: relationship between mouse position and coordinate and normal

    And how about the normal?

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Posts
    748

    Re: relationship between mouse position and coordinate and normal

    With gluUnProject you can get the position of your pixel in the world, and create a ray from your view position to this pixel. Now you can cast this ray with your world geometry to determine which triangle is hit, and get the intersection point and normal. All you need is a fast ray/triangle intersection function.

    Y.

  6. #6
    Intern Newbie
    Join Date
    Sep 2002
    Posts
    38

    Re: relationship between mouse position and coordinate and normal

    Any other ideas,plz?

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Melbourne,Victoria,Australia
    Posts
    767

    Re: relationship between mouse position and coordinate and normal

    Originally posted by ljz:
    Any other ideas,plz?
    Oh dear, another Shanedudddy...

    Ysaneya has given you the best answer. Implementing it will teach you a great deal about 3d intersections/transformations that will prove invaluable with more advanced 3d development.

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Edgewood, Maryland USA
    Posts
    2

    Re: relationship between mouse position and coordinate and normal

    And don't forget that the Mouse y Corrdinate muss be inverted,since the OpenGL uses the left bottom corner and not the left upper.

  9. #9
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: relationship between mouse position and coordinate and normal

    Originally posted by Buffalo:
    And don't forget that the Mouse y Corrdinate muss be inverted,since the OpenGL uses the left bottom corner and not the left upper.
    It does if you say it does. You can always exhange top and bottom you provide to glFrustum or glOrtho or whatever else you use.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  10. #10
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Edgewood, Maryland USA
    Posts
    2

    Re: relationship between mouse position and coordinate and normal

    Thanks i dind't now that

Posting Permissions

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