diff --git a/mainwindow.cpp b/mainwindow.cpp index 320a75f..80b9cd9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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::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() { diff --git a/mainwindow.hpp b/mainwindow.hpp index fa6e2f6..facc644 100644 --- a/mainwindow.hpp +++ b/mainwindow.hpp @@ -4,6 +4,7 @@ #include #include "robot.hpp" #include +#include namespace Ui { class MainWindow; @@ -28,6 +29,10 @@ public slots: Robot& _robot; QGraphicsScene _scene; + QLinkedList _pointList; + + static const int POINT_LIST_SIZE = 50; + static const int ADD_POINT_EVERY = 10; }; #endif // MAINWINDOW_H