Skip to main content
gamedev.net
🔒 Locked

Ray Picking

Started by stu_pb 2 replies 800+ views
Original Post
stu_pb
stu_pb
Does anyone have a link to a good ray-picking tutorial? Thanks in advance. I should probably be working now...
I should probably be working now...
Ataru
Ataru
Well, I don't have a link, but here's basically what you do.


GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];

glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);

GLint realy;

double fX,fY,fZ;
double tX,tY,tZ;

realy = viewport[3] - (SCREENY - (GLint)RmouseY) - 1;

gluUnProject((GLdouble)RmouseX, (GLdouble)realy, 0.0, mvmatrix, projmatrix, viewport,
&fX, &fY, &fZ);
gluUnProject((GLdouble)RmouseX, (GLdouble)realy, 1.0, mvmatrix, projmatrix, viewport,
&tX[0], &tY[1], &tZ[2]);


Now intersect the ray defined by fX,fY,fZ -> tX,tY,tZ with your objects and if there is an intersection, select.

[edited by - ataru on March 19, 2003 4:59:34 PM]
stu_pb
stu_pb
Thanks, I''ll give it a try

I should probably be working now...
I should probably be working now...
Ataru
Ataru
Check the code again if you copied it, there was a small mistake I corrected.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.