Surfaces now provide a location hint

This is supposed to be a point in space close to the surface
This commit is contained in:
Théophile Bastian 2018-02-13 18:42:15 +01:00
parent 5b6e61cec9
commit 7b374c70ae
7 changed files with 25 additions and 0 deletions

View file

@ -8,6 +8,8 @@ class ImplicitSurface {
double operator()(const Point& pt) const; double operator()(const Point& pt) const;
Point getCenter() const { return center;} Point getCenter() const { return center;}
virtual Point location_hint() const = 0;
/// Compute the normal vector to the isosurface at `pt` /// Compute the normal vector to the isosurface at `pt`
Point normal_at(const Point& pt) const; Point normal_at(const Point& pt) const;
protected: protected:

View file

@ -121,3 +121,11 @@ Point PerlinNoise::normal_vector(double x, double y) {
); );
return product; return product;
} }
Point PerlinNoise::location_hint() const {
return location_hint(0, 0);
}
Point PerlinNoise::location_hint(double x, double z) const {
return Point(x, noise(x, z), z);
}

View file

@ -15,6 +15,9 @@ class PerlinNoise : public ImplicitSurface {
double operator() (double _x, double _y, double _z) const; double operator() (double _x, double _y, double _z) const;
double noise(double x, double y) const; double noise(double x, double y) const;
Point normal_vector(double x, double y); Point normal_vector(double x, double y);
virtual Point location_hint() const;
Point location_hint(double x, double z) const;
private: private:
double noise(double x, double y, double z) const; double noise(double x, double y, double z) const;
double fade(double t) const; double fade(double t) const;

View file

@ -75,3 +75,7 @@ double Spheroid::operator() (double _x, double _y, double _z) const {
+ pow(_y, 2) / pow(p, 2) + pow(_y, 2) / pow(p, 2)
+ pow(_z, 2) / pow(q, 2) -1); + pow(_z, 2) / pow(q, 2) -1);
} }
Point Spheroid::location_hint() const {
return Point(0, p, 0);
}

View file

@ -23,6 +23,8 @@ class Spheroid : public ImplicitSurface {
void check_perlin_collision(PerlinNoise perlin); void check_perlin_collision(PerlinNoise perlin);
Point getNormalVector() const { return normal_vector;} Point getNormalVector() const { return normal_vector;}
double operator() (double _x, double _y, double _z) const; double operator() (double _x, double _y, double _z) const;
virtual Point location_hint() const;
private: private:
/** /**
* p corresponds to the half-height of the ball, * p corresponds to the half-height of the ball,

View file

@ -7,3 +7,7 @@ double TestImplicitSphere::operator()(double x, double y, double z) const {
+ sq(center.z - z)) + sq(center.z - z))
+ sq(radius); + sq(radius);
} }
Point TestImplicitSphere::location_hint() const {
return Point(center.x + radius, center.y, center.z);
}

View file

@ -8,6 +8,8 @@ class TestImplicitSphere: public ImplicitSurface {
ImplicitSurface(center), radius(r) {} ImplicitSurface(center), radius(r) {}
virtual double operator()(double x, double y, double z) const; virtual double operator()(double x, double y, double z) const;
virtual Point location_hint() const;
private: private:
double radius; double radius;
}; };