projects
/
flatland.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update.
[flatland.git]
/
polygon.cc
diff --git
a/polygon.cc
b/polygon.cc
index
69b125e
..
b64fbe4
100644
(file)
--- a/
polygon.cc
+++ b/
polygon.cc
@@
-356,7
+356,9
@@
void Polygon::apply_force(scalar_t dt, scalar_t x, scalar_t y, scalar_t fx, scal
_dtheta -= prod_vect(x - _center_x, y - _center_y, fx, fy) / (_mass * _moment_of_inertia) * dt;
}
_dtheta -= prod_vect(x - _center_x, y - _center_y, fx, fy) / (_mass * _moment_of_inertia) * dt;
}
-void Polygon::apply_border_forces(scalar_t dt, scalar_t xmax, scalar_t ymax) {
+void Polygon::apply_border_forces(scalar_t dt,
+ scalar_t xmin, scalar_t ymin,
+ scalar_t xmax, scalar_t ymax) {
for(int v = 0; v < _nb_vertices; v++) {
int vp = (v+1)%_nb_vertices;
for(int d = 0; d < _nb_dots[v]; d++) {
for(int v = 0; v < _nb_vertices; v++) {
int vp = (v+1)%_nb_vertices;
for(int d = 0; d < _nb_dots[v]; d++) {
@@
-364,9
+366,9
@@
void Polygon::apply_border_forces(scalar_t dt, scalar_t xmax, scalar_t ymax) {
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 <
0) vx =
x;
+ if(x <
xmin) vx = xmin -
x;
else if(x > xmax) vx = x - xmax;
else if(x > xmax) vx = x - xmax;
- if(y <
0) vy =
y;
+ if(y <
ymin) vy = ymin -
y;
else if(y > ymax) vy = y - ymax;
apply_force(dt, x, y, - dl * vx * repulsion_constant, - dl * vy * repulsion_constant);
}
else if(y > ymax) vy = y - ymax;
apply_force(dt, x, y, - dl * vx * repulsion_constant, - dl * vy * repulsion_constant);
}
@@
-390,9
+392,10
@@
void Polygon::apply_collision_forces(scalar_t dt, int n_polygon, Polygon *p) {
distance[d] = FLT_MAX;
}
distance[d] = FLT_MAX;
}
- // First, we tag the dots located inside the polygon p
+ // First, we tag the dots located inside the polygon p by looping
+ // through the _nb_vertices - 2 triangles from the decomposition
- for(int t = 0; t < p->_nb_vertices
-
2; t++) {
+ for(int t = 0; t < p->_nb_vertices
-
2; t++) {
scalar_t min = 0, max = 1;
scalar_t xa = p->_x[p->_triangles[t].a], ya = p->_y[p->_triangles[t].a];
scalar_t xb = p->_x[p->_triangles[t].b], yb = p->_y[p->_triangles[t].b];
scalar_t min = 0, max = 1;
scalar_t xa = p->_x[p->_triangles[t].a], ya = p->_y[p->_triangles[t].a];
scalar_t xb = p->_x[p->_triangles[t].b], yb = p->_y[p->_triangles[t].b];