Home > Back-end >  Opengl mouse for 3 d coordinate
Opengl mouse for 3 d coordinate

Time:12-09


If (event - & gt; Buttons () & amp; Qt: : RightButton)//the right-click
{

GlMatrixMode (GL_PROJECTION);
glLoadIdentity();
//glFrustum (0, 0, 0, 0, 0.8, 0.4);
GlOrtho (25, 25, 25, 25, 20, 20).
//glFrustum (1, 1, 1, 1, 0.2, 35).//near and far match your triangle Z short

GluLookAt (0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
Double modelview [16], the projection [16].
POINT iScreen;
Int viewport [4];
Float x=the event - & gt; Pos (). The rx ();
Float y=the event - & gt; The pos () ry ();
GLfloat z=0;
Double winx, winy, winz;
QDebug (" Window coords are (% d, % d) \ n ", x, y);
/* Read the the projection, the modelview and viewport matrices using the glGet functions provides. */
GlGetIntegerv (GL_VIEWPORT, viewport);//get perspective matrix
GlGetDoublev (GL_MODELVIEW_MATRIX modelview);//observation matrix
GlGetDoublev (GL_PROJECTION_MATRIX, the projection);//get the projection matrix
//: : GetCursorPos (& amp; IScreen);
//Read the window z value from the z - buffer
GlReadBuffer (GL_FRONT);
GlReadPixels (x, viewport [3] - y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, & amp; Z);


//Use the gluUnProject to get the world co - ordinates of
//the point the user clicked the and save in objx, objy, objz.
GluUnProject (x, viewport [3] - y, z, modelview, the projection, the viewport, & amp; Objx, & amp; Objy, & amp; Objz);
QDebug (" World coords at z=%. 1 f are (% % 3 f, 3 f, %, 3 f) "\ n, z, objx, objy, objz);

The update ();
Why do I get the coordinates of the z is the same

CodePudding user response:


Specializing in the 2 d - before & gt; 3 d mouse to pick up,
3 d - & gt; 2 d display such as bulletin board

CodePudding user response:

Can you teach me how should I change?
  • Related