graphicalmarkers.cpp
1 /********************************************************************************
2  * FARSA Experiments Library *
3  * Copyright (C) 2007-2012 *
4  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
5  * Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it> *
6  * Gianluca Massera <emmegian@yahoo.it> *
7  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the Free Software *
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
22  ********************************************************************************/
23 
24 #include "graphicalmarkers.h"
25 
26 #ifndef GLMultMatrix
27 #define GLMultMatrix glMultMatrixf
28 // for double glMultMatrixd
29 #endif
30 
31 namespace farsa {
32 
33 CircularGraphicalMarker::CircularGraphicalMarker(real radius, World* world, QString name, const wMatrix& tm) :
34  GraphicalWObject(world, name, tm),
35  m_radius(radius)
36 {
37 }
38 
40 {
41 }
42 
43 void CircularGraphicalMarker::render(RenderWObject* renderer, QGLContext* gw)
44 {
45  // Pushing our transformation matrix
46  renderer->container()->setupColorTexture(gw, renderer);
47  glPushMatrix();
48  GLMultMatrix(&tm[0][0]);
49 
50  // Drawing the disk. We disable lightining
51  glPushAttrib(GL_LIGHTING_BIT);
52  glDisable(GL_LIGHTING);
53  glColor3f(color().redF(), color().greenF(), color().blueF());
54 
55  // Actually drawing the disk
56  GLUquadricObj *pObj = gluNewQuadric();
57  gluDisk(pObj, 0.0f, m_radius, 20, 1);
58  gluDeleteQuadric(pObj);
59 
60  // Restoring lighting status
61  glPopAttrib();
62 
63  glPopMatrix();
64 }
65 
66 PlanarArrowGraphicalMarker::PlanarArrowGraphicalMarker(real arrowLength, real arrowTailWidth, real arrowHeadWidth, real arrowTailPortion, World* world, QString name, const wMatrix& tm):
67  GraphicalWObject(world, name, tm),
68  m_arrowLength(arrowLength),
69  m_arrowTailWidth(arrowTailWidth),
70  m_arrowHeadWidth(arrowHeadWidth),
71  m_arrowTailPortion(max(min(arrowTailPortion, 1.0), 0.0))
72 {
73 }
74 
76 {
77 }
78 
79 void PlanarArrowGraphicalMarker::render(RenderWObject* renderer, QGLContext* gw)
80 {
81  // Pushing our transformation matrix
82  renderer->container()->setupColorTexture(gw, renderer);
83  glPushMatrix();
84  GLMultMatrix(&tm[0][0]);
85 
86  // Drawing the arrow. We disable lightining
87  glPushAttrib(GL_LIGHTING_BIT);
88  glDisable(GL_LIGHTING);
89  glColor3f(color().redF(), color().greenF(), color().blueF());
90 
91  // First drawing the tail
92  const real tailLength = m_arrowLength * m_arrowTailPortion;
93  glBegin(GL_QUADS);
94  glNormal3f(0.0, 0.0, 1.0);
95  glVertex3f(0.0, -m_arrowTailWidth / 2.0, 0.0);
96  glVertex3f(0.0, m_arrowTailWidth / 2.0, 0.0);
97  glVertex3f(tailLength, m_arrowTailWidth / 2.0, 0.0);
98  glVertex3f(tailLength, -m_arrowTailWidth / 2.0, 0.0);
99  glEnd();
100 
101  // Now drawing the tip
102  glBegin(GL_TRIANGLES);
103  glNormal3f(0.0, 0.0, 1.0);
104  glVertex3f(tailLength, -m_arrowHeadWidth / 2.0, 0.0);
105  glVertex3f(tailLength, m_arrowHeadWidth / 2.0, 0.0);
106  glVertex3f(m_arrowLength, 0.0, 0.0);
107  glEnd();
108 
109  // Restoring lighting status
110  glPopAttrib();
111 
112  glPopMatrix();
113 }
114 
115 }