Roomba App  1.0
glWidget.hh
Go to the documentation of this file.
1 
15 #ifndef GLWIDGET_HH
16 #define GLWIDGET_HH
17 
18 #include <QGLViewer/qglviewer.h>
19 
20 #define PI 3.1415927f
21 
25 class GLWidget : public QGLViewer
26 {
27  public:
32  GLWidget(QWidget* parent);
33 
34  public slots:
39  void obstacleDataReady(const std::map<float, int>& lidarData);
40 
45  void rightWheelDirection(const int& direction);
46 
51  void leftWheelDirection(const int& direction);
52 
53  protected:
57  virtual void init() override;
58 
62  virtual void draw() override;
63 
68  virtual QString helpString() const override;
69 
70  private:
79  void loadTexture(GLuint* texture, const std::string& path);
80 
86  void drawRobot();
87 
95  void drawOneObstacle(GLfloat x, GLfloat y, GLfloat z, GLfloat color);
96 
104  void _drawCube(GLfloat size, GLubyte R, GLubyte G, GLubyte B);
105 
115  void _drawCylinder(GLfloat radius, GLfloat height, GLubyte R, GLubyte G, GLubyte B, GLuint texture);
116 
121  std::vector<std::vector<float>> _obstacleCoordinates;
122  std::vector<float> _obstacleColors;
123 
132  struct Dimensions
133  {
134  const float scale = 1.0 / 4000.0;
135  const float robotHeight = 200.0 * scale;
136  const float robotRadius = 300.0 * scale;
137  const float robotWheelRadius = 100.0 * scale;
138  const float robotWheelThickness = 50.0 * scale;
139  const float lidarHeight = 210.0 * scale;
140  const float obstacleSize = 30.0 * scale;
142 };
143 
144 #endif /* GLWIDGET_HH */
A wrapper class for drawing 3D shapes in OpenGL.
Definition: glWidget.hh:26
void loadTexture(GLuint *texture, const std::string &path)
Load a texture object.
Definition: glWidget.cpp:132
std::vector< float > _obstacleColors
All obstacles colors.
Definition: glWidget.hh:122
void obstacleDataReady(const std::map< float, int > &lidarData)
A slot to get a lidar data when the parser sent a signal that this data is ready.
Definition: glWidget.cpp:33
struct GLWidget::Dimensions _dimensions
void drawRobot()
Draw the robot shape.
Definition: glWidget.cpp:152
void drawOneObstacle(GLfloat x, GLfloat y, GLfloat z, GLfloat color)
Draw the one obstacle on (x, y, z) coordinates.
Definition: glWidget.cpp:177
GLWidget(QWidget *parent)
Construct a new GLWidget object.
Definition: glWidget.cpp:27
QString _robotTexturePath
The path to the robot texture file.
Definition: glWidget.hh:118
void rightWheelDirection(const int &direction)
A slot to get a right wheel spining direction.
Definition: glWidget.cpp:63
std::vector< std::vector< float > > _obstacleCoordinates
All obstacles coordinates in 3D space.
Definition: glWidget.hh:121
int _leftWheelDirection
The left robot wheel spining direction.
Definition: glWidget.hh:120
void _drawCube(GLfloat size, GLubyte R, GLubyte G, GLubyte B)
Draw a cube shape.
Definition: glWidget.cpp:186
virtual void init() override
Initialize the openGL widget.
Definition: glWidget.cpp:92
int _rightWheelDirection
The right robot wheel spining direction.
Definition: glWidget.hh:119
virtual void draw() override
Draw a content in the openGL widget.
Definition: glWidget.cpp:73
virtual QString helpString() const override
Construct a help string for the openGL widget.
Definition: glWidget.cpp:109
void leftWheelDirection(const int &direction)
A slot to get the left wheel spining direction.
Definition: glWidget.cpp:68
QString _wheelTexturePath
The path to the wheel texture file.
Definition: glWidget.hh:117
void _drawCylinder(GLfloat radius, GLfloat height, GLubyte R, GLubyte G, GLubyte B, GLuint texture)
Draw the cylinder shape with the texture on the top.
Definition: glWidget.cpp:233
Dimensions used in drawing.
Definition: glWidget.hh:133
const float robotWheelRadius
The wheel radius.
Definition: glWidget.hh:137
const float scale
The general scale.
Definition: glWidget.hh:134
const float obstacleSize
A size of the cube drawn as obstacle.
Definition: glWidget.hh:140
const float robotHeight
The obot body height.
Definition: glWidget.hh:135
const float robotRadius
The robot body radius.
Definition: glWidget.hh:136
const float lidarHeight
The laser sensor height.
Definition: glWidget.hh:139
const float robotWheelThickness
The wheel thickness.
Definition: glWidget.hh:138