PDA

View Full Version : Selection with ray from mouse



elrick23
03-16-2002, 07:59 AM
Hello,

I just want to have a ray from the mouse ...
I use this:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

CVector_4D Ray;

GLint viewportCoords[4] = {0};
GLdouble modelMatrix[16] = {0};
GLdouble projMatrix[16] = {0};

//gluLookAt ...

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


double vecx, vecy, vecz;
gluUnProject(xmouse, viewportCoords[3] - ymouse, 0.0, modelMatrix, projMatrix, viewportCoords, &vecx, &vecy, &vecz);

double vecx2, vecy2, vecz2;
gluUnProject(xmouse, viewportCoords[3] - ymouse, 1.0, modelMatrix, projMatrix, viewportCoords, &vecx2, &vecy2, &vecz2);


Ray.x = vecx2 - vecx;
Ray.y = vecy2 - vecy;
Ray.z = vecz2 - vecz;


But it doesn't seams to work
Can you help me ? ;-)


Elrick

knackered
03-16-2002, 10:09 AM
Your code segment looks fine.
What is the return value of gluunproject?
What are the resultant values in your ray variables?

elrick23
03-16-2002, 10:18 AM
glUnProject return GL_TRUE two times ...

And the values of ray seems to be good ... but it work badly ...
One time, it work and if i move or turn the camera, it does'nt work ...


Maybe there's another way to have this ray ?
Another method ?


Elrick

knackered
03-16-2002, 11:37 AM
You haven't got your camera in the projection matrix, by any chance?