Global coordination issues with gluUnProject ()

I am currently invoking Trace (method below) from the game loop. Right now, all I'm trying to do is get the world coordinates from the on-screen mouse so that I can move objects around in world space. The values ​​that I get from gluUnProject, however; puzzling me.

I used glReadPixel (...) to get the value of Z, but little has changed in the object I was drawing, and the resulting vector turned out to be the same as the location of my cameras (except for tiny decimal changes due to mouse movement) so I decided to get rid of the call and replace the value of Z with 1.

My question is: does the following code look right? Each example that I saw in this example is either identical or very similar, but I can’t show the correct results, even if I block the Y axis. If the code is correct, then I assume that I just don’t use the resulting vector correctly. Should I not draw an object or point directly with the resulting vector, or do I need to do something with it, for example normalize?

The current rendering mode is GL_RENDER, and I use glFrustum with a value of NearZ 1 and a value of FarZ 2048 to create a perspective. There is also a series of viewports created with scissors in size and width 512x768 and located in each corner of the window 1024x768. Trace (...) is called between the visualization of the upper left viewport and is the only perspective projection, while other viewports are spelling. FOV is set to 45.

void VideoWindow::Trace(int cursorX, int cursorY)
{
    double objX, objY, objZ;//holder for world coordinates
    GLint view[4];//viewport dimensions+pos
    GLdouble  p[16];//projection matrix
    GLdouble  m[16];//modelview matrix
    GLdouble z;//Z-Buffer Value?

    glGetDoublev (GL_MODELVIEW_MATRIX, m);
    glGetDoublev (GL_PROJECTION_MATRIX,p);
    glGetIntegerv( GL_VIEWPORT, view );

    //view[3]-cursorY = conversion from upper left (0,0) to lower left (0,0)
    //Unproject 2D Screen coordinates into wonderful world coordinates
    gluUnProject(cursorX, view[3]-cursorY, 1, m, p, view, &objX, &objY, &objZ);

    //Do something useful here???
}

Any ideas?

: winZ 0,5 1, , , - . , view [3] 384, , , 768 ( ), 100%. , 3D- , , 3D- .

+3
2

winz gluUnproject , "" . , [0, 1].

tutorials, NeHes, z , "" , , gluUnproject , .

, winz 0,5 - ( 0 1, , , ) :

gluUnProject(cursorX, view[3]-cursorY, 0.5, m, p, view, &objX, &objY, &objZ);
//Do something useful here???
glPointSize(10);
glBegin(GL_POINTS);
glColor3f(1, 0, 0);
glVertex3f(objX, objY, objZ);
glEnd();

blob ( , , , ).

+4

, gluUnProject - z , - , , ? , z .

0

Source: https://habr.com/ru/post/1724526/