arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Pick Class Reference

#include <Pick.h>

List of all members.


Detailed Description

Pick, creates a PickInfoVec in sorted order from least to greatest z1 when "endPick()" is called: Here's how it works: - You get a mouse event with an x,y screen space position - You determine if it warents a pick - If it does, create a Pick object - call Pick::startPickGL() - call your draw function - call Pick::endPickGL() & capture PickInfoVec.

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];
You might need to flip the y, ie. p.startPickGL(x,height-y-1,4);..

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)
Pickoperator= (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


Constructor & Destructor Documentation

Pick::Pick int  pickBufferSize = 1024  )  [inline]
 

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.

Pick::Pick const Pick p  )  [inline]
 

Definition at line 153 of file Pick.h.

References _pbSize, _pickBuffer, and _picking.

Pick::~Pick  )  [inline]
 

Definition at line 165 of file Pick.h.

References _pickBuffer.


Member Function Documentation

PickInfoVec Pick::endPickGL  ) 
 

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().

Pick& Pick::operator= const Pick p  )  [inline]
 

Definition at line 158 of file Pick.h.

References _pbSize, and _pickBuffer.

void Pick::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.

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().


Member Data Documentation

int Pick::_pbSize [protected]
 

Definition at line 188 of file Pick.h.

Referenced by endPickGL(), operator=(), Pick(), and startPickGL().

unsigned int* Pick::_pickBuffer [protected]
 

/////////////////////////////////////////////////////////////

Definition at line 187 of file Pick.h.

Referenced by endPickGL(), operator=(), Pick(), startPickGL(), and ~Pick().

bool Pick::_picking [protected]
 

Definition at line 189 of file Pick.h.

Referenced by endPickGL(), Pick(), and startPickGL().


The documentation for this class was generated from the following files:
Send questions, comments, and bug reports to:
jmk