Adress review comments

This commit is contained in:
Emma Broman
2021-07-09 15:30:42 +02:00
parent 23b70eaf14
commit 771aa46fcd
13 changed files with 361 additions and 230 deletions

View File

@@ -50,24 +50,79 @@ public:
Waypoint startPoint() const;
Waypoint endPoint() const;
/*
* Return the specified duration for the path, in seconds. Note that the time it
* takes to actually traverse the path will not exactly match the provided duration
*/
double duration() const;
/*
* Return the total length of the the curve for the path, in meters
*/
double pathLength() const;
/*
* Return a vector of positions corresponding to the control points of the path's
* spline curve
*/
std::vector<glm::dvec3> controlPoints() const;
/*
* Take a step along the current path, corresponding to the delta time step \p dt, and
* return the resulting camera pose. The \p speedScale is a factor that will be
* multiplied with the traversal speed
*/
CameraPose traversePath(double dt, float speedScale = 1.f);
/*
* Return the identifer of the node that is the current appropriate anchor node, of
* the start and end waypoint's reference node. Dtermined based on how far along the
* path we have traveled
*/
std::string currentAnchor() const;
/*
* Return wether the path has reached its end point or not
*/
bool hasReachedEnd() const;
/*
* Compute the interpolated camera pose at a certain distance along the path
*/
CameraPose interpolatedPose(double distance) const;
private:
glm::dquat interpolateRotation(double u) const;
/*
* Interpolate between the paths start and end rotation using the approach that
* corresponds to the path's curve type. The interpolation parameter \p t is the
* same as for the position interpolation, i.e. the relative traveled in distance
* along the path, in [0, 1]
*/
glm::dquat interpolateRotation(double t) const;
/*
* Compute the interpolated rotation quaternion using an eased SLERP approach
*/
glm::dquat easedSlerpRotation(double t) const;
/*
* Compute the interpolated rotation quaternion using an approach that first
* interpolates to look at the start node, and then the end node, before
* interpolating to the end rotation
*/
glm::dquat lookAtTargetsRotation(double t) const;
/*
* Evaluate the current traversal speed along the path, based on the currently
* traveled distance. The final speed will be scaled to match the desired duration
* for the path (which might have been specified by the user)
*/
double speedAlongPath(double traveledDistance);
Waypoint _start;
Waypoint _end;
double _duration;
double _duration; // seconds
CurveType _curveType;
std::unique_ptr<PathCurve> _curve;

View File

@@ -30,28 +30,46 @@
namespace openspace::interaction {
struct Waypoint;
class Waypoint;
class PathCurve {
public:
virtual ~PathCurve() = 0;
const double length() const;
/*
* Compute and rteturn the position along the path at the specified relative
* distance. The input parameter should be in range [0, 1], where 1 correspond to
* the full length of the path
*/
glm::dvec3 positionAt(double relativeDistance);
// Compute curve parameter u that matches the input arc length s
double curveParameter(double s);
/*
* Compute curve parameter u that matches the input arc length s
*/
virtual glm::dvec3 interpolate(double u);
/*
* Return the positions defining the control points for the spline interpolation
*/
std::vector<glm::dvec3> points();
protected:
// Precompute information related to the pspline parameters, that are
// needed for arc length reparameterization. Must be called after
// control point creation
/*
* Precompute information related to the spline parameters, that are
* needed for arc length reparameterization. Must be called after
* control point creation
*/
void initializeParameterData();
/*
* Compute curve parameter u that matches the input arc length s.
* Input s is a length value, in the range [0, _totalLength]. The returned curve
* parameter u is in range [0, 1]
*/
double curveParameter(double s);
double approximatedDerivative(double u, double h = 0.0001);
double arcLength(double limit = 1.0);
double arcLength(double lowerLimit, double upperLimit);

View File

@@ -31,7 +31,7 @@ namespace openspace { class SceneGraphNode; }
namespace openspace::interaction {
struct WayPoint;
class WayPoint;
class AvoidCollisionCurve : public PathCurve {
public:

View File

@@ -29,7 +29,7 @@
namespace openspace::interaction {
struct WayPoint;
class WayPoint;
class ZoomOutOverviewCurve : public PathCurve {
public:

View File

@@ -89,12 +89,20 @@ namespace openspace::splines {
// TODO: Move these to ghoul's interpolator file (and make template versions)
// Centripetal version alpha = 0, uniform for alpha = 0.5 and chordal for alpha = 1
/*
* Catmull-Rom curve interpolation based on implementation by Mika Rantanen
* https://qroph.github.io/2018/07/30/smooth-paths-using-catmull-rom-splines.html
* Centripetal version alpha = 0, uniform for alpha = 0.5 and chordal for alpha = 1
*/
glm::dvec3 catmullRom(double t, const glm::dvec3& p0, const glm::dvec3& p1,
const glm::dvec3& p2, const glm::dvec3& p3, double alpha = 0.5);
glm::dvec3 cubicBezier(double t, const glm::dvec3& cp1, const glm::dvec3& cp2,
const glm::dvec3& cp3, const glm::dvec3& cp4);
/*
* Compute the interpolation along the cubic Bézier curve defined by the points p0,
* p1, p2, and p3. The curve will pass through p0 and p3
*/
glm::dvec3 cubicBezier(double t, const glm::dvec3& p0, const glm::dvec3& p1,
const glm::dvec3& p2, const glm::dvec3& p3);
glm::dvec3 linear(double t, const glm::dvec3& cp1, const glm::dvec3& cp2);

View File

@@ -27,6 +27,7 @@
#include <openspace/camera/camerapose.h>
#include <ghoul/glm.h>
#include <string>
namespace openspace { class SceneGraphNode; }
@@ -34,20 +35,25 @@ namespace openspace::interaction {
struct NavigationState;
struct Waypoint {
class Waypoint {
public:
Waypoint() = default;
Waypoint(const glm::dvec3& pos, const glm::dquat& rot, const std::string& ref);
Waypoint(const NavigationState& ns);
static double findValidBoundingSphere(const SceneGraphNode* node);
CameraPose pose() const;
glm::dvec3 position() const;
glm::dquat rotation() const;
SceneGraphNode* node() const;
std::string nodeIdentifier() const;
double validBoundingSphere() const;
CameraPose pose;
std::string nodeIdentifier;
double validBoundingSphere = 0.0; // to be able to handle nodes with faulty bounding spheres
private:
CameraPose _pose;
std::string _nodeIdentifier;
double _validBoundingSphere = 0.0; // to be able to handle nodes with faulty bounding spheres
};
} // namespace openspace::interaction