8 #include <argos3/core/utility/math/vector2.h>
9 #include <argos3/plugins/simulator/entities/led_equipped_entity.h>
10 #include <argos3/plugins/simulator/entities/cylinder_entity.h>
11 #include <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_widget.h>
18 static const Real LED_RADIUS = 0.01f;
21 const GLfloat
SPECULAR[] = { 0.0f, 0.0f, 0.0f, 1.0f };
23 const GLfloat
EMISSION[] = { 0.0f, 0.0f, 0.0f, 1.0f };
32 m_unBaseList = glGenLists(1);
33 m_unBodyList = m_unBaseList;
34 m_unLEDList = m_unBaseList + 1;
37 glNewList(m_unBodyList, GL_COMPILE);
42 glNewList(m_unLEDList, GL_COMPILE);
51 glDeleteLists(m_unBaseList, 2);
59 GLfloat pfColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
60 const GLfloat pfSpecular[] = { 0.0f, 0.0f, 0.0f, 1.0f };
61 const GLfloat pfShininess[] = { 100.0f };
62 const GLfloat pfEmission[] = { 0.0f, 0.0f, 0.0f, 1.0f };
63 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pfSpecular);
64 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, pfShininess);
65 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pfEmission);
67 for(
UInt32 i = 0; i < cLEDEquippedEntity.
GetLEDs().size(); ++i) {
71 pfColor[0] = cColor.
GetRed() / 255.0f;
72 pfColor[1] = cColor.
GetGreen() / 255.0f;
73 pfColor[2] = cColor.
GetBlue() / 255.0f;
74 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
77 glTranslatef(cPosition.
GetX(), cPosition.
GetY(), cPosition.
GetZ());
79 glCallList(m_unLEDList);
90 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, MOVABLE_COLOR);
93 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, NONMOVABLE_COLOR);
97 glCallList(m_unBodyList);
104 void CQTOpenGLCylinder::MakeBody() {
107 glEnable(GL_NORMALIZE);
110 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SPECULAR);
111 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, SHININESS);
112 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, EMISSION);
118 glBegin(GL_QUAD_STRIP);
119 for(GLuint i = 0; i <= m_unVertices; i++) {
120 glNormal3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
121 glVertex3f(cVertex.GetX(), cVertex.GetY(), 1.0f);
122 glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
123 cVertex.Rotate(cAngle);
127 cVertex.Set(1.0f, 0.0f);
129 glNormal3f(0.0f, 0.0f, 1.0f);
130 for(GLuint i = 0; i <= m_unVertices; i++) {
131 glVertex3f(cVertex.GetX(), cVertex.GetY(), 1.0f);
132 cVertex.Rotate(cAngle);
136 cVertex.Set(1.0f, 0.0f);
139 glNormal3f(0.0f, 0.0f, -1.0f);
140 for(GLuint i = 0; i <= m_unVertices; i++) {
141 glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
142 cVertex.Rotate(cAngle);
148 glDisable(GL_NORMALIZE);
155 void CQTOpenGLCylinder::MakeLED() {
156 CVector3 cNormal, cPoint;
159 glBegin(GL_TRIANGLE_STRIP);
160 for(CRadians cInclination; cInclination <=
CRadians::PI; cInclination += cSlice) {
163 cNormal.FromSphericalCoords(1.0f, cInclination, cAzimuth);
164 cPoint = LED_RADIUS * cNormal;
165 glNormal3f(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
166 glVertex3f(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
168 cNormal.FromSphericalCoords(1.0f, cInclination + cSlice, cAzimuth);
169 cPoint = LED_RADIUS * cNormal;
170 glNormal3f(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
171 glVertex3f(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
173 cNormal.FromSphericalCoords(1.0f, cInclination, cAzimuth + cSlice);
174 cPoint = LED_RADIUS * cNormal;
175 glNormal3f(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
176 glVertex3f(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
178 cNormal.FromSphericalCoords(1.0f, cInclination + cSlice, cAzimuth + cSlice);
179 cPoint = LED_RADIUS * cNormal;
180 glNormal3f(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
181 glVertex3f(cPoint.GetX(), cPoint.GetY(), cPoint.GetZ());
197 m_cModel.
Draw(c_entity);
CLEDEntity & GetLED(UInt32 un_index)
Returns an LED by numeric index.
const GLfloat SHININESS[]
virtual void Draw(CCylinderEntity &c_entity)
float Real
Collects all ARGoS code.
void ApplyTo(CQTOpenGLWidget &c_visualization, CCylinderEntity &c_entity)
Real GetX() const
Returns the x coordinate of this vector.
Real GetY() const
Returns the y coordinate of this vector.
static const CRadians TWO_PI
Set to PI * 2.
UInt8 GetGreen() const
Returns the green channel of the color.
const GLfloat MOVABLE_COLOR[]
const CColor & GetColor() const
Returns the current color of the LED.
void DrawLEDs(CCylinderEntity &c_entity)
It defines the basic type CRadians, used to store an angle value in radians.
const GLfloat NONMOVABLE_COLOR[]
unsigned int UInt32
32-bit unsigned integer.
A container of CLEDEntity.
virtual ~CQTOpenGLCylinder()
const CVector3 & GetLEDOffset(size_t un_idx) const
Returns the offset position of the given LED.
static const CRadians PI
The PI constant.
void ApplyTo(CQTOpenGLWidget &c_visualization, CCylinderEntity &c_entity)
CLEDEquippedEntity & GetLEDEquippedEntity()
UInt8 GetRed() const
Returns the red channel of the color.
SActuator::TList & GetLEDs()
Returns all the LEDs.
void DrawEntity(CPositionalEntity &c_entity)
Draws a positional entity.
CEmbodiedEntity & GetEmbodiedEntity()
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)
bool IsMovable() const
Returns true if the entity is movable.
The namespace containing all the ARGoS related code.
Real GetZ() const
Returns the z coordinate of this vector.