ARGoS 3
A parallel, multi-engine simulator for swarm robotics
qtopengl_box.cpp
Go to the documentation of this file.
1
7#include "qtopengl_box.h"
8#include <argos3/core/utility/math/vector2.h>
9#include <argos3/plugins/simulator/entities/led_equipped_entity.h>
10#include <argos3/plugins/simulator/entities/box_entity.h>
11#include <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_widget.h>
12
13namespace argos {
14
15 /****************************************/
16 /****************************************/
17
18 static const Real LED_RADIUS = 0.01f;
19 const GLfloat MOVABLE_COLOR[] = { 1.0f, 0.0f, 0.0f, 1.0f };
20 const GLfloat NONMOVABLE_COLOR[] = { 0.7f, 0.7f, 0.7f, 1.0f };
21 const GLfloat SPECULAR[] = { 0.0f, 0.0f, 0.0f, 1.0f };
22 const GLfloat SHININESS[] = { 0.0f };
23 const GLfloat EMISSION[] = { 0.0f, 0.0f, 0.0f, 1.0f };
24
25 /****************************************/
26 /****************************************/
27
29 m_unVertices(20){
30
31 /* Reserve the needed display lists */
32 m_unBaseList = glGenLists(2);
33 m_unBodyList = m_unBaseList;
34 m_unLEDList = m_unBaseList + 1;
35
36 /* Make body list */
37 glNewList(m_unBodyList, GL_COMPILE);
38 MakeBody();
39 glEndList();
40
41 /* Make LED list */
42 glNewList(m_unLEDList, GL_COMPILE);
43 MakeLED();
44 glEndList();
45
46 }
47
48 /****************************************/
49 /****************************************/
50
52 glDeleteLists(m_unBaseList, 2);
53 }
54
55 /****************************************/
56 /****************************************/
57
59 /* Draw the LEDs */
60 GLfloat pfColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
61 const GLfloat pfSpecular[] = { 0.0f, 0.0f, 0.0f, 1.0f };
62 const GLfloat pfShininess[] = { 100.0f };
63 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
64 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
65 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
66 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
67 CLEDEquippedEntity& cLEDEquippedEntity = c_entity.GetLEDEquippedEntity();
68 for(UInt32 i = 0; i < cLEDEquippedEntity.GetLEDs().size(); ++i) {
69 glPushMatrix();
70 /* Set the material */
71 const CColor& cColor = cLEDEquippedEntity.GetLED(i).GetColor();
72 pfColor[0] = cColor.GetRed() / 255.0f;
73 pfColor[1] = cColor.GetGreen() / 255.0f;
74 pfColor[2] = cColor.GetBlue() / 255.0f;
75 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
76 /* Perform rototranslation */
77 const CVector3& cPosition = cLEDEquippedEntity.GetLEDOffset(i);
78 glTranslated(cPosition.GetX(), cPosition.GetY(), cPosition.GetZ());
79 /* Draw the LED */
80 glCallList(m_unLEDList);
81 glPopMatrix();
82 }
83 }
84
85 /****************************************/
86 /****************************************/
87
88 void CQTOpenGLBox::Draw(const CBoxEntity& c_entity) {
89 /* Draw the body */
90 if(c_entity.GetEmbodiedEntity().IsMovable()) {
91 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, MOVABLE_COLOR);
92 }
93 else {
94 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, NONMOVABLE_COLOR);
95 }
96 glPushMatrix();
97 glScaled(c_entity.GetSize().GetX(), c_entity.GetSize().GetY(), c_entity.GetSize().GetZ());
98 glCallList(m_unBodyList);
99 glPopMatrix();
100 }
101
102 /****************************************/
103 /****************************************/
104
105 void CQTOpenGLBox::MakeBody() {
106 /* Since this shape can be stretched,
107 make sure the normal vectors are unit-long */
108 glEnable(GL_NORMALIZE);
109
110 /* Set the material */
111 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SPECULAR);
112 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, SHININESS);
113 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, EMISSION);
114
115 /* Let's start the actual shape */
116
117 /* This part covers the top and bottom faces (parallel to XY) */
118 glBegin(GL_QUADS);
119 /* Bottom face */
120 glNormal3d(0.0f, 0.0f, -1.0f);
121 glVertex3d( 0.5f, 0.5f, 0.0f);
122 glVertex3d( 0.5f, -0.5f, 0.0f);
123 glVertex3d(-0.5f, -0.5f, 0.0f);
124 glVertex3d(-0.5f, 0.5f, 0.0f);
125 /* Top face */
126 glNormal3d(0.0f, 0.0f, 1.0f);
127 glVertex3d(-0.5f, -0.5f, 1.0f);
128 glVertex3d( 0.5f, -0.5f, 1.0f);
129 glVertex3d( 0.5f, 0.5f, 1.0f);
130 glVertex3d(-0.5f, 0.5f, 1.0f);
131 glEnd();
132 /* This part covers the faces (South, East, North, West) */
133 glBegin(GL_QUADS);
134 /* South face */
135 glNormal3d(0.0f, -1.0f, 0.0f);
136 glVertex3d(-0.5f, -0.5f, 1.0f);
137 glVertex3d(-0.5f, -0.5f, 0.0f);
138 glVertex3d( 0.5f, -0.5f, 0.0f);
139 glVertex3d( 0.5f, -0.5f, 1.0f);
140 /* East face */
141 glNormal3d(1.0f, 0.0f, 0.0f);
142 glVertex3d( 0.5f, -0.5f, 1.0f);
143 glVertex3d( 0.5f, -0.5f, 0.0f);
144 glVertex3d( 0.5f, 0.5f, 0.0f);
145 glVertex3d( 0.5f, 0.5f, 1.0f);
146 /* North face */
147 glNormal3d(0.0f, 1.0f, 0.0f);
148 glVertex3d( 0.5f, 0.5f, 1.0f);
149 glVertex3d( 0.5f, 0.5f, 0.0f);
150 glVertex3d(-0.5f, 0.5f, 0.0f);
151 glVertex3d(-0.5f, 0.5f, 1.0f);
152 /* West face */
153 glNormal3d(-1.0f, 0.0f, 0.0f);
154 glVertex3d(-0.5f, 0.5f, 1.0f);
155 glVertex3d(-0.5f, 0.5f, 0.0f);
156 glVertex3d(-0.5f, -0.5f, 0.0f);
157 glVertex3d(-0.5f, -0.5f, 1.0f);
158 glEnd();
159 /* The shape definitions is finished */
160
161 /* We don't need it anymore */
162 glDisable(GL_NORMALIZE);
163 }
164
165 /****************************************/
166 /****************************************/
167
168 void CQTOpenGLBox::MakeLED() {
169 CVector3 cNormal, cPoint;
170 CRadians cSlice(CRadians::TWO_PI / m_unVertices);
171
172 glBegin(GL_TRIANGLE_STRIP);
173 for(CRadians cInclination; cInclination <= CRadians::PI; cInclination += cSlice) {
174 for(CRadians cAzimuth; cAzimuth <= CRadians::TWO_PI; cAzimuth += cSlice) {
175
176 cNormal.FromSphericalCoords(1.0f, cInclination, cAzimuth);
177 cPoint = LED_RADIUS * cNormal;
178 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
179 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
180
181 cNormal.FromSphericalCoords(1.0f, cInclination + cSlice, cAzimuth);
182 cPoint = LED_RADIUS * cNormal;
183 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
184 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
185
186 cNormal.FromSphericalCoords(1.0f, cInclination, cAzimuth + cSlice);
187 cPoint = LED_RADIUS * cNormal;
188 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
189 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
190
191 cNormal.FromSphericalCoords(1.0f, cInclination + cSlice, cAzimuth + cSlice);
192 cPoint = LED_RADIUS * cNormal;
193 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
194 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
195
196 }
197 }
198 glEnd();
199 }
200
201 /****************************************/
202 /****************************************/
203
205 public:
206 void ApplyTo(CQTOpenGLWidget& c_visualization,
207 CBoxEntity& c_entity) {
208 static CQTOpenGLBox m_cModel;
209 c_visualization.DrawEntity(c_entity.GetEmbodiedEntity());
210 m_cModel.Draw(c_entity);
211 m_cModel.DrawLEDs(c_entity);
212 }
213 };
214
216 public:
217 void ApplyTo(CQTOpenGLWidget& c_visualization,
218 CBoxEntity& c_entity) {
219 c_visualization.DrawBoundingBox(c_entity.GetEmbodiedEntity());
220 }
221 };
222
224
226
227 /****************************************/
228 /****************************************/
229
230}
#define REGISTER_QTOPENGL_ENTITY_OPERATION(ACTION, OPERATION, ENTITY)
unsigned int UInt32
32-bit unsigned integer.
Definition datatypes.h:97
float Real
Collects all ARGoS code.
Definition datatypes.h:39
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
const GLfloat MOVABLE_COLOR[]
const GLfloat SHININESS[]
const GLfloat SPECULAR[]
const GLfloat EMISSION[]
const GLfloat NONMOVABLE_COLOR[]
bool IsMovable() const
Returns true if the entity is movable.
The basic color type.
Definition color.h:25
UInt8 GetBlue() const
Returns the blue channel of the color.
Definition color.h:101
UInt8 GetGreen() const
Returns the green channel of the color.
Definition color.h:90
UInt8 GetRed() const
Returns the red channel of the color.
Definition color.h:79
static const CRadians PI
The PI constant.
Definition angles.h:49
static const CRadians TWO_PI
Set to PI * 2.
Definition angles.h:54
A 3D vector class.
Definition vector3.h:31
Real GetX() const
Returns the x coordinate of this vector.
Definition vector3.h:105
Real GetY() const
Returns the y coordinate of this vector.
Definition vector3.h:121
Real GetZ() const
Returns the z coordinate of this vector.
Definition vector3.h:137
CLEDEquippedEntity & GetLEDEquippedEntity()
Definition box_entity.h:72
const CVector3 & GetSize() const
Definition box_entity.h:80
CEmbodiedEntity & GetEmbodiedEntity()
Definition box_entity.h:64
const CColor & GetColor() const
Returns the current color of the LED.
Definition led_entity.h:58
A container of CLEDEntity.
CLEDEntity & GetLED(UInt32 un_index)
Returns an LED by numeric index.
const CVector3 & GetLEDOffset(size_t un_idx) const
Returns the offset position of the given LED.
SActuator::TList & GetLEDs()
Returns all the LEDs.
void ApplyTo(CQTOpenGLWidget &c_visualization, CBoxEntity &c_entity)
void ApplyTo(CQTOpenGLWidget &c_visualization, CBoxEntity &c_entity)
virtual void DrawLEDs(CBoxEntity &c_entity)
virtual void Draw(const CBoxEntity &c_entity)
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
void DrawBoundingBox(CEmbodiedEntity &c_entity)
Draws the bounding box of an embodied entity.