Jump to content
  • Advertisement
Sign in to follow this  
lenlod

picking works wrong

This topic is 3082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone.
I have a problem with multiple picking in OpenGL. One time I click the mouse it works right, another time I try to pick the object it works wrong, i.e it not picks. Where is the problem?

Share this post


Link to post
Share on other sites
Advertisement

void TFormDrawShape::Selection(void) // This is where selection is done
{
GLuint buffer[512]; // Set up a selection buffer
GLint hits; // The number of objects that we selected

// The size of the viewport. [0] is <x>, [1] is <y>, [2] is <length>, [3] is <width>
GLint viewport[4];

// This sets the array <viewport> to the size and location of the screen relative to the window
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(512, buffer); // Tell OpenGL to use our array for selection

// Puts OpenGL in selection mode. Nothing will be drawn. Object ID's and extents are stored in the buffer.
(void) glRenderMode(GL_SELECT);

glInitNames(); // Initializes the name stack
glPushName(0); // Push 0 (At least one entry) onto the stack

glMatrixMode(GL_PROJECTION); // Selects the projection matrix
glPushMatrix(); // Push the projection matrix
glLoadIdentity(); // Resets the matrix

// This creates a matrix that will zoom up to a small portion of the screen, where the mouse is.
gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y), 1.0f, 1.0f, viewport);

// Apply the perspective matrix
gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW); // Select the modelview matrix
DrawTargets(); // Render the targets to the selection buffer
glMatrixMode(GL_PROJECTION); // Select the projection matrix
glPopMatrix(); // Pop the projection matrix
glMatrixMode(GL_MODELVIEW); // Select the modelview matrix
hits=glRenderMode(GL_RENDER); // Switch to render mode, find out how many
// Objects were drawn where the mouse was
if (hits > 0) // If there were more than 0 hits
{
int choose = buffer[3]; // Make our selection the first object
int depth = buffer[1]; // Store how far away it is

for (int loop = 1; loop < hits; loop++) // Loop through all the detected hits
{
// If this object is closer to us than the one we have selected
int choose1 = buffer[loop*4+3]; // Select the closer object
if(choose1>=200)
{
choose=choose1;
// break;
}
/* if (buffer[loop*4+1] < GLuint(depth))
{
choose = buffer[loop*4+3]; // Select the closer object
depth = buffer[loop*4+1]; // Store how far away it is
}*/

}

/* if (!object[choose].hit) // If the object hasn't already been hit
{
object[choose].hit=TRUE; // Mark the object as bening hit
}*/

if(choose<100)//decorations
{
if(!pconfig->GetDecor(choose)->m_hit)
pconfig->GetDecor(choose)->m_hit=true;
else
pconfig->GetDecor(choose)->m_hit=false;
// FormTableConfig->UpdateDecors();
FormTableConfig->Init(pconfig);
FormTableConfig->sgDecors->Repaint();
}
if(choose>=100 && choose<200)//barbells
{
if(!pconfig->GetBarbell(choose-100)->m_hit)
pconfig->GetBarbell(choose-100)->m_hit=true;
else
pconfig->GetBarbell(choose-100)->m_hit=false;
FormTableConfig->Init(pconfig);
FormTableConfig->sgBarbells->Repaint();

// FormTableConfig->UpdateBarbells();
}
if(choose>=200)//devices
{
if(!pconfig->GetDevice(choose-200)->m_hit)
pconfig->GetDevice(choose-200)->m_hit=true;
else
pconfig->GetDevice(choose-200)->m_hit=false;
FormTableDeviceConfig->Init(pconfig);
FormTableDeviceConfig->sgDevices->Repaint();
FormDrawShapeUser->SetConfig(pconfig);
// FormTableDeviceConfig->UpdateDevices();
}
}





As you can see depth checking is commented. Actually it does not work too, however depth test was set enabled. For each object depth value is the same and very big negative.
But the main problem is still not regular objects picking.
I have tried to test one thing. I have made selection cycle with the points around the mouse points, because often I have to change mouse position to pick.
And the result is it does not work ever.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!