i have gone through all the topics posted related to gluUnproject, they did help me a lot but i am still having some problems. the x and y values i get are close, but not whatz desired. the z value is totally off. whenever i click at a different position the difference in the x and y values is very small(10-100) whereas the difference has to be in hunderds to thousands. herez some of my code (VB6):
Private Sub picOpengl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim tempz As GLfloat
Dim temp As Boolean
If Button = vbLeftButton And Check1.Value = Checked Then
intXPosition = (intWidth / 2) + X
intYPosition = (intHeight / 2) + Y
OpenGLRender
temp = gluUnProject(X, Y, -CDbl(sngZatXY), mvmatrix(0), projmatrix(0), viewport(0), wx, wy, wz)
MsgBox intXPosition & " " & intYPosition & " " & wx & " " & wy & " " & wz
End If
End Sub
the intXPosition and intYPosition are right, cause the way i have set my viewport in VB is that the mouse event returns values between -250 to 250 for X and - 300 to 300 for Y. passing a negative value for the ‘z’ parameter in gluUnproject gets the values closer to whats desired, if i send a +ve value, the values returned are totally off. another thing, im not sure if readpixels returns a values between 0-1 or the actual z value. if it returns between 0-1 then do i have to convert it to the actual value when i pass it thru gluunproject?
display routine :
glpushmatrix
translate…
rotate…
rotate…
translate…
glGetIntegerv glgViewport, viewport(0)
glGetDoublev glgModelViewMatrix, mvmatrix(0)
glGetDoublev glgProjectionMatrix, projmatrix(0)
glReadBuffer rbmBack
glReadPixels intXPosition, intYPosition, 1, 1, rpDepthComponent, pxlFloat, sngZatXY
most of the variables are global.
also my readpixels always returns 1.
[This message has been edited by mithun_daa (edited 12-29-2003).]