feat: add support for drawing velocity vectors
This commit is contained in:
parent
c4ef11f38e
commit
4dae604485
@ -51,8 +51,11 @@ struct Screen {
|
|||||||
~Screen() { delete[] buf; }
|
~Screen() { delete[] buf; }
|
||||||
|
|
||||||
std::vector<const vec<2>*> points;
|
std::vector<const vec<2>*> points;
|
||||||
|
std::vector<std::pair<const vec<2>*,const vec<2>*>> vecs;
|
||||||
char_shader_t shader;
|
char_shader_t shader;
|
||||||
|
|
||||||
|
bool draw_vecs = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Symbol *buf;
|
Symbol *buf;
|
||||||
Symbol _dummy;
|
Symbol _dummy;
|
||||||
|
@ -132,6 +132,7 @@ struct Particle : public Agent<vec<N>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const vec<N> &get_position() const { return position; };
|
const vec<N> &get_position() const { return position; };
|
||||||
|
const vec<N> &get_velocity() const { return velocity; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
A alg;
|
A alg;
|
||||||
|
@ -53,6 +53,10 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
for(const auto &p : swarm.get_particles()) {
|
for(const auto &p : swarm.get_particles()) {
|
||||||
scr.points.push_back(&p.get_position());
|
scr.points.push_back(&p.get_position());
|
||||||
|
scr.vecs.push_back({
|
||||||
|
&p.get_position(),
|
||||||
|
&p.get_velocity(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
enter_noncanonical_mode();
|
enter_noncanonical_mode();
|
||||||
@ -178,7 +182,8 @@ main(int argc, char **argv) {
|
|||||||
printf(" movement zoom coloring pause step \n"
|
printf(" movement zoom coloring pause step \n"
|
||||||
" W io IK LO SPC ., \n"
|
" W io IK LO SPC ., \n"
|
||||||
" ASD \n"
|
" ASD \n"
|
||||||
" quit: q \n");
|
" [%c] draw (v)elocities quit: q \n",
|
||||||
|
scr.draw_vecs ? 'x' : ' ');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,32 @@ void Screen::draw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw lines for each velocity vector
|
||||||
|
if(draw_vecs) {
|
||||||
|
for(const auto &[start, vel] : vecs) {
|
||||||
|
auto end = *start + (*vel) / 3;
|
||||||
|
if(start->x == end.x) {
|
||||||
|
// TODO: draw horizontal/vertical lines
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto a = (end.y - start->y) / (end.x - start->x);
|
||||||
|
auto b = start->y - a * start->x;
|
||||||
|
|
||||||
|
for(int i = 0; i < w; ++i) {
|
||||||
|
const auto [x, _] = screen_to_xy(i, 0);
|
||||||
|
if(x < std::min(start->x, end.x)
|
||||||
|
|| x > std::max(start->x, end.x)) continue;
|
||||||
|
|
||||||
|
auto y = a*x + b;
|
||||||
|
at(x, y) = Symbol{
|
||||||
|
.sym = '+',
|
||||||
|
.color = { 0.75, 0, 0 },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// write out a '#' wherever we have a point registered
|
// write out a '#' wherever we have a point registered
|
||||||
for(const auto &p : points) {
|
for(const auto &p : points) {
|
||||||
at(p->x, p->y) = {.sym = '#', .color = 1};
|
at(p->x, p->y) = {.sym = '#', .color = 1};
|
||||||
|
Loading…
Reference in New Issue
Block a user