PDA

View Full Version : gluUnProject



guju
06-05-2002, 11:51 PM
Hi there!
I want to find the next vertex with gluUnProject. I made the following code:
glGetDoublev(GL_MODELVIEW_MATRIX,modelmatrix);
glGetDoublev(GL_PROJECTION_MATRIX,projectionmatrix );
glGetIntegerv(GL_VIEWPORT,viewport);
glReadBuffer(GL_BACK);
glReadPixels((GLdouble) xRot_old, (GLdouble) (viewport[3]-yRot_old-1), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fWindowZ);
workproject=gluUnProject ((GLdouble) xRot_old, (GLdouble) (viewport[3]-yRot_old-1), fWindowZ, modelmatrix,projectionmatrix,viewport, &winX, &winY, &winZ);
if (workproject){
for (int index=0;index<numVertices;index++){
distance = sqrt(sqr(vertices[index*3 ]-winX)+sqr(vertices[index*3+1]-winY)+sqr(vertices[index*3+2]-winZ));
if(distance < minDist){
minDist = distance;
minIndex = index;
}
}
But i get for the winX bad Values. Whats rong with it?
Juergen