Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
nobody seems to understand my code.
sorry, because I post new questions while no one has answered the question before
I have read about gluUnProject Nehe lession 13 but I do not understand.
giatuan asked about the mouse in OpenGL.
Is Z depth?
I understand Z points out of the screen towards me
How can I get value Z mouse?
suppose I drew three axes x, y, z
My purpose is to draw polygon in 3D
help me
Posted
Updated 8-Jul-11 19:35pm
v2
Comments
harish85 9-Jul-11 2:13am    
Use glReadPixels to get depth...Can you post some code?

1 solution

See if this helps you - Googled
http://www.idevgames.com/forums/thread-6400.html[^]

Check this for code -

http://nehe.gamedev.net/data/articles/article.asp?article=13[^]

I am copying the code from that link what you need, you are converting mouse (X,Y)
points to a space(X,Y,Z) GL coordinates -

CVector3 GetOGLPos(int x, int y)
{
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
winX = (float)x;
winY = (float)viewport[3] - (float)y;
glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
return CVector3(posX, posY, posZ);
}

Hope this helps...
 
Share this answer
 
Comments
Phuong_ 13-Jul-11 0:43am    
thanks you.
Sorry,I late.
code then return x, y, z.toi will try it and reply you soon
Phuong_ 15-Jul-11 6:41am    
I'm pretty busy.
little time to rest.
I can only take the time to Develop
I tried your code.
it is good code.
but there is a problem.
if you rotate the camera (angle view), the xmouse, ymouse would like?
It would be wrong?
I'm trying to use Form application C++
in win32, I can use WM_MOUSEDOWN.
but I can put GetOGLPos where?
and how to detect a point, by code that face?
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900