Archived

This topic is now archived and is closed to further replies.

JeroenDierckx

picking problem

Recommended Posts

JeroenDierckx    122
Hi, I'm developing a 3D VE in QT, using OpenGL (for a school project). In the program, you can choose between several navigation methods, and some of them require you to pick an object in the scene. The picking is working fine, as long as the navigation method doesn't rotate the "camera". I can fe walk backward, strafe left/right, and picking works just fine. But as soon as I rotate, the picking gets screwed. It seems as if the scene drawed by the picking algorithm isn't affected by the rotations. Here is some code I use: drawing:
  // Clear OpenGL buffers

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // Apply the navigation

  if(m_navigation)
    m_navigation->applyGL();

  // Draw the scene

  m_scene->drawGL();
Picking at (x,y):
  // Clear OpenGL buffers

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // Apply the navigation

  if(m_navigation)
    m_navigation->applyGL();

  m_scene->pick(x, y);
The picking function is the standard text-book method for picking. Any ideas? Greetz, JeDi [edited by - JeroenDierckx on March 21, 2004 10:25:25 AM]

Share this post


Link to post
Share on other sites
JeroenDierckx    122
Just to make sure, here is the picking function:


Object *Scene::pick(int x, int y)
{
GLuint selectBuffer[PICKINGSIZE];
glSelectBuffer(PICKINGSIZE, selectBuffer);

glRenderMode(GL_SELECT);

glInitNames();
glPushName(0);

GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

GLdouble projection[16];
glGetDoublev(GL_PROJECTION_MATRIX, projection);

glMatrixMode(GL_PROJECTION);
glPushMatrix();

glLoadIdentity();
gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), PICKREGION, PICKREGION, viewport);
glMultMatrixd(projection);

// Draw the objects

for(unsigned int i = 0; i < m_objects.size(); ++i)
{
glLoadName(i);
m_objects[i]->drawGL();
}

glPopMatrix();
glFlush();

glMatrixMode(GL_MODELVIEW);
GLint hits = glRenderMode(GL_RENDER);
if(hits < 0)
cerr << "The picking buffer has overflowed!" << endl;


// Determine which item is picked

GLuint depth = 0;
int index = -1;
GLuint *ptr = (GLuint *) selectBuffer;

for(GLint i = 0; i < hits; ++i)
{
GLuint nrNames = *ptr;
++ptr;
GLuint minZ = *ptr;
++ptr;
++ptr;

for(GLuint j = 0; j < nrNames; ++j)
{
if(minZ >= depth)
{
depth = minZ;
index = *ptr;
}
ptr++;
}
}

if(index != -1)
{
Object *object = m_objects[index];
m_selectedObject = object;
return object;
}

m_selectedObject = 0;
return 0;
}


Greetz,
JeDi

[edited by - JeroenDierckx on March 21, 2004 10:29:28 AM]

Share this post


Link to post
Share on other sites