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.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky