Sign in to follow this  
datalurkur

Picking Problem - FIXED

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this