1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-07-06 11:32:49 +00:00

rogueviz::flocking:: added some comments

This commit is contained in:
Zeno Rogue 2018-11-18 17:34:26 +01:00
parent 73de211bf2
commit be3a464527

View File

@ -1,6 +1,11 @@
// flocking simulations // flocking simulations
// Copyright (C) 2018 Zeno and Tehora Rogue, see 'hyper.cpp' for details // Copyright (C) 2018 Zeno and Tehora Rogue, see 'hyper.cpp' for details
// based on Flocking by Daniel Shiffman (which in turn implements Boids by Craig Reynold)
// https://processing.org/examples/flocking.html
// Our implementation simplifies some equations a bit.
// example parameters: // example parameters:
// flocking on a torus: // flocking on a torus:
@ -9,7 +14,7 @@
// flocking on the Zebra quotient: // flocking on the Zebra quotient:
// -geo 4 -flocking 10 -rvshape 3 -zoom .9 // -geo 4 -flocking 10 -rvshape 3 -zoom .9
// press 'o' when flocking active to change the parameters // press 'o' when flocking active to change the parameters.
namespace hr { namespace hr {
hyperpoint nearcorner(cell *c, int i); hyperpoint nearcorner(cell *c, int i);
@ -159,16 +164,12 @@ namespace flocking {
} }
} }
// a bit simpler rules than original
if(sep_count) velvec += sep * (d * sep_factor / sep_count); if(sep_count) velvec += sep * (d * sep_factor / sep_count);
if(align_count) velvec += align * (d * align_factor / align_count); if(align_count) velvec += align * (d * align_factor / align_count);
if(coh_count) velvec += coh * (d * coh_factor / coh_count); if(coh_count) velvec += coh * (d * coh_factor / coh_count);
if(i == 0) {
printf("%s\n", display(velvec));
// lines.emplace_back(gmatrix[m->base] * m->at * C0, gmatrix[m->base] * m->at * (C0 + velvec));
// lines.emplace_back(gmatrix[m->base] * m->at * C0, gmatrix[m->base] * m->at * (C0 + sep / hypot2(sep)));
}
vels[i] = hypot2(velvec); vels[i] = hypot2(velvec);
ld alpha = -atan2(velvec); ld alpha = -atan2(velvec);