ARGoS 3
A parallel, multi-engine simulator for swarm robotics
qtopengl_light.cpp
Go to the documentation of this file.
1
7#include "qtopengl_light.h"
8#include <argos3/core/utility/math/vector3.h>
9#include <argos3/plugins/simulator/entities/light_entity.h>
10#include <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_widget.h>
11
12namespace argos {
13
14 /****************************************/
15 /****************************************/
16
18 m_unVertexes(20),
19 m_fRadius(0.1f) {
20 /* Reserve a display list */
21 m_unList = glGenLists(1);
22
23 /* Start the display list */
24 glNewList(m_unList, GL_COMPILE);
25
26 /* Let's start the actual shape, a sphere */
27 CVector3 cNormal, cPoint;
28 CRadians cSlice(CRadians::TWO_PI / m_unVertexes);
29
30 glBegin(GL_TRIANGLE_STRIP);
31 for(CRadians cInclination; cInclination <= CRadians::PI; cInclination += cSlice) {
32 for(CRadians cAzimuth; cAzimuth <= CRadians::TWO_PI; cAzimuth += cSlice) {
33
34 cNormal.FromSphericalCoords(1.0f, cInclination, cAzimuth);
35 cPoint = m_fRadius * cNormal;
36 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
37 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
38
39 cNormal.FromSphericalCoords(1.0f, cInclination + cSlice, cAzimuth);
40 cPoint = m_fRadius * cNormal;
41 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
42 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
43
44 cNormal.FromSphericalCoords(1.0f, cInclination, cAzimuth + cSlice);
45 cPoint = m_fRadius * cNormal;
46 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
47 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
48
49 cNormal.FromSphericalCoords(1.0f, cInclination + cSlice, cAzimuth + cSlice);
50 cPoint = m_fRadius * cNormal;
51 glNormal3d(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
52 glVertex3d(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
53
54 }
55 }
56 glEnd();
57
58 /* End of the display list */
59 glEndList();
60 }
61
62 /****************************************/
63 /****************************************/
64
66 glDeleteLists(m_unList, 1);
67 }
68
69 /****************************************/
70 /****************************************/
71
73 /* Set the material */
74 const CColor& cColor = c_entity.GetColor();
75 const GLfloat pfColor[] = { cColor.GetRed() / 255.0f,
76 cColor.GetGreen() / 255.0f,
77 cColor.GetBlue() / 255.0f,
78 1.0f };
79 const GLfloat pfSpecular[] = { 0.0f, 0.0f, 0.0f, 1.0f };
80 const GLfloat pfShininess[] = { 100.0f };
81 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
82 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
83 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
84 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
85 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
86
87 glCallList(m_unList);
88 }
89
90 /****************************************/
91 /****************************************/
92
94 public:
95 void ApplyTo(CQTOpenGLWidget& c_visualization,
96 CLightEntity& c_entity) {
97 static CQTOpenGLLight m_cModel;
98 c_visualization.DrawEntity(c_entity);
99 m_cModel.Draw(c_entity);
100 }
101 };
102
104 public:
105 void ApplyTo(CQTOpenGLWidget& c_visualization,
106 CLightEntity& c_entity) {
107 static CQTOpenGLLight m_cModel;
108 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
109 c_visualization.DrawEntity(c_entity);
110 glScaled(1.1, 1.1, 1.1);
111 m_cModel.Draw(c_entity);
112 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
113 }
114 };
115
117
119
120 /****************************************/
121 /****************************************/
122
123}
#define REGISTER_QTOPENGL_ENTITY_OPERATION(ACTION, OPERATION, ENTITY)
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
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
It defines the basic type CRadians, used to store an angle value in radians.
Definition angles.h:42
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
CVector3 & FromSphericalCoords(Real f_length, const CRadians &c_inclination, const CRadians &c_azimuth)
Sets the vector contents from spherical coordinates.
Definition vector3.h:180
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
const CColor & GetColor() const
Returns the current color of the LED.
Definition led_entity.h:58
void ApplyTo(CQTOpenGLWidget &c_visualization, CLightEntity &c_entity)
void ApplyTo(CQTOpenGLWidget &c_visualization, CLightEntity &c_entity)
virtual void Draw(CLightEntity &c_entity)
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.