Introduction
Mouse picking is an often used, intuitive operation to interact with 3D scenes in a variety of 3D graphics applications. CHAI3D provides some basic capabilities to detect if an object has been selected. The mouse selection procedure requires first setting up a collision recorder and the desired collision settings. The following listing illustrate a basic example.
bool hit = camera->select(x, y, windowWidth, windowHeight, recorder, settings);
This class implements a collision detection recorder that stores all collision events that are report...
Definition CCollisionBasics.h:186
Definition CAudioBuffer.cpp:57
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition CCollisionBasics.h:243
The collision recorder is empty at first and accumulates the selected objects located underneath the mouse pointer. The information returned for each collision event is stored in a cCollisionEvent structure. Such structure will contain a pointer to the object, 3D position information of the mouse click, selected triangle (cMesh), and surface normal.
Collision settings can be setup to filter certain types of data or to speed up the procedure.
Example
Example 07-mouse-select: The operator can select and move an object with the mouse.
In the following listing extracted from example 12-polygon, a mouse click callback is programmed. If a triangle from a mesh object is selected, its vertices a painted in red.
void mouseClick(int button, int state, int x, int y)
{
if (state == GLUT_DOWN)
{
bool hit = camera->select(x, y, windowW, windowH, recorder, settings);
if (hit)
{
if (triangle != NULL)
{
triangle->getVertex0()->setColor(color);
triangle->getVertex1()->setColor(color);
triangle->getVertex2()->setColor(color);
}
}
}
}
cCollisionEvent m_nearestCollision
Nearest collision event from the start point of the collision segment.
Definition CCollisionBasics.h:221
This class defines a color using a GLfloat representation for each component.
Definition CColor.h:139
void setRed()
This method sets the color to Red.
Definition CColor.h:660