aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-01 17:17:35 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-01 17:17:35 +0100
commit3b8497a4d6c71ac542a2992a645c00bf99d45390 (patch)
treea7c125183618b649bff3cbd5c0f59e5c238c2052
parent74dba84f9197a3b65b194d8a3dc53bf086d9f072 (diff)
downloadRobotique-Projet-3b8497a4d6c71ac542a2992a645c00bf99d45390.tar.gz
Robotique-Projet-3b8497a4d6c71ac542a2992a645c00bf99d45390.zip
Implement movement rendering
-rw-r--r--problem.cpp8
-rw-r--r--problem.hpp6
-rw-r--r--ui.cpp61
-rw-r--r--ui.hpp6
4 files changed, 55 insertions, 26 deletions
diff --git a/problem.cpp b/problem.cpp
index 8078c33..e56b0b3 100644
--- a/problem.cpp
+++ b/problem.cpp
@@ -46,6 +46,12 @@ solution solution::direct_sol(const hilare_a &pos_a, const hilare_a &pos_b) {
// IMPLEMENTATION FOR CLASS SOLVER //
// =============================== //
-// TODO
+solver::solver() {
+ // nothing ?
+}
+
+solver_internal solver::peek_internal() {
+ return _d;
+}
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/problem.hpp b/problem.hpp
index 381b52d..685e1df 100644
--- a/problem.hpp
+++ b/problem.hpp
@@ -86,14 +86,14 @@ struct solver_internal {
// intermediate data for the solver
// represents a graph of randomly chosen positions and simple solutions between them
std::vector<hilare_a> pts;
- std::map<int, std::map<int, hilare_a_mvt> > paths;
+ std::map<int, std::map<int, solution> > paths;
};
class solver {
// mutex-protected asynchronous structure
private:
- //todo
+ solver_internal _d;
public:
solver();
@@ -101,6 +101,8 @@ class solver {
void start(const problem &p);
bool finished();
solution get_solution();
+
+ solver_internal peek_internal();
};
diff --git a/ui.cpp b/ui.cpp
index 9c1fec7..1f61f03 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -107,7 +107,7 @@ void UI::handle_normal(const sf::Event &ev) {
if (k == 'd') {
vec p = mouse_coord();
vector<obstacle> o2;
- for(auto i: _p.obstacles) {
+ for(auto& i: _p.obstacles) {
if (!i.c.intersects(p)) o2.push_back(i);
}
_p.obstacles = o2;
@@ -187,21 +187,6 @@ void UI::render_circle(const circle &c, sf::Color border, sf::Color inside, int
_win.draw(a);
}
-void UI::render_seg(vec a, vec b, sf::Color c, int w) {
- sf::ConvexShape l;
-
- l.setPointCount(4);
- l.setPoint(0, to_view(a));
- l.setPoint(1, to_view(b));
- l.setPoint(2, to_view(b));
- l.setPoint(3, to_view(a));
-
- l.setOutlineColor(c);
- l.setOutlineThickness(w);
-
- _win.draw(l);
-}
-
void UI::render_pos(const hilare_a &pos, sf::Color c) {
render_circle(circle(pos.pos(), pos.param->r_c_car), c, sf::Color::Transparent, 2);
@@ -223,8 +208,34 @@ void UI::render_obstacle(const obstacle &o) {
render_circle(o.c, sf::Color::Transparent, sf::Color(100, 100, 100), 0);
}
-void UI::render_mvt(const hilare_a_mvt &m) {
- // TODO
+void UI::render_mvt(const hilare_a_mvt &m, sf::Color c) {
+ if (m.is_arc) {
+ sf::Vertex l[20];
+
+ l[0] = sf::Vertex(to_view(m.from.pos()), c);
+
+ double th = (m.from.pos() - m.center).angle();
+ double r = (m.from.pos() - m.center).norm();
+ for (int i = 1; i < 19; i++) {
+ l[i] = sf::Vertex(to_view(m.center + vec::from_polar(r, th + m.domega * i / 20)), c);
+ }
+
+ l[19] = sf::Vertex(to_view(m.to.pos()), c);
+
+ _win.draw(l, 20, sf::Lines);
+ } else {
+ sf::Vertex l[] = {
+ sf::Vertex(to_view(m.from.pos()), c),
+ sf::Vertex(to_view(m.to.pos()), c),
+ };
+ _win.draw(l, 2, sf::Lines);
+ }
+}
+
+void UI::render_sol(const solution &s, sf::Color c) {
+ for (auto i: s.movement) {
+ render_mvt(i, c);
+ }
}
void UI::render_problem() {
@@ -240,12 +251,22 @@ void UI::render_solution() {
for (auto i = _s.movement.begin(); i != _s.movement.end(); i++) {
if (i != _s.movement.begin())
render_pos(i->from, sf::Color::Green);
- render_mvt(*i);
}
+ render_sol(_s.movement, sf::Color::Green);
}
void UI::render_internal() {
- // TODO
+ solver_internal x = _solver.peek_internal();
+
+ for (auto& p: x.pts) {
+ render_pos(p, sf::Color(42, 42, 42));
+ }
+
+ for (auto& kv: x.paths) {
+ for (auto kv2: kv.second) {
+ render_sol(kv2.second, sf::Color(42, 42, 42));
+ }
+ }
}
sf::Vector2f UI::to_view(const vec &p) {
diff --git a/ui.hpp b/ui.hpp
index 169dc60..8496b58 100644
--- a/ui.hpp
+++ b/ui.hpp
@@ -26,8 +26,8 @@ class UI {
hilare_a_param *_param;
problem _p;
-
solution _s;
+ solver _solver;
struct {
double x0, y0, zoom;
@@ -49,11 +49,11 @@ class UI {
void handle_sel_pos(const sf::Event &ev);
void render_circle(const circle& c, sf::Color border, sf::Color inside, int linewidth);
- void render_seg(vec a, vec b, sf::Color l, int w);
void render_pos(const hilare_a &pos, sf::Color c);
void render_obstacle(const obstacle &o);
- void render_mvt(const hilare_a_mvt &m);
+ void render_mvt(const hilare_a_mvt &m, sf::Color c);
+ void render_sol(const solution &s, sf::Color c);
void render_problem();
void render_solution();