#include <Pick.h>
The PickInfoVec is now filled with the pick info. This info is sorted based on z1 in increasing order. Use this info to handle picking how ever you like.
If you are doing a whole lot of picking, you may want to create a single pick object and keep it around so you aren't creating and deleating the pick buffer so much.
Here is an example:
... in a mouse-down function (double/int x, double/int y) Pick p(); p.startPickGL(x,y,4); // starting picking { /// I use brackets to keep the code clean :) draw(); // my draw function } PickInfoVec pinfo = p.endPickGL(); if(pinfo.size()) myTopObjId0 = pinfo[0].data[0];
Note: This class sets the "GL_PROJECTION" matrix, so if you are setting it every render pass, you need make sure that you don't while picking is going on. Once Pick::endPickGL() has been called, the projection matrix will be reset to what it was before Pick::startPickGL() was called. Just make sure that you don't modify the projection matrix between these calls, or you will get some strange picking behavior. The projection matrix that you are using for rendering should be the current projection matrix when you call Pick::startPickGL().
Definition at line 141 of file Pick.h.
Public Member Functions | |
Pick (int pickBufferSize=1024) | |
how big do you want the pick buffer to be? depends on how much data you will be pushing on the gl name stack, and the depth complexity of the scene; 1024 is probably ample. | |
Pick (const Pick &p) | |
Pick & | operator= (const Pick &p) |
~Pick () | |
void | startPickGL (double x, double y, double pickWin=4) |
begin a pick, you need to call your draw loop and then endPick when you are done. | |
PickInfoVec | endPickGL () |
end a pick, creates a pick information vector | |
Protected Attributes | |
unsigned int * | _pickBuffer |
///////////////////////////////////////////////////////////// | |
int | _pbSize |
bool | _picking |
|
how big do you want the pick buffer to be? depends on how much data you will be pushing on the gl name stack, and the depth complexity of the scene; 1024 is probably ample.
Definition at line 148 of file Pick.h. References _pbSize, _pickBuffer, and _picking. |
|
Definition at line 153 of file Pick.h. References _pbSize, _pickBuffer, and _picking. |
|
Definition at line 165 of file Pick.h. References _pickBuffer. |
|
end a pick, creates a pick information vector reset projection matrix setting the render mode back returns hits see if we actually picked ANYTHING we did so create the info vector loop over picks < just return what we have first item on stack is the number of names < just return what we have add the pick info to our vector increment j so we are at the right position in the pick buffer. end loop over picks sort pickInfo vector based on increasing z1 value catch the most obvious user mistake and report it TODO: an assertion would force the user fix this too make sure we don't overrun the pick buffer, first check. make sure we don't overrun the pick buffer second check.. Definition at line 66 of file Pick.cpp. References _pbSize, _pickBuffer, _picking, GL_MODELVIEW, GL_PROJECTION, GL_RENDER, GLint, glMatrixMode(), glPopMatrix(), glRenderMode(), and PickInfoVec. Referenced by RenderableQGL::pickGL(). |
|
Definition at line 158 of file Pick.h. References _pbSize, and _pickBuffer. |
|
begin a pick, you need to call your draw loop and then endPick when you are done. set up projection matrix for picking set up pick buffer and render mode initiallize name buffer Definition at line 28 of file Pick.cpp. References _pbSize, _pickBuffer, _picking, GL_MODELVIEW, GL_PROJECTION, GL_PROJECTION_MATRIX, GL_SELECT, GL_VIEWPORT, GLfloat, glGetFloatv(), glGetIntegerv(), glInitNames(), GLint, glLoadIdentity(), glMatrixMode(), glMultMatrixf(), glPushMatrix(), glRenderMode(), glSelectBuffer(), x, and y. Referenced by RenderableQGL::pickGL(). |
|
Definition at line 188 of file Pick.h. Referenced by endPickGL(), operator=(), Pick(), and startPickGL(). |
|
/////////////////////////////////////////////////////////////
Definition at line 187 of file Pick.h. Referenced by endPickGL(), operator=(), Pick(), startPickGL(), and ~Pick(). |
|
Definition at line 189 of file Pick.h. Referenced by endPickGL(), Pick(), and startPickGL(). |