/**************************************************************************** Copyright (C) 2002-2006 Gilles Debunne (Gilles.Debunne@imag.fr) This file is part of the QGLViewer library. Version 2.2.4-1, released on December 12, 2006. http://artis.imag.fr/Members/Gilles.Debunne/QGLViewer libQGLViewer is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. libQGLViewer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with libQGLViewer; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ #include "select.h" #include #include using namespace std; static void drawSpiral(const bool specialColor = false) { const float nbSteps = 100.0; glBegin(GL_QUAD_STRIP); for (float i=0; iconvertClickToLine(point, orig, dir); // Find the selectedPoint coordinates, using camera()->pointUnderPixel(). bool found; selectedPoint = camera()->pointUnderPixel(point, found); selectedPoint -= 0.01*dir; // Small offset to make point clearly visible. // Note that "found" is different from (selectedObjectId()>=0) because of the size of the select region. if (selectedName() == -1) QMessageBox::information(this, "No selection", "No object selected under pixel " + QString::number(point.x()) + "," + QString::number(point.y())); else QMessageBox::information(this, "Selection", "Spiral number " + QString::number(selectedName()) + " selected under pixel " + QString::number(point.x()) + "," + QString::number(point.y())); } void Viewer::init() { restoreStateFromFile(); glLineWidth(3.0); glPointSize(10.0); help(); } void Viewer::draw() { // Draw ten spirals const int nb = 10; for (int i=0; i= 0) { glColor3f(0.9, 0.2, 0.1); glBegin(GL_POINTS); glVertex3fv(selectedPoint); glEnd(); } } QString Viewer::helpString() const { QString text("

S e l e c t

"); text += "Left click while pressing the Shift key to select an object of the scene.

"; text += "A line is drawn between the selected point and the camera selection position. "; text += "using convertClickToLine(), a useful function for analytical intersections.

"; text += "To add object selection in your viewer, all you need to do is to define the drawWithNames function. "; text += "It gives a name to each selectable object and selection is then performed using the OpenGL GL_SELECT render mode.

"; text += "Feel free to cut and paste this implementation in your own applications."; return text; }