From e3d913fd611b9eeb253a3e24c7272126162f2187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Tue, 13 Feb 2018 01:02:58 +0100 Subject: [PATCH] Bouncing nearly works' --- Ball.cpp | 3 ++- spheroid.cpp | 14 ++++++++------ spheroid.hpp | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Ball.cpp b/Ball.cpp index 5851b5a..0593040 100644 --- a/Ball.cpp +++ b/Ball.cpp @@ -24,6 +24,7 @@ void Ball::_compute_pos(double dt) { Center.x += dt * v_x; Center.z += dt * v_z; surface.update_center_pos(Center); + surface.check_horizontal_plan_collision(0.0); } void Ball::_compute_T_n() { @@ -48,7 +49,7 @@ void Ball::_compute_v_x(Point normal) { } void Ball::_compute_v_z(Point normal) { - double factor = normal.x / (4*(normal.x + normal.z)); + double factor = normal.z / (4*(normal.x + normal.z)); v_z *= (0.5 + factor); } diff --git a/spheroid.cpp b/spheroid.cpp index 65b5c0c..60b2d94 100644 --- a/spheroid.cpp +++ b/spheroid.cpp @@ -3,6 +3,7 @@ **/ #include "spheroid.hpp" +#include Spheroid::Spheroid(const Point& _center, double _min_p, double _p, double _q) : ImplicitSurface(_center), normal_vector(Point(0,0,1)), min_p(_min_p), @@ -18,11 +19,11 @@ void Spheroid::_compute_volume() { void Spheroid::update_radius() { - q = sqrt((3/4) * V / PI / p); + q = sqrt((3./4.) * V / PI / p); } void Spheroid::update_height() { - q = (3/4) * V / PI / (p*p); + q = (3./4.) * V / PI / (p*p); } @@ -30,10 +31,11 @@ void Spheroid::update_center_pos(Point& _center) { center = _center; } -void Spheroid::check_horizontal_plan_collision(double& height) { - if ((center.y - p) <= height) { +void Spheroid::check_horizontal_plan_collision(double height) { + if (((center.y - p) <= height) || (p <= init_p)) { p = fmin(init_p, center.y-height); update_radius(); + std::cout << "p:" << p << "q:" << q << '\n'; } } @@ -71,6 +73,6 @@ void Spheroid::check_perlin_collision(PerlinNoise perlin) { double Spheroid::operator() (double _x, double _y, double _z) const { return (pow(_x, 2) / pow(q, 2) - + pow(_y, 2) / pow(q, 2) - + pow(_z, 2) / pow(p, 2) -1); + + pow(_y, 2) / pow(p, 2) + + pow(_z, 2) / pow(q, 2) -1); } diff --git a/spheroid.hpp b/spheroid.hpp index c1e051a..1e6f0f0 100644 --- a/spheroid.hpp +++ b/spheroid.hpp @@ -17,7 +17,7 @@ class Spheroid : public ImplicitSurface { void update_center_pos(Point& _center); void update_radius(); void update_height(); - void check_horizontal_plan_collision(double& height); + void check_horizontal_plan_collision(double height); void check_vertical_plan_collision(double& abscissa); Cuboid max_bounding_box() const; void check_perlin_collision(PerlinNoise perlin);