From 7b374c70aed461737d9831c1f271a58f0de1fcb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Tue, 13 Feb 2018 18:42:15 +0100 Subject: [PATCH] Surfaces now provide a location hint This is supposed to be a point in space close to the surface --- Implicit.hpp | 2 ++ PerlinNoise.cpp | 8 ++++++++ PerlinNoise.hpp | 3 +++ spheroid.cpp | 4 ++++ spheroid.hpp | 2 ++ tests/TestImplicitSphere.cpp | 4 ++++ tests/TestImplicitSphere.hpp | 2 ++ 7 files changed, 25 insertions(+) diff --git a/Implicit.hpp b/Implicit.hpp index dc4a3d5..721f963 100644 --- a/Implicit.hpp +++ b/Implicit.hpp @@ -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: diff --git a/PerlinNoise.cpp b/PerlinNoise.cpp index af46b57..7857b35 100644 --- a/PerlinNoise.cpp +++ b/PerlinNoise.cpp @@ -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); +} diff --git a/PerlinNoise.hpp b/PerlinNoise.hpp index e013e9e..a03760b 100644 --- a/PerlinNoise.hpp +++ b/PerlinNoise.hpp @@ -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; diff --git a/spheroid.cpp b/spheroid.cpp index 88dbb76..7d347fb 100644 --- a/spheroid.cpp +++ b/spheroid.cpp @@ -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); +} diff --git a/spheroid.hpp b/spheroid.hpp index 1e6f0f0..52c0499 100644 --- a/spheroid.hpp +++ b/spheroid.hpp @@ -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, diff --git a/tests/TestImplicitSphere.cpp b/tests/TestImplicitSphere.cpp index 575dc56..afb5fdc 100644 --- a/tests/TestImplicitSphere.cpp +++ b/tests/TestImplicitSphere.cpp @@ -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); +} diff --git a/tests/TestImplicitSphere.hpp b/tests/TestImplicitSphere.hpp index ab0d13f..4171bce 100644 --- a/tests/TestImplicitSphere.hpp +++ b/tests/TestImplicitSphere.hpp @@ -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; };