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/visualizations/qt-opengl/qtopengl_widget.h>
20 static const GLfloat SIDE = 0.470f;
21 static const GLfloat DIAGONAL = SIDE * ::sqrt(2);
22 static const GLfloat OUT_RADIUS = DIAGONAL / 5.0f;
23 static const GLfloat IN_RADIUS = OUT_RADIUS * 0.95f;
24 static const GLfloat HEIGHT = 0.090f;
26 static const GLfloat PROP_HEIGHT = HEIGHT / 2.0f;
27 static const GLfloat PROP_ELEVATION = HEIGHT - PROP_HEIGHT;
28 static const GLfloat PROP_ARM = DIAGONAL / 2.0f - OUT_RADIUS;
30 static const GLfloat LEG_RADIUS = OUT_RADIUS * 0.05f;
31 static const GLfloat LEG_HEIGHT = HEIGHT - PROP_HEIGHT;
33 static const GLfloat BODY_SIDE = OUT_RADIUS;
34 static const GLfloat BODY_HEIGHT = HEIGHT * 3.0f / 4.0f;
35 static const GLfloat BODY_ELEVATION = HEIGHT - BODY_HEIGHT;
43 m_unList = glGenLists(1);
44 glNewList(m_unList, GL_COMPILE);
53 glDeleteLists(m_unList, 1);
62 glPushAttrib(GL_LINE_BIT);
64 glEnable(GL_LINE_SMOOTH);
67 SetMainBodyMaterial();
71 glVertex3f(DIAGONAL,0,0);
80 void CQTOpenGLSpiri::SetPlasticMaterial() {
81 const GLfloat pfColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
82 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
83 const GLfloat pfShininess[] = { 100.0f };
84 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
85 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
86 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
87 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
88 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
94 void CQTOpenGLSpiri::SetPropellerMaterial() {
95 const GLfloat pfColor[] = { 0.7f, 0.7f, 0.7f, 1.0f };
96 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
97 const GLfloat pfShininess[] = { 100.0f };
98 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
99 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
100 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
101 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
102 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
108 void CQTOpenGLSpiri::SetMainBodyMaterial() {
109 const GLfloat pfColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };
110 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
111 const GLfloat pfShininess[] = { 100.0f };
112 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
113 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
114 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
115 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
116 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
122 void CQTOpenGLSpiri::MakeModel() {
124 glRotatef(45.0f, 0.0f, 0.0f, 1.0f);
128 glTranslatef(PROP_ARM, 0.0f, 0.0f);
131 glTranslatef(-PROP_ARM, PROP_ARM, 0.0f);
134 glTranslatef(-PROP_ARM, -PROP_ARM, 0.0f);
137 glTranslatef(PROP_ARM, -PROP_ARM, 0.0f);
139 glTranslatef(0.0f, PROP_ARM, 0.0f);
146 void CQTOpenGLSpiri::MakePropeller() {
148 SetPlasticMaterial();
152 MakeCylinder(LEG_RADIUS, LEG_HEIGHT);
157 glTranslatef(0.0f, 0.0f, PROP_ELEVATION);
159 MakeCylinderSurface(OUT_RADIUS, PROP_HEIGHT);
160 glCullFace(GL_FRONT);
161 MakeCylinderSurface(IN_RADIUS, PROP_HEIGHT);
164 glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
165 SetPlasticMaterial();
166 MakeRing(OUT_RADIUS, IN_RADIUS);
168 glRotatef(-180.0f, 1.0f, 0.0f, 0.0f);
169 glTranslatef(0.0f, 0.0f, PROP_HEIGHT / 2.0f);
170 SetPropellerMaterial();
173 glTranslatef(0.0f, 0.0f, PROP_HEIGHT / 2.0f);
174 SetPlasticMaterial();
175 MakeRing(OUT_RADIUS, IN_RADIUS);
182 void CQTOpenGLSpiri::MakeMainBody() {
184 SetMainBodyMaterial();
185 glTranslatef(0.0f, 0.0f, BODY_ELEVATION);
186 MakeBox(BODY_SIDE, BODY_SIDE, BODY_HEIGHT);
193 void CQTOpenGLSpiri::MakeRing(GLfloat f_out_radius,
194 GLfloat f_in_radius) {
195 CVector2 cVertex(1.0f, 0.0f);
197 glBegin(GL_QUAD_STRIP);
198 glNormal3f(0.0f, 0.0f, 1.0f);
199 for(GLuint i = 0; i <= m_unVertices; i++) {
200 glVertex3f(cVertex.GetX() * f_in_radius, cVertex.GetY() * f_in_radius, 0.0f);
201 glVertex3f(cVertex.GetX() * f_out_radius, cVertex.GetY() * f_out_radius, 0.0f);
202 cVertex.Rotate(cAngle);
210 void CQTOpenGLSpiri::MakeDisk(GLfloat f_radius) {
211 CVector2 cVertex(f_radius, 0.0f);
214 glNormal3f(0.0f, 0.0f, 1.0f);
215 for(GLuint i = 0; i <= m_unVertices; i++) {
216 glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
217 cVertex.Rotate(cAngle);
225 void CQTOpenGLSpiri::MakeCylinderSurface(GLfloat f_radius,
227 CVector2 cVertex(f_radius, 0.0f);
229 glEnable(GL_NORMALIZE);
230 glBegin(GL_QUAD_STRIP);
231 for(GLuint i = 0; i <= m_unVertices; i++) {
232 glNormal3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
233 glVertex3f(cVertex.GetX(), cVertex.GetY(), f_height);
234 glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
235 cVertex.Rotate(cAngle);
238 glDisable(GL_NORMALIZE);
244 void CQTOpenGLSpiri::MakeCylinder(GLfloat f_radius,
248 MakeCylinderSurface(f_radius, f_height);
249 glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
257 void CQTOpenGLSpiri::MakeBox(GLfloat f_length,
260 glEnable(GL_NORMALIZE);
262 glScalef(f_length, f_width, f_height);
266 glNormal3f(0.0f, 0.0f, -1.0f);
267 glVertex3f( 0.5f, 0.5f, 0.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);
272 glNormal3f(0.0f, 0.0f, 1.0f);
273 glVertex3f(-0.5f, -0.5f, 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);
281 glNormal3f(0.0f, -1.0f, 0.0f);
282 glVertex3f(-0.5f, -0.5f, 1.0f);
283 glVertex3f(-0.5f, -0.5f, 0.0f);
284 glVertex3f( 0.5f, -0.5f, 0.0f);
285 glVertex3f( 0.5f, -0.5f, 1.0f);
287 glNormal3f(1.0f, 0.0f, 0.0f);
288 glVertex3f( 0.5f, -0.5f, 1.0f);
289 glVertex3f( 0.5f, -0.5f, 0.0f);
290 glVertex3f( 0.5f, 0.5f, 0.0f);
291 glVertex3f( 0.5f, 0.5f, 1.0f);
293 glNormal3f(0.0f, 1.0f, 0.0f);
294 glVertex3f( 0.5f, 0.5f, 1.0f);
295 glVertex3f( 0.5f, 0.5f, 0.0f);
296 glVertex3f(-0.5f, 0.5f, 0.0f);
297 glVertex3f(-0.5f, 0.5f, 1.0f);
299 glNormal3f(-1.0f, 0.0f, 0.0f);
300 glVertex3f(-0.5f, 0.5f, 1.0f);
301 glVertex3f(-0.5f, 0.5f, 0.0f);
302 glVertex3f(-0.5f, -0.5f, 0.0f);
303 glVertex3f(-0.5f, -0.5f, 1.0f);
307 glDisable(GL_NORMALIZE);
320 m_cModel.
Draw(c_entity);
static const CRadians TWO_PI
Set to PI * 2.
void ApplyTo(CQTOpenGLWidget &c_visualization, CSpiriEntity &c_entity)
void ApplyTo(CQTOpenGLWidget &c_visualization, CSpiriEntity &c_entity)
CEmbodiedEntity & GetEmbodiedEntity()
virtual ~CQTOpenGLSpiri()
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
void DrawBoundingBox(CEmbodiedEntity &c_entity)
Draws the bounding box of an embodied entity.
CControllableEntity & GetControllableEntity()
REGISTER_QTOPENGL_ENTITY_OPERATION(CQTOpenGLOperationDrawNormal, CQTOpenGLOperationDrawEPuckNormal, CEPuckEntity)
void DrawRays(CControllableEntity &c_entity)
Draws a ray.
The namespace containing all the ARGoS related code.
virtual void Draw(CSpiriEntity &c_entity)