23 static void Rototranslate(
const CVector3& c_position,
24 const CQuaternion& c_orientation) {
26 CRadians cZAngle, cYAngle, cXAngle;
27 c_orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
29 glTranslatef(c_position.GetX(), c_position.GetY(), c_position.GetZ());
31 glRotatef(
ToDegrees(cXAngle).GetValue(), 1.0f, 0.0f, 0.0f);
32 glRotatef(
ToDegrees(cYAngle).GetValue(), 0.0f, 1.0f, 0.0f);
33 glRotatef(
ToDegrees(cZAngle).GetValue(), 0.0f, 0.0f, 1.0f);
40 m_vecFunctionHolders(1),
41 m_pcQTOpenGLMainWindow(NULL) {
94 return *m_pcQTOpenGLMainWindow;
101 m_pcQTOpenGLMainWindow = &c_main_win;
115 const GLfloat pfColor[] = {
116 c_color.
GetRed() / 255.0f,
121 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, DEFAULT_SPECULAR);
122 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, DEFAULT_SHININESS);
123 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, DEFAULT_EMISSION);
124 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
132 const Real f_diameter) {
134 glPushAttrib(GL_POINT_BIT);
138 glPointSize(f_diameter);
139 glEnable(GL_POINT_SMOOTH);
142 glVertex3f(c_position.
GetX(), c_position.
GetY(), c_position.
GetZ());
158 glPushAttrib(GL_POLYGON_BIT);
163 glDisable(GL_CULL_FACE);
165 glEnable(GL_POLYGON_SMOOTH);
166 glPolygonMode(GL_FRONT_AND_BACK, b_fill ? GL_FILL : GL_LINE);
168 Rototranslate(c_position, c_orientation);
170 glBegin(GL_TRIANGLES);
171 glNormal3f(0.0f, 0.0f, 1.0f);
172 glVertex3f(-f_base * 0.5f, 0.0f, 0.0f);
173 glVertex3f( f_base * 0.5f, 0.0f, 0.0f);
174 glVertex3f( 0.0f, f_height, 0.0f);
186 const std::vector<CVector2>& vec_points,
189 if(vec_points.size() < 2) {
190 LOGERR <<
"CQTOpenGLUserFunctions::DrawPolygon() needs at least 3 points." << std::endl;
194 glPushAttrib(GL_POLYGON_BIT);
198 glDisable(GL_CULL_FACE);
200 glEnable(GL_POLYGON_SMOOTH);
201 glPolygonMode(GL_FRONT_AND_BACK, b_fill ? GL_FILL : GL_LINE);
203 Rototranslate(c_position, c_orientation);
206 glNormal3f(0.0f, 0.0f, 1.0f);
207 for(
size_t i = 0; i < vec_points.size(); ++i) {
208 glVertex3f(vec_points[i].GetX(), vec_points[i].GetY(), 0.0f);
212 glTranslatef(-c_position.
GetX(), -c_position.
GetY(), -c_position.
GetZ());
225 GLuint un_vertices) {
227 glPushAttrib(GL_POLYGON_BIT);
232 glDisable(GL_CULL_FACE);
234 glEnable(GL_POLYGON_SMOOTH);
235 glPolygonMode(GL_FRONT_AND_BACK, b_fill ? GL_FILL : GL_LINE);
237 Rototranslate(c_position, c_orientation);
242 glNormal3f(0.0f, 0.0f, 1.0f);
243 for(
size_t i = 0; i < un_vertices; ++i) {
244 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), 0.0f);
261 GLuint un_vertices) {
267 Rototranslate(c_position, c_orientation);
269 Real fHalfHeight = f_height * 0.5f;
272 glBegin(GL_QUAD_STRIP);
273 for(GLuint i = 0; i <= un_vertices; i++) {
274 glNormal3f(cVertex.
GetX(), cVertex.
GetY(), 0.0f);
275 glVertex3f(cVertex.
GetX() * f_radius, cVertex.
GetY() * f_radius, fHalfHeight);
276 glVertex3f(cVertex.
GetX() * f_radius, cVertex.
GetY() * f_radius, -fHalfHeight);
281 cVertex.
Set(f_radius, 0.0f);
283 glNormal3f(0.0f, 0.0f, 1.0f);
284 for(GLuint i = 0; i <= un_vertices; i++) {
285 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), fHalfHeight);
290 cVertex.
Set(f_radius, 0.0f);
293 glNormal3f(0.0f, 0.0f, -1.0f);
294 for(GLuint i = 0; i <= un_vertices; i++) {
295 glVertex3f(cVertex.
GetX(), cVertex.
GetY(), -fHalfHeight);
315 Rototranslate(c_position, c_orientation);
320 glNormal3f(0.0f, 0.0f, -1.0f);
321 glVertex3f( cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
322 glVertex3f( cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
323 glVertex3f(-cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
324 glVertex3f(-cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
326 glNormal3f(0.0f, 0.0f, 1.0f);
327 glVertex3f(-cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
328 glVertex3f( cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
329 glVertex3f( cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
330 glVertex3f(-cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
335 glNormal3f(1.0f, 0.0f, 0.0f);
336 glVertex3f( cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
337 glVertex3f( cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
338 glVertex3f( cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
339 glVertex3f( cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
341 glNormal3f(-1.0f, 0.0f, 0.0f);
342 glVertex3f(-cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
343 glVertex3f(-cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
344 glVertex3f(-cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
345 glVertex3f(-cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
347 glNormal3f(0.0f, -1.0f, 0.0f);
348 glVertex3f(-cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
349 glVertex3f( cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
350 glVertex3f( cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
351 glVertex3f(-cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
353 glNormal3f(0.0f, 1.0f, 0.0f);
354 glVertex3f(-cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
355 glVertex3f(-cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
356 glVertex3f( cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
357 glVertex3f( cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
370 glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
372 glEnable(GL_LINE_SMOOTH);
373 glLineWidth(f_width);
375 glDisable(GL_LIGHTING);
376 glDisable(GL_COLOR_MATERIAL);
391 static void TransformPoint(
Real* pf_vec_out,
392 const Real* pf_trans,
393 const Real* pf_vec_in) {
394 #define M(row,col) pf_trans[col * 4 + row]
396 M(0, 0) * pf_vec_in[0] +
397 M(0, 1) * pf_vec_in[1] +
398 M(0, 2) * pf_vec_in[2] +
399 M(0, 3) * pf_vec_in[3];
401 M(1, 0) * pf_vec_in[0] +
402 M(1, 1) * pf_vec_in[1] +
403 M(1, 2) * pf_vec_in[2] +
404 M(1, 3) * pf_vec_in[3];
406 M(2, 0) * pf_vec_in[0] +
407 M(2, 1) * pf_vec_in[1] +
408 M(2, 2) * pf_vec_in[2] +
409 M(2, 3) * pf_vec_in[3];
411 M(3, 0) * pf_vec_in[0] +
412 M(3, 1) * pf_vec_in[1] +
413 M(3, 2) * pf_vec_in[2] +
414 M(3, 3) * pf_vec_in[3];
422 const std::string& str_text,
424 const QFont& c_font) {
427 glGetDoublev(GL_MODELVIEW_MATRIX, pf_mv);
429 GLdouble pf_proj[16];
430 glGetDoublev(GL_PROJECTION_MATRIX, pf_proj);
433 glGetIntegerv(GL_VIEWPORT, pn_vp);
435 GLdouble pf_v1[4], pf_v2[4];
437 pf_v1[0] = c_position.
GetX();
438 pf_v1[1] = c_position.
GetY();
439 pf_v1[2] = c_position.
GetZ();
441 TransformPoint(pf_v2, pf_mv, pf_v1);
443 TransformPoint(pf_v1, pf_proj, pf_v2);
445 if (pf_v1[3] == 0.0)
return;
447 pf_v1[0] /= pf_v1[3];
448 pf_v1[1] /= pf_v1[3];
451 (pn_vp[0] + (1. + pf_v1[0]) * pn_vp[2] / 2.) /
454 (pn_vp[1] + (1. + pf_v1[1]) * pn_vp[3] / 2.) /
459 glPushAttrib(GL_ENABLE_BIT);
461 glDisable(GL_LIGHTING);
462 glDisable(GL_COLOR_MATERIAL);
464 glDisable(GL_CULL_FACE);
468 cPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
476 cPainter.setFont(c_font);
478 cPainter.drawText(pf_v2[0], pf_v2[1], str_text.c_str());
490 if(t_thunk) (this->*t_thunk)(c_entity);
void DrawBox(const CVector3 &c_position, const CQuaternion &c_orientation, const CVector3 &c_size, const CColor &c_color=CColor::RED)
Draws a box.
void DrawPoint(const CVector3 &c_position, const CColor &c_color=CColor::RED, Real f_diameter=5.0)
Draws a point.
CQTOpenGLWidget & GetQTOpenGLWidget()
Returns the QTOpenGLWidget.
const GLfloat DEFAULT_SHININESS[]
void(CQTOpenGLUserFunctions::* TThunk)(CEntity &)
Pointer-to-thunk type definition.
CDegrees ToDegrees(const CRadians &c_radians)
Converts CRadians to CDegrees.
float Real
Collects all ARGoS code.
Real GetX() const
Returns the x coordinate of this vector.
CQTOpenGLWidget & GetOpenGLWidget()
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.
std::vector< CFunctionHolder * > m_vecFunctionHolders
A vector of function holders.
UInt8 GetGreen() const
Returns the green channel of the color.
void SetMainWindow(CQTOpenGLMainWindow &c_main_win)
Sets the QTOpenGL main window for these user functions.
Real GetY() const
Returns the y coordinate of this vector.
void KeyPressed(QKeyEvent *pc_event)
Handles key press events.
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL if none is selected.
virtual void SelectEntity(CEntity &c_entity)
Selects the specified entity.
It defines the basic type CRadians, used to store an angle value in radians.
void DrawRay(const CRay3 &c_ray, const CColor &c_color=CColor::RED, Real f_width=1.0f)
Draws a ray, with optional endpoint markers.
void SetColor(const CColor &c_color)
Sets the current drawing color.
void DrawCircle(const CVector3 &c_position, const CQuaternion &c_orientation, Real f_radius, const CColor &c_color=CColor::RED, const bool b_fill=true, GLuint un_vertices=20)
Draws a circle.
void KeyReleased(QKeyEvent *pc_event)
Handles key release events.
const GLfloat DEFAULT_EMISSION[]
void SelectEntity(CEntity &c_entity)
Selects the passed entity.
virtual void Call(CEntity &c_entity)
Calls a user method for the given entity.
void DeselectEntity()
Deselects the currently selected entity.
void DrawText(const CVector3 &c_position, const std::string &str_text, const CColor &c_color=CColor::BLACK, const QFont &c_font=QFont())
Draws a string of text.
virtual ~CQTOpenGLUserFunctions()
Class destructor.
UInt8 GetRed() const
Returns the red channel of the color.
void DrawTriangle(const CVector3 &c_position, const CQuaternion &c_orientation, Real f_base, Real f_height, const CColor &c_color=CColor::RED, const bool b_fill=true)
Draws an isosceles triangle.
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
virtual void DeselectEntity()
Deselects the currently selected entity.
void DrawPolygon(const CVector3 &c_position, const CQuaternion &c_orientation, const std::vector< CVector2 > &vec_points, const CColor &c_color=CColor::RED, const bool b_fill=true)
Draws a 2D polygon.
const GLfloat DEFAULT_SPECULAR[]
virtual void KeyPressed(QKeyEvent *pc_event)
Called when a key press event occurs.
CQTOpenGLUserFunctions()
Class constructor.
UInt8 GetAlpha() const
Returns the alpha channel of the color.
CQTOpenGLMainWindow & GetMainWindow()
Returns the QTOpenGL main window.
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL.
virtual void KeyReleased(QKeyEvent *pc_event)
Called when a key release event occurs.
UInt8 GetBlue() const
Returns the blue channel of the color.
void Set(Real f_x, Real f_y)
Sets the vector contents from Cartesian coordinates.
The namespace containing all the ARGoS related code.
Real GetZ() const
Returns the z coordinate of this vector.
void DrawCylinder(const CVector3 &c_position, const CQuaternion &c_orientation, Real f_radius, Real f_height, const CColor &c_color=CColor::RED, GLuint un_vertices=20)
Draws a cylinder, with the height perpendicular to the XY plane.
CVector2 & Rotate(const CRadians &c_angle)
Rotates this vector by the wanted angle.
CVTable< CQTOpenGLUserFunctions, CEntity, TThunk > m_cThunks
The vtable storing the thunks.