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 glTranslated(c_position.GetX(), c_position.GetY(), c_position.GetZ());
31 glRotated(
ToDegrees(cXAngle).GetValue(), 1.0f, 0.0f, 0.0f);
32 glRotated(
ToDegrees(cYAngle).GetValue(), 0.0f, 1.0f, 0.0f);
33 glRotated(
ToDegrees(cZAngle).GetValue(), 0.0f, 0.0f, 1.0f);
40 m_vecFunctionHolders(1),
41 m_pcQTOpenGLMainWindow(nullptr) {
94 return *m_pcQTOpenGLMainWindow;
101 m_pcQTOpenGLMainWindow = &c_main_win;
115 const GLfloat pfColor[] = {
116 c_color.
GetRed() / 255.0f,
124 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor);
132 const Real f_diameter) {
134 glPushAttrib(GL_POINT_BIT);
138 glPointSize(
static_cast<GLfloat
>(f_diameter));
139 glEnable(GL_POINT_SMOOTH);
142 glVertex3d(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 glNormal3d(0.0f, 0.0f, 1.0f);
172 glVertex3d(-f_base * 0.5f, 0.0f, 0.0f);
173 glVertex3d( f_base * 0.5f, 0.0f, 0.0f);
174 glVertex3d( 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 glNormal3d(0.0f, 0.0f, 1.0f);
207 for(
size_t i = 0; i < vec_points.size(); ++i) {
208 glVertex3d(vec_points[i].GetX(), vec_points[i].GetY(), 0.0f);
212 glTranslated(-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 glNormal3d(0.0f, 0.0f, 1.0f);
243 for(
size_t i = 0; i < un_vertices; ++i) {
244 glVertex3d(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 glNormal3d(cVertex.
GetX(), cVertex.
GetY(), 0.0f);
275 glVertex3d(cVertex.
GetX() * f_radius, cVertex.
GetY() * f_radius, fHalfHeight);
276 glVertex3d(cVertex.
GetX() * f_radius, cVertex.
GetY() * f_radius, -fHalfHeight);
281 cVertex.
Set(f_radius, 0.0f);
283 glNormal3d(0.0f, 0.0f, 1.0f);
284 for(GLuint i = 0; i <= un_vertices; i++) {
285 glVertex3d(cVertex.
GetX(), cVertex.
GetY(), fHalfHeight);
290 cVertex.
Set(f_radius, 0.0f);
293 glNormal3d(0.0f, 0.0f, -1.0f);
294 for(GLuint i = 0; i <= un_vertices; i++) {
295 glVertex3d(cVertex.
GetX(), cVertex.
GetY(), -fHalfHeight);
315 Rototranslate(c_position, c_orientation);
320 glNormal3d(0.0f, 0.0f, -1.0f);
321 glVertex3d( cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
322 glVertex3d( cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
323 glVertex3d(-cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
324 glVertex3d(-cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
326 glNormal3d(0.0f, 0.0f, 1.0f);
327 glVertex3d(-cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
328 glVertex3d( cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
329 glVertex3d( cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
330 glVertex3d(-cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
335 glNormal3d(1.0f, 0.0f, 0.0f);
336 glVertex3d( cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
337 glVertex3d( cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
338 glVertex3d( cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
339 glVertex3d( cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
341 glNormal3d(-1.0f, 0.0f, 0.0f);
342 glVertex3d(-cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
343 glVertex3d(-cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
344 glVertex3d(-cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
345 glVertex3d(-cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
347 glNormal3d(0.0f, -1.0f, 0.0f);
348 glVertex3d(-cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
349 glVertex3d( cHalfSize.
GetX(), -cHalfSize.
GetY(), -cHalfSize.
GetZ());
350 glVertex3d( cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
351 glVertex3d(-cHalfSize.
GetX(), -cHalfSize.
GetY(), cHalfSize.
GetZ());
353 glNormal3d(0.0f, 1.0f, 0.0f);
354 glVertex3d(-cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
355 glVertex3d(-cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
356 glVertex3d( cHalfSize.
GetX(), cHalfSize.
GetY(), cHalfSize.
GetZ());
357 glVertex3d( cHalfSize.
GetX(), cHalfSize.
GetY(), -cHalfSize.
GetZ());
370 glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
372 glEnable(GL_LINE_SMOOTH);
373 glLineWidth(
static_cast<GLfloat
>(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(
static_cast<UInt32>(pf_v2[0]),
479 static_cast<UInt32>(pf_v2[1]),
492 if(t_thunk) (this->*t_thunk)(c_entity);
unsigned int UInt32
32-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
CARGoSLog LOGERR(std::cerr, SLogColor(ARGOS_LOG_ATTRIBUTE_BRIGHT, ARGOS_LOG_COLOR_RED))
const GLfloat DEFAULT_SPECULAR[]
CDegrees ToDegrees(const CRadians &c_radians)
Converts CRadians to CDegrees.
const GLfloat DEFAULT_EMISSION[]
const GLfloat DEFAULT_SHININESS[]
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.
UInt8 GetAlpha() const
Returns the alpha 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.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.
CQTOpenGLWidget & GetOpenGLWidget()
CQTOpenGLUserFunctions()
Class constructor.
std::vector< CFunctionHolder * > m_vecFunctionHolders
A vector of function holders.
void SetColor(const CColor &c_color)
Sets the current drawing color.
void SetMainWindow(CQTOpenGLMainWindow &c_main_win)
Sets the QTOpenGL main window for these user functions.
CVTable< CQTOpenGLUserFunctions, CEntity, TThunk > m_cThunks
The vtable storing the thunks.
void DrawPoint(const CVector3 &c_position, const CColor &c_color=CColor::RED, Real f_diameter=5.0)
Draws a point.
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.
virtual void SelectEntity(CEntity &c_entity)
Selects the specified entity.
virtual void KeyPressed(QKeyEvent *pc_event)
Called when a key press event occurs.
virtual ~CQTOpenGLUserFunctions()
Class destructor.
CQTOpenGLMainWindow & GetMainWindow()
Returns the QTOpenGL main window.
virtual void KeyReleased(QKeyEvent *pc_event)
Called when a key release event occurs.
virtual void Call(CEntity &c_entity)
Calls a user method for the given 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.
void DrawBox(const CVector3 &c_position, const CQuaternion &c_orientation, const CVector3 &c_size, const CColor &c_color=CColor::RED)
Draws a box.
CQTOpenGLWidget & GetQTOpenGLWidget()
Returns the QTOpenGLWidget.
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.
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.
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL.
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(CQTOpenGLUserFunctions::* TThunk)(CEntity &)
Pointer-to-thunk type definition.
void DrawRay(const CRay3 &c_ray, const CColor &c_color=CColor::RED, Real f_width=1.0f)
Draws a ray, with optional endpoint markers.
virtual void DeselectEntity()
Deselects the currently selected entity.
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL if none is selected.
void KeyPressed(QKeyEvent *pc_event)
Handles key press events.
void SelectEntity(CEntity &c_entity)
Selects the passed entity.
void KeyReleased(QKeyEvent *pc_event)
Handles key release events.
void DeselectEntity()
Deselects the currently selected entity.