Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


picking / line-plane intersection

This topic is 6005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, Im using OpenGL to create a "boids" style flocking simulation. Im at the stage where I want to include functionality to let the user click an area of the screen and an object will appear on a plane (the ground) for the boids to dodge according to where the user clicked. My question: Is gluUnProject: http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/glu/unproject.html the way to go to calculate a "ray" from viewpoint to where the clicked point "is on" the far clip plane? This is related to a picking problem I think but Im totally new to it. I figure that once I can get the vector from view point (the position of the camera using gluLookAt) to far clip then all ill need is an algorithm to figure out where that ray intersects the plane (the ground) Can someeone please help me with this or point me to a tutorial or example? Id REALLY appreciate it. Many thanks, Tim.

Share this post

Link to post
Share on other sites
Hi everyone, can someeone please explain what is meant by the following description of the OpenGL function gluUnProject? Im confused about this - and would really appreciate some help. Thanks, Tim. PS: I got this description at:

gluUnProject - map window coordinates to object coordinates

GLint gluUnProject( GLdouble winX,
GLdouble winY,
GLdouble winZ,
const GLdouble *model,
const GLdouble *proj,
const GLint *view,
GLdouble* objX,
GLdouble* objY,
GLdouble* objZ )

winX, winY, winZ
Specify the window coordinates to be mapped.

model Specifies the modelview matrix (as from a
glGetDoublev call).

proj Specifies the projection matrix (as from a
glGetDoublev call).

view Specifies the viewport (as from a
glGetIntegerv call).

objX, objY, objZ
Returns the computed object coordinates.

gluUnProject maps the specified window coordinates into
object coordinates using model, proj, and view. The result
is stored in objX, objY, and objZ. A return value of GL_TRUE
indicates success; a return value of GL_FALSE indicates

To compute the coordinates (objX, objY, and objZ),
gluUnProject multiplies the normalized device coordinates by
the inverse of model*proj as follows:

| |
|_________________ |
( ) | view[2] - 1 |
| objX | | |
| objY | = INV(PM)|_________________ - 1 |
| | | view[3] |
| objZ | | 2(winZ) - 1 |
( W ) | |
( 1 )

INV() denotes matrix inversion. W is an unused variable,
included for consistent matrix notation.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!