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>
22 static const Real WHEEL_DIAMETER = 0.041f;
23 static const Real WHEEL_RADIUS = WHEEL_DIAMETER * 0.5f;
24 static const Real WHEEL_WIDTH = 0.01f;
25 static const Real HALF_WHEEL_WIDTH = WHEEL_WIDTH * 0.5f;
26 static const Real INTERWHEEL_DISTANCE = 0.053f;
27 static const Real HALF_INTERWHEEL_DISTANCE = INTERWHEEL_DISTANCE * 0.5f;
29 static const Real CHASSIS_ELEVATION = 0.005f;
30 static const Real HALF_CHASSIS_LENGTH = 0.0275f;
31 static const Real HALF_CHASSIS_WIDTH = HALF_INTERWHEEL_DISTANCE - HALF_WHEEL_WIDTH;
33 static const Real BODY_RADIUS = 0.035f;
34 static const Real BODY_ELEVATION = WHEEL_DIAMETER + CHASSIS_ELEVATION;
35 static const Real BODY_HEIGHT = 0.03f;
37 static const Real LED_ELEVATION = BODY_ELEVATION + BODY_HEIGHT;
38 static const Real LED_HEIGHT = 0.01;
39 static const Real LED_UPPER_RING_INNER_RADIUS = 0.8 * BODY_RADIUS;
46 m_fLEDAngleSlice(360.0f / 8.0f) {
48 m_unLists = glGenLists(4);
51 m_unWheelList = m_unLists;
52 m_unChassisList = m_unLists + 1;
53 m_unBodyList = m_unLists + 2;
54 m_unLEDList = m_unLists + 3;
57 glNewList(m_unWheelList, GL_COMPILE);
62 glNewList(m_unBodyList, GL_COMPILE);
67 glNewList(m_unChassisList, GL_COMPILE);
72 glNewList(m_unLEDList, GL_COMPILE);
81 glDeleteLists(m_unLists, 4);
89 glCallList(m_unChassisList);
91 glCallList(m_unBodyList);
94 glTranslatef(0.0f, HALF_INTERWHEEL_DISTANCE, 0.0f);
95 glCallList(m_unWheelList);
98 glTranslatef(0.0f, -HALF_INTERWHEEL_DISTANCE, 0.0f);
99 glCallList(m_unWheelList);
104 for(
UInt32 i = 0; i < 8; i++) {
106 glRotatef(-m_fLEDAngleSlice, 0.0f, 0.0f, 1.0f);
110 glCallList(m_unLEDList);
119 const GLfloat pfColor[] = { 0.0f, 1.0f, 0.0f, 1.0f };
120 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
121 const GLfloat pfShininess[] = { 100.0f };
122 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
123 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
124 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
125 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
126 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
133 const GLfloat pfColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
134 const GLfloat pfSpecular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
135 const GLfloat pfShininess[] = { 100.0f };
136 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
137 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
138 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
139 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
140 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
147 const GLfloat pfColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };
148 const GLfloat pfSpecular[] = { 0.5f, 0.5f, 1.0f, 1.0f };
149 const GLfloat pfShininess[] = { 10.0f };
150 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
151 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
152 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
153 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
154 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
163 const GLfloat pfColor[] = { f_red, f_green, f_blue, 1.0f };
164 const GLfloat pfSpecular[] = { 0.0f, 0.0f, 0.0f, 1.0f };
165 const GLfloat pfShininess[] = { 0.0f };
166 const GLfloat pfEmission[] = { f_red, f_green, f_blue, 1.0f };
167 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
168 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
169 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
170 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
180 CVector2 cVertex(WHEEL_RADIUS, 0.0f);
182 CVector3 cNormal(-1.0f, -1.0f, 0.0f);
185 for(GLuint i = 0; i <= m_unVertices; i++) {
186 glNormal3f(cNormal.
GetX(), cNormal.
GetY(), cNormal.
GetZ());
187 glVertex3f(cVertex.
GetX(), -HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.
GetY());
193 cVertex.
Set(WHEEL_RADIUS, 0.0f);
194 cNormal.
Set(-1.0f, 1.0f, 0.0f);
198 for(GLuint i = 0; i <= m_unVertices; i++) {
199 glNormal3f(cNormal.
GetX(), cNormal.
GetY(), cNormal.
GetZ());
200 glVertex3f(cVertex.
GetX(), HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.
GetY());
206 cNormal.
Set(1.0f, 0.0f, 0.0f);
207 cVertex.
Set(WHEEL_RADIUS, 0.0f);
209 glBegin(GL_QUAD_STRIP);
210 for(GLuint i = 0; i <= m_unVertices; i++) {
211 glNormal3f(cNormal.
GetX(), cNormal.
GetY(), cNormal.
GetZ());
212 glVertex3f(cVertex.
GetX(), -HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.
GetY());
213 glVertex3f(cVertex.
GetX(), HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.
GetY());
229 glNormal3f(0.0f, 0.0f, -1.0f);
230 glVertex3f( HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
231 glVertex3f( HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
232 glVertex3f(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
233 glVertex3f(-HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
236 glBegin(GL_QUAD_STRIP);
238 glNormal3f(-1.0f, 0.0f, 0.0f);
239 glVertex3f(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
240 glVertex3f(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
242 glVertex3f( HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
243 glVertex3f( HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
245 glNormal3f(0.0f, -1.0f, 0.0f);
246 glVertex3f( HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
247 glVertex3f( HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
249 glNormal3f(1.0f, 0.0f, 0.0f);
250 glVertex3f(-HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
251 glVertex3f(-HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
253 glNormal3f(0.0f, 1.0f, 0.0f);
254 glVertex3f(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
255 glVertex3f(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
265 CVector2 cVertex(BODY_RADIUS, 0.0f);
269 glNormal3f(0.0f, 0.0f, -1.0f);
270 for(GLuint i = 0; i <= m_unVertices; i++) {
271 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION);
278 cVertex.
Set(BODY_RADIUS, 0.0f);
279 glBegin(GL_QUAD_STRIP);
280 for(GLuint i = 0; i <= m_unVertices; i++) {
281 glNormal3f(cNormal.
GetX(), cNormal.
GetY(), 0.0f);
282 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION + BODY_HEIGHT);
283 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION);
290 cVertex.
Set(LED_UPPER_RING_INNER_RADIUS, 0.0f);
291 glNormal3f(0.0f, 0.0f, 1.0f);
292 for(GLuint i = 0; i <= m_unVertices; i++) {
293 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
299 glBegin(GL_TRIANGLES);
300 glVertex3f( BODY_RADIUS * 0.7, 0.0f, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
301 glVertex3f(-BODY_RADIUS * 0.7, BODY_RADIUS * 0.3, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
302 glVertex3f(-BODY_RADIUS * 0.7, -BODY_RADIUS * 0.3, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
311 CVector2 cVertex(BODY_RADIUS, 0.0f);
314 glBegin(GL_QUAD_STRIP);
315 for(GLuint i = 0; i <= m_unVertices / 8; i++) {
316 glNormal3f(cNormal.
GetX(), cNormal.
GetY(), 0.0f);
317 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), LED_ELEVATION + LED_HEIGHT);
318 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), LED_ELEVATION);
324 cVertex.
Set(BODY_RADIUS, 0.0f);
325 CVector2 cVertex2(LED_UPPER_RING_INNER_RADIUS, 0.0f);
326 glBegin(GL_QUAD_STRIP);
327 glNormal3f(0.0f, 0.0f, 1.0f);
328 for(GLuint i = 0; i <= m_unVertices / 8; i++) {
329 glVertex3f(cVertex2.
GetX(), cVertex2.
GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
330 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
347 m_cModel.
Draw(c_entity);
CLEDEntity & GetLED(UInt32 un_index)
Returns an LED by numeric index.
void RenderWheel()
Renders a wheel.
void RenderLED()
A single LED of the ring.
CVector3 & RotateY(const CRadians &c_angle)
Rotates this vector wrt the y axis.
float Real
Collects all ARGoS code.
Real GetX() const
Returns the x coordinate of this vector.
void SetRedPlasticMaterial()
Sets a red plastic material.
void ApplyTo(CQTOpenGLWidget &c_visualization, CEPuckEntity &c_entity)
Real GetX() const
Returns the x coordinate of this vector.
virtual ~CQTOpenGLEPuck()
void SetLEDMaterial(GLfloat f_red, GLfloat f_green, GLfloat f_blue)
Sets a colored LED material.
Real GetY() const
Returns the y coordinate of this vector.
static const CRadians TWO_PI
Set to PI * 2.
CEmbodiedEntity & GetEmbodiedEntity()
UInt8 GetGreen() const
Returns the green channel of the color.
const CColor & GetColor() const
Returns the current color of the LED.
Real GetY() const
Returns the y coordinate of this vector.
It defines the basic type CRadians, used to store an angle value in radians.
void SetCircuitBoardMaterial()
Sets a circuit board material.
unsigned int UInt32
32-bit unsigned integer.
A container of CLEDEntity.
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
void RenderBody()
Renders the body.
void ApplyTo(CQTOpenGLWidget &c_visualization, CEPuckEntity &c_entity)
CLEDEquippedEntity & GetLEDEquippedEntity()
UInt8 GetRed() const
Returns the red channel of the color.
virtual void Draw(CEPuckEntity &c_entity)
void SetGreenPlasticMaterial()
Sets a green plastic material.
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
void DrawBoundingBox(CEmbodiedEntity &c_entity)
Draws the bounding box of an embodied entity.
UInt8 GetBlue() const
Returns the blue channel of the color.
REGISTER_QTOPENGL_ENTITY_OPERATION(CQTOpenGLOperationDrawNormal, CQTOpenGLOperationDrawEPuckNormal, CEPuckEntity)
void Set(Real f_x, Real f_y)
Sets the vector contents from Cartesian coordinates.
void DrawRays(CControllableEntity &c_entity)
Draws a ray.
void RenderChassis()
Renders the chassis.
The namespace containing all the ARGoS related code.
Real GetZ() const
Returns the z coordinate of this vector.
CVector3 & Normalize()
Normalizes this vector.
CVector2 & Rotate(const CRadians &c_angle)
Rotates this vector by the wanted angle.
CControllableEntity & GetControllableEntity()