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 glTranslated(0.0f, HALF_INTERWHEEL_DISTANCE, 0.0f);
95 glCallList(m_unWheelList);
98 glTranslated(0.0f, -HALF_INTERWHEEL_DISTANCE, 0.0f);
99 glCallList(m_unWheelList);
104 for(
UInt32 i = 0; i < 8; i++) {
106 glRotated(-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 glNormal3d(cNormal.
GetX(), cNormal.
GetY(), cNormal.
GetZ());
187 glVertex3d(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 glNormal3d(cNormal.
GetX(), cNormal.
GetY(), cNormal.
GetZ());
200 glVertex3d(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 glNormal3d(cNormal.
GetX(), cNormal.
GetY(), cNormal.
GetZ());
212 glVertex3d(cVertex.
GetX(), -HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.
GetY());
213 glVertex3d(cVertex.
GetX(), HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.
GetY());
229 glNormal3d(0.0f, 0.0f, -1.0f);
230 glVertex3d( HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
231 glVertex3d( HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
232 glVertex3d(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
233 glVertex3d(-HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
236 glBegin(GL_QUAD_STRIP);
238 glNormal3d(-1.0f, 0.0f, 0.0f);
239 glVertex3d(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
240 glVertex3d(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
242 glVertex3d( HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
243 glVertex3d( HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
245 glNormal3d(0.0f, -1.0f, 0.0f);
246 glVertex3d( HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
247 glVertex3d( HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
249 glNormal3d(1.0f, 0.0f, 0.0f);
250 glVertex3d(-HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
251 glVertex3d(-HALF_CHASSIS_LENGTH, HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
253 glNormal3d(0.0f, 1.0f, 0.0f);
254 glVertex3d(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION + WHEEL_DIAMETER);
255 glVertex3d(-HALF_CHASSIS_LENGTH, -HALF_CHASSIS_WIDTH, CHASSIS_ELEVATION);
265 CVector2 cVertex(BODY_RADIUS, 0.0f);
269 glNormal3d(0.0f, 0.0f, -1.0f);
270 for(GLuint i = 0; i <= m_unVertices; i++) {
271 glVertex3d(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 glNormal3d(cNormal.
GetX(), cNormal.
GetY(), 0.0f);
282 glVertex3d(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION + BODY_HEIGHT);
283 glVertex3d(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION);
290 cVertex.
Set(LED_UPPER_RING_INNER_RADIUS, 0.0f);
291 glNormal3d(0.0f, 0.0f, 1.0f);
292 for(GLuint i = 0; i <= m_unVertices; i++) {
293 glVertex3d(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
299 glBegin(GL_TRIANGLES);
300 glVertex3d( BODY_RADIUS * 0.7, 0.0f, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
301 glVertex3d(-BODY_RADIUS * 0.7, BODY_RADIUS * 0.3, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
302 glVertex3d(-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 glNormal3d(cNormal.
GetX(), cNormal.
GetY(), 0.0f);
317 glVertex3d(cVertex.
GetX(), cVertex.
GetY(), LED_ELEVATION + LED_HEIGHT);
318 glVertex3d(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 glNormal3d(0.0f, 0.0f, 1.0f);
328 for(GLuint i = 0; i <= m_unVertices / 8; i++) {
329 glVertex3d(cVertex2.
GetX(), cVertex2.
GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
330 glVertex3d(cVertex.
GetX(), cVertex.
GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
347 m_cModel.
Draw(c_entity);
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
REGISTER_QTOPENGL_ENTITY_OPERATION(CQTOpenGLOperationDrawNormal, CQTOpenGLOperationDrawEPuckNormal, CEPuckEntity)
UInt8 GetBlue() const
Returns the blue channel of the color.
UInt8 GetGreen() const
Returns the green channel of the color.
UInt8 GetRed() const
Returns the red channel of the color.
It defines the basic type CRadians, used to store an angle value in radians.
static const CRadians TWO_PI
Set to PI * 2.
Real GetY() const
Returns the y coordinate of this vector.
CVector2 & Rotate(const CRadians &c_angle)
Rotates this vector by the wanted angle.
void Set(Real f_x, Real f_y)
Sets the vector contents from Cartesian coordinates.
Real GetX() const
Returns the x coordinate of this vector.
Real GetX() const
Returns the x coordinate of this vector.
CVector3 & Normalize()
Normalizes this vector.
void Set(const Real f_x, const Real f_y, const Real f_z)
Sets the vector contents from Cartesian coordinates.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.
CVector3 & RotateY(const CRadians &c_angle)
Rotates this vector wrt the y axis.
CLEDEquippedEntity & GetLEDEquippedEntity()
CControllableEntity & GetControllableEntity()
CEmbodiedEntity & GetEmbodiedEntity()
void ApplyTo(CQTOpenGLWidget &c_visualization, CEPuckEntity &c_entity)
void ApplyTo(CQTOpenGLWidget &c_visualization, CEPuckEntity &c_entity)
void SetLEDMaterial(GLfloat f_red, GLfloat f_green, GLfloat f_blue)
Sets a colored LED material.
virtual ~CQTOpenGLEPuck()
void SetCircuitBoardMaterial()
Sets a circuit board material.
void RenderChassis()
Renders the chassis.
void SetGreenPlasticMaterial()
Sets a green plastic material.
void RenderLED()
A single LED of the ring.
void RenderBody()
Renders the body.
virtual void Draw(CEPuckEntity &c_entity)
void RenderWheel()
Renders a wheel.
void SetRedPlasticMaterial()
Sets a red plastic material.
const CColor & GetColor() const
Returns the current color of the LED.
A container of CLEDEntity.
CLEDEntity & GetLED(UInt32 un_index)
Returns an LED by numeric index.
void DrawRays(CControllableEntity &c_entity)
Draws a ray.
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
void DrawBoundingBox(CEmbodiedEntity &c_entity)
Draws the bounding box of an embodied entity.