Points Selection

Started by
14 comments, last by Flatus 16 years, 2 months ago
Thats the function I wanted to read pixels. Values winX and winY are correctly transfered from OnLButtonDown(UINT nFlags, CPoint point) funtion, but the output values objX and objY are far away from correct results. As I wrote before, after zoom, move or rotation is much worse.

GLdouble winX;
GLdouble winY;
GLdouble winZ;
GLdouble objX;
GLdouble objY;
GLdouble objZ;


GLdouble modelMatrix[16];
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
GLdouble projMatrix[16];
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
int viewport[4];
glViewport(0, 0, mx, my);
glGetIntegerv(GL_VIEWPORT,viewport);
winX = (float)point.x; //MousePosX
winY = (float)viewport[3] - (float)point.y;
glReadPixels( winX, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject(
winX,
winY,
winZ,
modelMatrix,
projMatrix,
viewport,
&objX,
&objY,
&objZ
);
Advertisement
...good idea oc2k1. Although that method will hit problems in complex picking scenarios such as group selections, for simpler problems like this one it's great. I'm sure I'll find a use for this myself. Thanks!

[Edited by - ElectricVoodoo on February 13, 2008 6:32:54 AM]
glSelectBuffer, glPushName(0), GL_SELECT are set as in exemple from link and coordinates are gluPickMatrix(xPos, viewport[3] - yPos, 1.0, 1.0, viewport); But I still get value zero in hits. Could be because of this glutSwapBuffers() ???
That's the function is use and get no hits:

void COpenGLControl::ProcessSelection(int xPos, int yPos)
{
const int BUFFER_LENGTH = 64;
GLuint selectBuff[BUFFER_LENGTH]={0};
GLint hits, viewport[4];
glSelectBuffer(BUFFER_LENGTH, selectBuff);
glGetIntegerv(GL_VIEWPORT, viewport);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
float PICK_REGION_SIZE = 20.0f;
//gluPickMatrix(xPos, viewport[3] - yPos, 1.0, 1.0, viewport);
gluPickMatrix(xPos, viewport[3] - yPos, PICK_REGION_SIZE, PICK_REGION_SIZE, viewport);
gluPerspective(35.0, mx / my, 0.01f, 2000.0f);
glMatrixMode(GL_MODELVIEW);
//glutSwapBuffers(); //when enable application crashes
oglDrawScene(); //my drawing function
glMatrixMode(GL_PROJECTION);
glPopMatrix();
hits = glRenderMode(GL_RENDER);
if(hits == 1)
{
AfxMessageBox("HIT");
MakeSelection(selectBuff[3]);
}
glMatrixMode(GL_MODELVIEW);
}
Certainly you should not swap buffers in selection mode. glutSwapBuffers is a framebuffer function and we have been rendering to our own selection buffer, not the frame buffer.

In your draw function you should move your glLoadName() calls to OUTSIDE the glBegin()...glEnd() blocks as I don't think they work inside these blocks.
For what it's worth, I have created modules for color picking and selection picking, and the speed differences are minimal. My app displays large amounts of primitives, so I would think the original poster would have the same results.

This topic is closed to new replies.

Advertisement