Skip to content

Commit

Permalink
Now drawing the robot's trajectory with a red line.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elioty committed Oct 16, 2014
1 parent 5c6e940 commit dda74f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ void MainWindow::renderRobot() {
_scene.addPolygon(bot);
_scene.addPolygon(right_wheel);
_scene.addPolygon(left_wheel);

const QPointF* prev = NULL;
int j = 0;
for(QLinkedList<QPointF>::Iterator i = _pointList.begin(); i != _pointList.end(); i++, j++) {
if(prev) {
QLine line((int) prev->x(), (int) prev->y(), (int) (*i).x(), (int) (*i).y());
QPen pen(QBrush(QColor(255, 0, 0, 255 - (255. / POINT_LIST_SIZE * j))), 3);
_scene.addLine(line, pen);
}
prev = &(*i);
}

static int cpt = 0;
if(++cpt > ADD_POINT_EVERY) {
cpt = 0;
_pointList.prepend(pos);
}

while(_pointList.size() > POINT_LIST_SIZE) {
_pointList.removeLast();
}
}

void MainWindow::renderWorld() {
Expand Down
5 changes: 5 additions & 0 deletions mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QMainWindow>
#include "robot.hpp"
#include <QGraphicsScene>
#include <QLinkedList>

namespace Ui {
class MainWindow;
Expand All @@ -28,6 +29,10 @@ public slots:
Robot& _robot;

QGraphicsScene _scene;
QLinkedList<QPointF> _pointList;

static const int POINT_LIST_SIZE = 50;
static const int ADD_POINT_EVERY = 10;
};

#endif // MAINWINDOW_H

0 comments on commit dda74f5

Please sign in to comment.