static const scalar_t dl = 20.0;
static const scalar_t repulsion_constant = 0.2;
static const scalar_t speed_max = 1e2;
+static const scalar_t angular_speed_max = M_PI / 10;
Polygon::Polygon(scalar_t mass,
scalar_t red, scalar_t green, scalar_t blue,
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(speed > 0) {
+ 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;
+ }
+
+ scalar_t angular_speed = abs(_dtheta);
+
+ if(angular_speed > 0) {
+ scalar_t angular_speed_target = angular_speed_max - exp(-angular_speed / angular_speed_max) * angular_speed_max;
+ _dtheta = angular_speed_target * _dtheta / angular_speed;
+ }
if(!_nailed) {
_center_x += _dcenter_x * dt;