Ray tracing question

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

Recommended Posts

I got the normalized direction of my ray like this:
VERTEX GetRay()
{
VERTEX P1,P2,direction;
double length=0;
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLint viewport[4];
GLdouble objx,objy,objz;

glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
glGetIntegerv(GL_VIEWPORT,viewport);

gluUnProject(mouse_x,
viewport[3] - mouse_y,
0,
modelMatrix,
projMatrix,
viewport,
&objx,
&objy,
&objz);

P1.x = objx;  P1.y = objy;  P1.z = objz;

gluUnProject(mouse_x,
viewport[3] - mouse_y,
1,
modelMatrix,
projMatrix,
viewport,
&objx,
&objy,
&objz);

P2.x = objx;  P2.y = objy;  P2.z = objz;
direction.x = P2.x - P1.x;
direction.y = P2.y - P1.y;
direction.z = P2.z - P1.z;

length = sqrt(direction.x*direction.x + direction.y*direction.y + direction.z*direction.z);

direction.x /= length;
direction.y /= length;
direction.z /= length;

return(direction);
}


I wanted to see the ray so I did this:
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
Camera.Look();
glLineWidth(5.0f);
glColor3f(1,1,1);
glBegin(GL_LINES);
glVertex3f(Camera.PositionX(), Camera.PositionY(), Camera.PositionZ() );
glVertex3f(Camera.PositionX() +  1000*GetRay().x,
Camera.PositionY() +  1000*GetRay().y,
Camera.PositionZ() +  1000*GetRay().z);
glEnd();
glLineWidth(1.0f);


But I didn't see any line? How do I get the line and did I calculate the ray correctly(camera + direction)? Thanks.

Share on other sites
I didn't look at the code at all, but keep in mind that if you try to render a picking ray from the point of view of the camera, it will only show up as a point (if it shows up at all). So this probably isn't the best way to test your picking function.

Share on other sites
Then how should I test it? (could someone check the code maybe?)
Thanks.

Share on other sites
Quote:
 Original post by daniel_i_lThen how should I test it?
One way is to set up a 'dummy' camera in addition to your 'actual' camera, and compute and draw the frustum for this camera. Then take the mouse position, use it to construct a pick ray given the parameters of the 'dummy' camera, and draw the ray (this is how I tested my picking code).

Share on other sites
Thanks, I have another question, after getting the direction (which I think is right) do I add it to the camera position to get the ray, the camera view position, or something else? - Shouldn't the view direction have something to do with it?
Thanks.

[Edited by - daniel_i_l on April 3, 2006 3:48:34 AM]

Share on other sites
I think I solved the problem! I was using gluLookAt and forgot to call it before getting the matrixes.
Thanks for the help!

1. 1
Rutin
19
2. 2
JoeJ
15
3. 3
4. 4
5. 5

• 23
• 20
• 11
• 13
• 17
• Forum Statistics

• Total Topics
631698
• Total Posts
3001771
×