diff --git a/Ball.cpp b/Ball.cpp index 390fa56..0201912 100644 --- a/Ball.cpp +++ b/Ball.cpp @@ -41,24 +41,27 @@ void Ball::_compute_U_n() { U *= 0.5; } -void Ball::_compute_v_x() { - v_x *= 0.5; +void Ball::_compute_v_x(Point normal) { + double factor = normal.x / (4*(normal.x + normal.y)); + v_x *= (0.5 + factor); } -void Ball::_compute_v_y() { - v_y *= 0.5; +void Ball::_compute_v_y(Point normal) { + double factor = normal.x / (4*(normal.x + normal.y)); + v_y *= (0.5 + factor); } void Ball::update_pos(double dt) { crt_time += dt; if (crt_time >= T) { + Point normal = surface.getNormalVector(); bounce_number += 1; _compute_U_n(); _compute_A_n(); _compute_B_n(); _compute_T_n(); - _compute_v_x(); - _compute_v_y(); + _compute_v_x(normal); + _compute_v_y(normal); std::cout << "New bounce :"; std::cout << "U:" << U << ":"; std::cout << "A:" << A << ":"; diff --git a/Ball.hpp b/Ball.hpp index a9ed49f..9f2d90e 100644 --- a/Ball.hpp +++ b/Ball.hpp @@ -26,8 +26,8 @@ class Ball { double A, B, U, T; // Coefficients for the physical model. double v_x, v_y; void _compute_pos(double dt); - void _compute_v_x(); - void _compute_v_y(); + void _compute_v_x(Point normal); + void _compute_v_y(Point normal); void _compute_A_n(); void _compute_B_n(); void _compute_U_n();