diff --git a/spheroid.cpp b/spheroid.cpp index 2c0a60b..af24061 100644 --- a/spheroid.cpp +++ b/spheroid.cpp @@ -5,7 +5,7 @@ #include "spheroid.hpp" Spheroid::Spheroid(Point& _center, size_t _p, size_t _q) : - ImplicitSurface(_center), init_p(_p), p(_p), q(_q), stiffness(0) { + ImplicitSurface(_center), normal_vector(Point(0,0,1)), init_p(_p), p(_p), q(_q), stiffness(0) { _compute_volume(); } @@ -52,6 +52,15 @@ void Spheroid::check_vertical_plan_collision(double& abscissa) { } } +void Spheroid::check_perlin_collision(PerlinNoise perlin) { + double height = perlin.noise(center.x, center.y); + if ((center.z - p) <= height) { + p = fmin(init_p, center.z- height ); + normal_vector = perlin.normal_vector(center.x, center.y); + update_radius(); + } +} + double Spheroid::operator() (double _x, double _y, double _z) const { return (pow(_x - center.x, 2) / pow(q, 2) diff --git a/spheroid.hpp b/spheroid.hpp index ca74894..df84664 100644 --- a/spheroid.hpp +++ b/spheroid.hpp @@ -7,6 +7,7 @@ #include #include "Implicit.hpp" #include "common_structures.hpp" +#include "PerlinNoise.hpp" const double PI = 3.141592653589793; @@ -19,6 +20,8 @@ class Spheroid : public ImplicitSurface { void set_stiffness(size_t _stiffness); void check_horizontal_plan_collision(double& height); void check_vertical_plan_collision(double& abscissa); + void check_perlin_collision(PerlinNoise perlin); + Point getNormalVector() const { return normal_vector;} double operator() (double _x, double _y, double _z) const; private: /** @@ -27,6 +30,7 @@ class Spheroid : public ImplicitSurface { * V is the volume. Extremely useful to have a constant volume in the * ball **/ + Point normal_vector; double init_p, p, q; size_t stiffness; double V;