9 #include <argos3/core/simulator/entity/embodied_entity.h>
10 #include <argos3/core/utility/math/vector2.h>
11 #include <argos3/core/utility/math/vector3.h>
12 #include <argos3/plugins/simulator/entities/led_equipped_entity.h>
13 #include <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_widget.h>
21 static const GLfloat SIDE = 0.470f;
22 static const GLfloat DIAGONAL = SIDE * ::sqrt(2);
23 static const GLfloat OUT_RADIUS = DIAGONAL / 5.0f;
24 static const GLfloat IN_RADIUS = OUT_RADIUS * 0.95f;
25 static const GLfloat HEIGHT = 0.090f;
27 static const GLfloat PROP_HEIGHT = HEIGHT / 2.0f;
28 static const GLfloat PROP_ELEVATION = HEIGHT - PROP_HEIGHT;
29 static const GLfloat PROP_ARM = DIAGONAL / 2.0f - OUT_RADIUS;
31 static const GLfloat LEG_RADIUS = OUT_RADIUS * 0.05f;
32 static const GLfloat LEG_HEIGHT = HEIGHT - PROP_HEIGHT;
34 static const GLfloat BODY_SIDE = OUT_RADIUS;
35 static const GLfloat BODY_HEIGHT = HEIGHT * 3.0f / 4.0f;
36 static const GLfloat BODY_ELEVATION = HEIGHT - BODY_HEIGHT;
44 m_unList = glGenLists(1);
45 glNewList(m_unList, GL_COMPILE);
54 glDeleteLists(m_unList, 1);
63 glPushAttrib(GL_LINE_BIT);
65 glEnable(GL_LINE_SMOOTH);
68 SetMainBodyMaterial();
72 glVertex3f(DIAGONAL,0,0);
81 void CQTOpenGLSpiri::SetPlasticMaterial() {
82 const GLfloat pfColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
83 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
84 const GLfloat pfShininess[] = { 100.0f };
85 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
86 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
87 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
88 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
89 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
95 void CQTOpenGLSpiri::SetPropellerMaterial() {
96 const GLfloat pfColor[] = { 0.7f, 0.7f, 0.7f, 1.0f };
97 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
98 const GLfloat pfShininess[] = { 100.0f };
99 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
100 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
101 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
102 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
103 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
109 void CQTOpenGLSpiri::SetMainBodyMaterial() {
110 const GLfloat pfColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };
111 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
112 const GLfloat pfShininess[] = { 100.0f };
113 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
114 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
115 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
116 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
117 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
123 void CQTOpenGLSpiri::MakeModel() {
125 glRotatef(45.0f, 0.0f, 0.0f, 1.0f);
129 glTranslatef(PROP_ARM, 0.0f, 0.0f);
132 glTranslatef(-PROP_ARM, PROP_ARM, 0.0f);
135 glTranslatef(-PROP_ARM, -PROP_ARM, 0.0f);
138 glTranslatef(PROP_ARM, -PROP_ARM, 0.0f);
140 glTranslatef(0.0f, PROP_ARM, 0.0f);
147 void CQTOpenGLSpiri::MakePropeller() {
149 SetPlasticMaterial();
153 MakeCylinder(LEG_RADIUS, LEG_HEIGHT);
158 glTranslatef(0.0f, 0.0f, PROP_ELEVATION);
160 MakeCylinderSurface(OUT_RADIUS, PROP_HEIGHT);
161 glCullFace(GL_FRONT);
162 MakeCylinderSurface(IN_RADIUS, PROP_HEIGHT);
165 glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
166 SetPlasticMaterial();
167 MakeRing(OUT_RADIUS, IN_RADIUS);
169 glRotatef(-180.0f, 1.0f, 0.0f, 0.0f);
170 glTranslatef(0.0f, 0.0f, PROP_HEIGHT / 2.0f);
171 SetPropellerMaterial();
174 glTranslatef(0.0f, 0.0f, PROP_HEIGHT / 2.0f);
175 SetPlasticMaterial();
176 MakeRing(OUT_RADIUS, IN_RADIUS);
183 void CQTOpenGLSpiri::MakeMainBody() {
185 SetMainBodyMaterial();
186 glTranslatef(0.0f, 0.0f, BODY_ELEVATION);
187 MakeBox(BODY_SIDE, BODY_SIDE, BODY_HEIGHT);
194 void CQTOpenGLSpiri::MakeRing(GLfloat f_out_radius,
195 GLfloat f_in_radius) {
196 CVector2 cVertex(1.0f, 0.0f);
198 glBegin(GL_QUAD_STRIP);
199 glNormal3f(0.0f, 0.0f, 1.0f);
200 for(GLuint i = 0; i <= m_unVertices; i++) {
201 glVertex3f(cVertex.GetX() * f_in_radius, cVertex.GetY() * f_in_radius, 0.0f);
202 glVertex3f(cVertex.GetX() * f_out_radius, cVertex.GetY() * f_out_radius, 0.0f);
203 cVertex.Rotate(cAngle);
211 void CQTOpenGLSpiri::MakeDisk(GLfloat f_radius) {
212 CVector2 cVertex(f_radius, 0.0f);
215 glNormal3f(0.0f, 0.0f, 1.0f);
216 for(GLuint i = 0; i <= m_unVertices; i++) {
217 glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
218 cVertex.Rotate(cAngle);
226 void CQTOpenGLSpiri::MakeCylinderSurface(GLfloat f_radius,
228 CVector2 cVertex(f_radius, 0.0f);
230 glEnable(GL_NORMALIZE);
231 glBegin(GL_QUAD_STRIP);
232 for(GLuint i = 0; i <= m_unVertices; i++) {
233 glNormal3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
234 glVertex3f(cVertex.GetX(), cVertex.GetY(), f_height);
235 glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
236 cVertex.Rotate(cAngle);
239 glDisable(GL_NORMALIZE);
245 void CQTOpenGLSpiri::MakeCylinder(GLfloat f_radius,
249 MakeCylinderSurface(f_radius, f_height);
250 glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
258 void CQTOpenGLSpiri::MakeBox(GLfloat f_length,
261 glEnable(GL_NORMALIZE);
263 glScalef(f_length, f_width, f_height);
267 glNormal3f(0.0f, 0.0f, -1.0f);
268 glVertex3f( 0.5f, 0.5f, 0.0f);
269 glVertex3f( 0.5f, -0.5f, 0.0f);
270 glVertex3f(-0.5f, -0.5f, 0.0f);
271 glVertex3f(-0.5f, 0.5f, 0.0f);
273 glNormal3f(0.0f, 0.0f, 1.0f);
274 glVertex3f(-0.5f, -0.5f, 1.0f);
275 glVertex3f( 0.5f, -0.5f, 1.0f);
276 glVertex3f( 0.5f, 0.5f, 1.0f);
277 glVertex3f(-0.5f, 0.5f, 1.0f);
282 glNormal3f(0.0f, -1.0f, 0.0f);
283 glVertex3f(-0.5f, -0.5f, 1.0f);
284 glVertex3f(-0.5f, -0.5f, 0.0f);
285 glVertex3f( 0.5f, -0.5f, 0.0f);
286 glVertex3f( 0.5f, -0.5f, 1.0f);
288 glNormal3f(1.0f, 0.0f, 0.0f);
289 glVertex3f( 0.5f, -0.5f, 1.0f);
290 glVertex3f( 0.5f, -0.5f, 0.0f);
291 glVertex3f( 0.5f, 0.5f, 0.0f);
292 glVertex3f( 0.5f, 0.5f, 1.0f);
294 glNormal3f(0.0f, 1.0f, 0.0f);
295 glVertex3f( 0.5f, 0.5f, 1.0f);
296 glVertex3f( 0.5f, 0.5f, 0.0f);
297 glVertex3f(-0.5f, 0.5f, 0.0f);
298 glVertex3f(-0.5f, 0.5f, 1.0f);
300 glNormal3f(-1.0f, 0.0f, 0.0f);
301 glVertex3f(-0.5f, 0.5f, 1.0f);
302 glVertex3f(-0.5f, 0.5f, 0.0f);
303 glVertex3f(-0.5f, -0.5f, 0.0f);
304 glVertex3f(-0.5f, -0.5f, 1.0f);
308 glDisable(GL_NORMALIZE);
321 m_cModel.
Draw(c_entity);