projects
/
flatland.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
d0756dc
)
Fixed a major bug in the border forces, and changed the dissipation model to max...
author
Francois Fleuret
<francois@fleuret.org>
Sat, 1 Apr 2017 21:09:31 +0000
(23:09 +0200)
committer
Francois Fleuret
<francois@fleuret.org>
Sat, 1 Apr 2017 21:09:31 +0000
(23:09 +0200)
polygon.cc
patch
|
blob
|
history
diff --git
a/polygon.cc
b/polygon.cc
index
ba629c5
..
353486e
100644
(file)
--- a/
polygon.cc
+++ b/
polygon.cc
@@
-31,7
+31,7
@@
using namespace std;
static const scalar_t dl = 20.0;
static const scalar_t repulsion_constant = 0.2;
static const scalar_t dl = 20.0;
static const scalar_t repulsion_constant = 0.2;
-static const scalar_t
dissipation = 0.5
;
+static const scalar_t
speed_max = 1e2
;
Polygon::Polygon(scalar_t mass,
scalar_t red, scalar_t green, scalar_t blue,
Polygon::Polygon(scalar_t mass,
scalar_t red, scalar_t green, scalar_t blue,
@@
-306,17
+306,18
@@
void Polygon::initialize(int nb_polygons) {
}
bool Polygon::update(scalar_t dt) {
}
bool Polygon::update(scalar_t dt) {
+ scalar_t speed = sqrt(_dcenter_x * _dcenter_x + _dcenter_y * _dcenter_y);
+ scalar_t speed_target = speed_max - exp(-speed / speed_max) * speed_max;
+
+ _dcenter_x = speed_target * _dcenter_x / speed;
+ _dcenter_y = speed_target * _dcenter_y / speed;
+
if(!_nailed) {
_center_x += _dcenter_x * dt;
_center_y += _dcenter_y * dt;
_theta += _dtheta * dt;
}
if(!_nailed) {
_center_x += _dcenter_x * dt;
_center_y += _dcenter_y * dt;
_theta += _dtheta * dt;
}
- scalar_t d = exp(log(dissipation) * dt);
- _dcenter_x *= d;
- _dcenter_y *= d;
- _dtheta *= d;
-
scalar_t vx = cos(_theta), vy = sin(_theta);
for(int n = 0; n < _nb_vertices; n++) {
scalar_t vx = cos(_theta), vy = sin(_theta);
for(int n = 0; n < _nb_vertices; n++) {
@@
-366,11
+367,15
@@
void Polygon::apply_border_forces(scalar_t dt,
scalar_t x = _x[v] * (1 - s) + _x[vp] * s;
scalar_t y = _y[v] * (1 - s) + _y[vp] * s;
scalar_t vx = 0, vy = 0;
scalar_t x = _x[v] * (1 - s) + _x[vp] * s;
scalar_t y = _y[v] * (1 - s) + _y[vp] * s;
scalar_t vx = 0, vy = 0;
- if(x < xmin) vx = x
min - x
;
+ if(x < xmin) vx = x
- xmin
;
else if(x > xmax) vx = x - xmax;
else if(x > xmax) vx = x - xmax;
- if(y < ymin) vy = y
min - y
;
+ if(y < ymin) vy = y
- ymin
;
else if(y > ymax) vy = y - ymax;
else if(y > ymax) vy = y - ymax;
- apply_force(dt, x, y, - dl * vx * repulsion_constant, - dl * vy * repulsion_constant);
+ if(vx != 0 || vy != 0) {
+ // cerr << "apply_border_forces vx = " << vx << " vy = " << vy << endl;
+ apply_force(dt, x, y,
+ - dl * vx * repulsion_constant, - dl * vy * repulsion_constant);
+ }
}
}
}
}
}
}