diff --git a/Ball.cpp b/Ball.cpp index 93bb674..b85d6fb 100644 --- a/Ball.cpp +++ b/Ball.cpp @@ -25,20 +25,22 @@ Ball::Ball(const Point& _center, const Ground* _ground, double _min_height, } void Ball::_compute_pos(double dt) { + double height = (*ground)(Center.x, Center.z); if (bouncing) { Center.y = fmax( - min_height, - A + B * crt_time - (G_CTE / 2) * crt_time * crt_time + min_height + min_height + height, + A + B * crt_time - (G_CTE / 2) * crt_time * crt_time + min_height + height ); } else { double n_time = crt_time - stop_bouncing; double min_rad = radius - min_height; - Center.y = min_height + ((min_rad * (1.0 - exp(-n_time)) + min_rad )/2.) + - (min_rad - ((min_rad* (1- exp(-n_time)) + min_rad)/2.)) * sin(5. * - n_time); v_x *= 0.8; v_z *= 0.8; + Center.y = height + min_height + ((min_rad * (1.0 - exp(-n_time)) + min_rad )/2.) + + (min_rad - ((min_rad* (1- exp(-n_time)) + min_rad)/2.)) * sin(5. * + n_time); } + std::cout << (*this) << "\n"; Center.x += dt * v_x; Center.z += dt * v_z; surface.update_center_pos(Center); @@ -72,11 +74,12 @@ void Ball::_compute_v_z(Point normal) { } void Ball::update_pos(double dt) { + //double height = (*ground)(Center.x, Center.z); crt_time += dt; if ((bouncing) && (crt_time >= T)) { double old_t = T; double max_t; - Point normal = surface.getNormalVector(); + Point normal = (*ground).get_normal(Center.x, Center.z); bounce_number += 1; _compute_U_n(); _compute_A_n(); diff --git a/FlatGround.cpp b/FlatGround.cpp index b3bf243..782f232 100644 --- a/FlatGround.cpp +++ b/FlatGround.cpp @@ -4,3 +4,7 @@ double FlatGround::operator() (double, double) const { return 0. ; } + +Point FlatGround::get_normal(double, double) const { + return Point(0, 1, 0); +} diff --git a/FlatGround.hpp b/FlatGround.hpp index e2ee420..74cd6e2 100644 --- a/FlatGround.hpp +++ b/FlatGround.hpp @@ -2,5 +2,7 @@ #include "Ground.hpp" class FlatGround : public Ground { - double operator() (double, double) const; + public: + double operator() (double, double) const; + Point get_normal(double x, double y) const; }; diff --git a/Ground.hpp b/Ground.hpp index c03f06a..66d8c98 100644 --- a/Ground.hpp +++ b/Ground.hpp @@ -5,4 +5,5 @@ class Ground { public: virtual double operator() (double, double) const = 0; + virtual Point get_normal(double x, double y) const = 0; }; diff --git a/MarchingCubes.cpp b/MarchingCubes.cpp index 48c4774..90d93a0 100644 --- a/MarchingCubes.cpp +++ b/MarchingCubes.cpp @@ -5,6 +5,8 @@ #include "GL/gl.h" +#include "GL/gl.h" + MarchingCubes::MarchingCubes( const ImplicitSurface& surface, const Cuboid& box, diff --git a/PerlinGround.cpp b/PerlinGround.cpp index 081a46b..338bdc1 100644 --- a/PerlinGround.cpp +++ b/PerlinGround.cpp @@ -7,3 +7,8 @@ double PerlinGround::operator() (double x, double z) const { return surface.noise(x, z); } + +Point PerlinGround::get_normal(double x, double z) const { + const Point pt(x, surface.noise(x, z), z); + return surface.normal_at(pt); +} diff --git a/PerlinGround.hpp b/PerlinGround.hpp index df2add7..597624c 100644 --- a/PerlinGround.hpp +++ b/PerlinGround.hpp @@ -7,6 +7,7 @@ class PerlinGround : public Ground { PerlinGround(); PerlinGround(unsigned int seed); double operator() (double, double) const; + Point get_normal(double x, double y) const; private: PerlinNoise surface; }; diff --git a/main_bounce.cpp b/main_bounce.cpp index 9f0aa65..b1849e8 100644 --- a/main_bounce.cpp +++ b/main_bounce.cpp @@ -11,7 +11,7 @@ int main(int argc, char** argv) { - FlatGround* flat = new FlatGround(); + PerlinGround* flat = new PerlinGround(); GlutRender& render = GlutRender::get_instance(); render.init(&argc, argv, 640, 480, "Bouncing stuff"); diff --git a/spheroid.cpp b/spheroid.cpp index 4fc09b4..03cab7c 100644 --- a/spheroid.cpp +++ b/spheroid.cpp @@ -6,7 +6,7 @@ #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), + ImplicitSurface(_center), min_p(_min_p), init_p(_p), p(_p), q(_q), stiffness(0) { _compute_volume(); @@ -44,15 +44,6 @@ Cuboid Spheroid::max_bounding_box() const { return Cuboid(_bd1, _bd2); } -void Spheroid::check_perlin_collision(PerlinNoise perlin) { - double height = perlin.noise(center.x, center.z); - if ((center.y - p) <= height) { - p = fmin(init_p, center.z- height ); - normal_vector = perlin.normal_vector(center.x, center.z); - update_radius(); - } -} - double Spheroid::operator() (double _x, double _y, double _z) const { return (pow(_x, 2) / pow(q, 2) diff --git a/spheroid.hpp b/spheroid.hpp index b9549fe..5ca21e0 100644 --- a/spheroid.hpp +++ b/spheroid.hpp @@ -21,7 +21,6 @@ class Spheroid : public ImplicitSurface { void check_ground_collision(const Ground* ground); Cuboid max_bounding_box() const; void check_perlin_collision(PerlinNoise perlin); - Point getNormalVector() const { return normal_vector;} double operator() (double _x, double _y, double _z) const; virtual Point location_hint() const; @@ -32,7 +31,6 @@ class Spheroid : public ImplicitSurface { * V is the volume. Extremely useful to have a constant volume in the * ball **/ - Point normal_vector; double min_p, init_p, p, q; size_t stiffness; double V;