Archived

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

glJunkie

picking / line-plane intersection

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:
http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/glu/unproject.html


NAME
gluUnProject - map window coordinates to object coordinates


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


PARAMETERS
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.

DESCRIPTION
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
failure.

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