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;
Point getCenter() const { return center;}
virtual Point location_hint() const = 0;
/// Compute the normal vector to the isosurface at `pt`
Point normal_at(const Point& pt) const;
protected:

View File

@ -121,3 +121,11 @@ Point PerlinNoise::normal_vector(double x, double y) {
);
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 noise(double x, double y) const;
Point normal_vector(double x, double y);
virtual Point location_hint() const;
Point location_hint(double x, double z) const;
private:
double noise(double x, double y, double z) 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(_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);
Point getNormalVector() const { return normal_vector;}
double operator() (double _x, double _y, double _z) const;
virtual Point location_hint() const;
private:
/**
* 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(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) {}
virtual double operator()(double x, double y, double z) const;
virtual Point location_hint() const;
private:
double radius;
};