Jump to content
  • Advertisement
Sign in to follow this  
datalurkur

Picking Problem - FIXED

This topic is 3673 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

I am working on a RTS, and I want to be able to select all of the units within a bounding box drawn by clicking and dragging the mouse (the start and end locations defining the corners of the box). Simply clicking on a location (making a very small picking window) works fine, but about 25% of the large selection areas I've tested simply don't work. Here is the picking code: // xCent and yCent are the center of the picking window // xRad and yRad are the width and height of the picking window GLint doPicking(int xCent, int yCent, int xRad, int yRad) { GLint viewport[4]; GLint hits; // User has clicked, use picking to find out what they clicked on // Set the pickbuffer and switch to select mode glSelectBuffer(pickBufferSize, pickBuffer); glRenderMode(GL_SELECT); // Redefine draw volume to only include a small area around the cursor glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); // Get current viewport glGetIntegerv(GL_VIEWPORT, viewport); gluPickMatrix(xCent, viewport[3]-yCent, xRad, yRad, viewport); gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1, 1000); glMatrixMode(GL_MODELVIEW); // Render for picking DrawGrid(); DrawBits(); // Stop picking glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glFlush(); // Reset rendering mode and get the number of hits hits=glRenderMode(GL_RENDER); return hits; } Width and height are external integers set to the GL window's width and height, and pickBufferSize is sufficiently large (2048, with < 100 named objects present in the scene). I have verified (by commenting out calls to glRenderMode) that in the cases where picking fails, the objects are indeed being drawn to the selection buffer. For some reason, however, glRenderMode(GL_RENDER) returns -1. What does this mean? [Edited by - datalurkur on July 24, 2008 8:46:06 PM]

Share this post


Link to post
Share on other sites
Advertisement
So I've been working on this problem for days, and sure enough as soon as I post about it, I answered my own question. It seems glRenderMode will return -1 if the pick buffer is too small.

I solved the problem with a simple if statement that increases the pick buffer size twofold and re-runs picking if hits is returned as -1.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!