[gameprogrammer] Re: OpenGL and mouse click location
- From: iso8859-1 <iso8859-1@xxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Thu, 07 Apr 2005 14:08:56 +0200
I'll add in my answer as well :) In simple cases such as yours, it's
>sufficient to use gluUnProject()
>
>Stephane
>
Point View::mouseClickedOn(int mouseX, int mouseY) {
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)mouseX;
winY = (float)viewport[3] - (float)mouseY;
winZ = (float)-10.0f;
//glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
&winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport,
&posX, &posY, &posZ);
Point p;
p.y=posY;
p.x=posX;
return p;
}
I tried it with this code (modified from nehe) but I can't get it to
work. The width of a quadratic tile is 1.0f, the z-coordinate is -10.0f.
I only get weird coordinates with this code. Does anybody know how to do
it correctly?
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] perspective correction
- From: Szasz Pal
- References:
- [gameprogrammer] OpenGL and mouse click location
- From: tobias . langner
- [gameprogrammer] Re: OpenGL and mouse click location
- From: Stephane Marchesin
Other related posts:
- » [gameprogrammer] OpenGL and mouse click location
- » [gameprogrammer] OpenGL and mouse click location
- » [gameprogrammer] Re: OpenGL and mouse click location
- » [gameprogrammer] Re: OpenGL and mouse click location
- » [gameprogrammer] Re: OpenGL and mouse click location
- » [gameprogrammer] Re: OpenGL and mouse click location
- » [gameprogrammer] Re: OpenGL and mouse click location
- [gameprogrammer] perspective correction
- From: Szasz Pal
- [gameprogrammer] OpenGL and mouse click location
- From: tobias . langner
- [gameprogrammer] Re: OpenGL and mouse click location
- From: Stephane Marchesin