From 53cedde49c61d57f44698c6e22823c3fe9ba5b56 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sat, 1 Apr 2017 23:18:04 +0200 Subject: [PATCH] Added the same dissipation model for the angular speed. --- polygon.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/polygon.cc b/polygon.cc index 353486e..b899950 100644 --- a/polygon.cc +++ b/polygon.cc @@ -32,6 +32,7 @@ using namespace std; 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, @@ -307,10 +308,19 @@ void Polygon::initialize(int nb_polygons) { 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; -- 2.39.5