Class6 Picking
Class6 Picking
Picking
Object Picking
Mankyu Sung 1
Computer Graphics II
Object Picking
For many cases, we should be able to change the positions of objects with mouse
The framework I provided have functions for object picking. You must know how to
use them
These functions are not related to Physical Simulation directly. However, it is
required for interaction.
Mankyu Sung 2
Computer Graphics II
Mankyu Sung 3
Computer Graphics II
step 1
Numbering : in the draw(), provide a number for each object
if (!shadow)
glLoadName(1); (set the number 1)
Mankyu Sung 4
Computer Graphics II
step 2
Call MyGlWindow::doPick(), when you click a left mouse button
Go to MyGlWindow::handle()
int MyGlWindow::handle(int e)
{
switch (e) {
case FL_SHOW:
show();
return 1;
case FL_PUSH: //mouse pushing event
{
m_pressedMouseButton = Fl::event_button(); //which button? 1(left), 2(middle), 3(rig
m_lastMouseX = Fl::event_x(); //mouse x pos
When you click m_lastMouseY = Fl::event_y(); //mouse y pos
}
damage(1);
return 1;
case FL_RELEASE: //mouse releasing event
When you release a button m_pressedMouseButton = -1;
damage(1);
return 1;
When you drag a mouse case FL_DRAG: // if the user drags the mouse
{
Mankyu Sung 5
Computer Graphics II
step2
Call doPick() on GL_PUSH event
case FL_PUSH:
{
m_pressedMouseButton = Fl::event_button();
m_lastMouseX = Fl::event_x();
m_lastMouseY = Fl::event_y();
Mankyu Sung 6
Computer Graphics II
step3
Modify doPick()
….
setProjection(false); set this value to false
GLuint buf[100];
glSelectBuffer(100, buf);
glRenderMode(GL_SELECT); Ex)
glInitNames(); 1. When there is only one object
glPushName(0); m_mover->draw(0);
Call draw() with (shadow = 0)
2. When there are several objects
//why shadow=0? Because object itself
//must be pickable (not its shadow) for(int i=0; i<movers.size(); i++)
{
movers[i]->draw(0);
int hits = glRenderMode(GL_RENDER); }
//note that each mover must have a different number
…
Mankyu Sung 7
Computer Graphics II
step3
Modify doPick()
Mankyu Sung 8
Computer Graphics II
step4
Dragging Event processing : Choice between camera control and object moving
case FL_DRAG: // if the user drags the mouse
{
damage(1);
}
else {
Mankyu Sung 9
Computer Graphics II
Step 4
When an object is picked
if (selected >= 0 && m_pressedMouseButton == 1) {
damage(1);
}
Mankyu Sung 10
Computer Graphics II
Step 4 Example
if (selected >= 0 && m_pressedMouseButton == 1) {
damage(1);
}
Mankyu Sung 11
Computer Graphics II
Mankyu Sung 12
Computer Graphics II
https://padlet.com/mksung89/picking
Mankyu Sung 13