Move camera path code into core and refactor navigation code a bit

This commit is contained in:
Emma Broman
2021-06-21 14:04:21 +02:00
parent 6c50b2a134
commit 77bdfaefd6
73 changed files with 3476 additions and 292 deletions

View File

@@ -0,0 +1,173 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___CAMERA___H__
#define __OPENSPACE_CORE___CAMERA___H__
#include <openspace/util/syncdata.h>
#include <ghoul/glm.h>
#include <mutex>
namespace openspace {
class SceneGraphNode;
/**
* This class still needs some more love. Suggested improvements:
* - Accessors should return constant references to double precision class members.
* - Remove the scaling variable (What is it used for?)
* - Remove the maxFov and sinMaxfov variables. Redundant since the fov is embedded
* within the perspective projection matrix.
* - Remove focusposition, part of the integration with the scale graph. The
* "focus position" should not be needed since we assume the camera is always
* positioned relative to its origin. When orbiting another object (not in origin),
* the focus position should probably be handled outside the camera class
* (interaction handler) since it does not affect the state of the camera
* (only how it interacts).
* - The class might need some more reasonable accessors depending on use cases.
* (up vector world space?)
* - Make clear which function returns a combined view matrix (things that are
* dependent on the separate sgct nodes).
*/
class Camera {
public:
/**
* Used to explicitly show which variables within the Camera class that are used
* for caching.
*/
template<typename T>
struct Cached {
T datum = T(0);
bool isDirty = true;
};
Camera() = default;
Camera(const Camera& o);
~Camera() = default;
// Mutators
void setPositionVec3(glm::dvec3 pos);
void setRotation(glm::dquat rotation);
void setScaling(float scaling);
void setMaxFov(float fov);
void setParent(SceneGraphNode* parent);
// Relative mutators
void rotate(glm::dquat rotation);
// Accessors
// Remove Vec3 from the name when psc is gone
const glm::dvec3& positionVec3() const;
glm::dvec3 eyePositionVec3() const;
const glm::dvec3& unsynchedPositionVec3() const;
const glm::dvec3& viewDirectionWorldSpace() const;
const glm::dvec3& lookUpVectorCameraSpace() const;
const glm::dvec3& lookUpVectorWorldSpace() const;
const glm::dmat4& viewRotationMatrix() const;
const glm::dmat4& viewScaleMatrix() const;
const glm::dquat& rotationQuaternion() const;
float maxFov() const;
float sinMaxFov() const;
SceneGraphNode* parent() const;
float scaling() const;
// @TODO this should simply be called viewMatrix!
// Or it needs to be changed so that it actually is combined. Right now it is
// only the view matrix that is the same for all SGCT cameras.
// Right now this function returns the actual combined matrix which makes some
// of the old calls to the function wrong..
const glm::dmat4& combinedViewMatrix() const;
void invalidateCache();
void serialize(std::ostream& os) const;
void deserialize(std::istream& is);
/**
* Handles SGCT's internal matrices. Also caches a calculated viewProjection
* matrix. This is the data that is different for different cameras within SGCT.
*/
class SgctInternal {
friend class Camera;
public:
void setSceneMatrix(glm::mat4 sceneMatrix);
void setViewMatrix(glm::mat4 viewMatrix);
void setProjectionMatrix(glm::mat4 projectionMatrix);
const glm::mat4& sceneMatrix() const;
const glm::mat4& viewMatrix() const;
const glm::mat4& projectionMatrix() const;
const glm::mat4& viewProjectionMatrix() const;
private:
SgctInternal() = default;
SgctInternal(const SgctInternal& o);
glm::mat4 _sceneMatrix = glm::mat4(1.f);
glm::mat4 _viewMatrix = glm::mat4(1.f);
glm::mat4 _projectionMatrix = glm::mat4(1.f);
mutable Cached<glm::mat4> _cachedViewProjectionMatrix;
mutable std::mutex _mutex;
} sgctInternal;
// @TODO use Camera::SgctInternal interface instead
// [[deprecated("Replaced by Camera::SgctInternal::viewMatrix()")]]
const glm::mat4& viewMatrix() const;
// [[deprecated("Replaced by Camera::SgctInternal::projectionMatrix()")]]
const glm::mat4& projectionMatrix() const;
// [[deprecated("Replaced by Camera::SgctInternal::viewProjectionMatrix()")]]
const glm::mat4& viewProjectionMatrix() const;
std::vector<Syncable*> getSyncables();
// Static constants
static const glm::dvec3 ViewDirectionCameraSpace;
static const glm::dvec3 UpDirectionCameraSpace;
private:
SyncData<glm::dvec3> _position = glm::dvec3(1.0, 1.0, 1.0);
SyncData<glm::dquat> _rotation = glm::dquat(glm::dvec3(1.0, 1.0, 1.0));
SyncData<float> _scaling = 1.f;
SceneGraphNode* _parent = nullptr;
// _focusPosition to be removed
glm::dvec3 _focusPosition = glm::dvec3(0.0);
float _maxFov = 0.f;
// Cached data
mutable Cached<glm::dvec3> _cachedViewDirection;
mutable Cached<glm::dvec3> _cachedLookupVector;
mutable Cached<glm::dmat4> _cachedViewRotationMatrix;
mutable Cached<glm::dmat4> _cachedViewScaleMatrix;
mutable Cached<glm::dmat4> _cachedCombinedViewMatrix;
mutable Cached<float> _cachedSinMaxFov;
mutable std::mutex _mutex;
};
} // namespace openspace
#endif // __OPENSPACE_CORE___CAMERA___H__

View File

@@ -0,0 +1,39 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___CAMERAPOSE___H__
#define __OPENSPACE_CORE___CAMERAPOSE___H__
#include <ghoul/glm.h>
namespace openspace {
struct CameraPose {
glm::dvec3 position = glm::dvec3(0.0);
glm::dquat rotation = glm::dquat(1.0, 0.0, 0.0, 0.0);
};
} // namespace openspace
#endif // __OPENSPACE_CORE___CAMERAPOSE___H__

View File

@@ -26,7 +26,7 @@
#define __OPENSPACE_CORE___SESSIONRECORDING___H__
#include <openspace/interaction/externinteraction.h>
#include <openspace/interaction/keyframenavigator.h>
#include <openspace/navigation/keyframenavigator.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/scripting/lualibrary.h>
#include <vector>

View File

@@ -25,8 +25,8 @@
#ifndef __OPENSPACE_CORE___KEYFRAMENAVIGATOR___H__
#define __OPENSPACE_CORE___KEYFRAMENAVIGATOR___H__
#include <openspace/util/timeline.h>
#include <openspace/network/messagestructures.h>
#include <openspace/util/timeline.h>
#include <ghoul/glm.h>
#include <ghoul/misc/boolean.h>
#include <glm/gtx/quaternion.hpp>

View File

@@ -28,10 +28,12 @@
#include <openspace/documentation/documentation.h>
#include <openspace/interaction/inputstate.h>
#include <openspace/interaction/joystickcamerastates.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/interaction/keyframenavigator.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/interaction/websocketcamerastates.h>
#include <openspace/navigation/keyframenavigator.h>
#include <openspace/navigation/navigationstate.h>
#include <openspace/navigation/orbitalnavigator.h>
#include <openspace/navigation/pathnavigator.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/util/mouse.h>
@@ -48,31 +50,14 @@ namespace openspace::scripting { struct LuaLibrary; }
namespace openspace::interaction {
struct JoystickInputStates;
struct NavigationState;
struct WebsocketInputStates;
class KeyframeNavigator;
class OrbitalNavigator;
class PathNavigator;
class NavigationHandler : public properties::PropertyOwner {
public:
struct NavigationState {
NavigationState() = default;
NavigationState(const ghoul::Dictionary& dictionary);
NavigationState(std::string anchor, std::string aim, std::string referenceFrame,
glm::dvec3 position, std::optional<glm::dvec3> up = std::nullopt,
double yaw = 0.0, double pitch = 0.0);
ghoul::Dictionary dictionary() const;
static documentation::Documentation Documentation();
std::string anchor;
std::string aim;
std::string referenceFrame;
glm::dvec3 position = glm::dvec3(0.0);
std::optional<glm::dvec3> up;
double yaw = 0.0;
double pitch = 0.0;
};
NavigationHandler();
~NavigationHandler();
@@ -80,11 +65,9 @@ public:
void deinitialize();
// Mutators
void setFocusNode(SceneGraphNode* node);
void resetCameraDirection();
void setNavigationStateNextFame(NavigationState state);
void setCamera(Camera* camera);
void setInterpolationTime(float durationInSeconds);
@@ -101,6 +84,7 @@ public:
const OrbitalNavigator& orbitalNavigator() const;
OrbitalNavigator& orbitalNavigator();
KeyframeNavigator& keyframeNavigator();
PathNavigator& pathNavigator();
bool isKeyFrameInteractionEnabled() const;
float interpolationTime() const;
@@ -154,7 +138,7 @@ public:
static scripting::LuaLibrary luaLibrary();
private:
void applyNavigationState(const NavigationHandler::NavigationState& ns);
void applyNavigationState(const NavigationState& ns);
bool _playbackModeEnabled = false;
@@ -164,6 +148,7 @@ private:
OrbitalNavigator _orbitalNavigator;
KeyframeNavigator _keyframeNavigator;
PathNavigator _pathNavigator;
std::optional<NavigationState> _pendingNavigationState;

View File

@@ -0,0 +1,59 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___NAVIGATIONSTATE___H__
#define __OPENSPACE_CORE___NAVIGATIONSTATE___H__
#include <openspace/documentation/documentation.h>
#include <optional>
namespace openspace {
struct CameraPose;
} // namespace openspace
namespace openspace::interaction {
struct NavigationState {
NavigationState() = default;
NavigationState(const ghoul::Dictionary& dictionary);
NavigationState(std::string anchor, std::string aim, std::string referenceFrame,
glm::dvec3 position, std::optional<glm::dvec3> up = std::nullopt,
double yaw = 0.0, double pitch = 0.0);
CameraPose cameraPose() const;
ghoul::Dictionary dictionary() const;
static documentation::Documentation Documentation();
std::string anchor;
std::string aim;
std::string referenceFrame;
glm::dvec3 position = glm::dvec3(0.0);
std::optional<glm::dvec3> up;
double yaw = 0.0;
double pitch = 0.0;
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___NAVIGATIONSTATE___H__

View File

@@ -46,6 +46,7 @@
namespace openspace {
class SceneGraphNode;
class Camera;
struct CameraPose;
struct SurfacePositionHandle;
} // namespace
@@ -104,11 +105,6 @@ private:
glm::dquat globalRotation = glm::dquat(1.0, 0.0, 0.0, 0.0);
};
struct CameraPose {
glm::dvec3 position = glm::dvec3(0.0);
glm::dquat rotation = glm::dquat(1.0, 0.0, 0.0, 0.0);
};
using Displacement = std::pair<glm::dvec3, glm::dvec3>;
struct Friction : public properties::PropertyOwner {

View File

@@ -0,0 +1,83 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___PATH___H__
#define __OPENSPACE_CORE___PATH___H__
#include <openspace/navigation/pathcurve.h>
#include <openspace/navigation/waypoint.h>
#include <optional>
#include <vector>
namespace openspace {
struct CameraPose;
} // namespace openspace
namespace openspace::interaction {
class Path {
public:
enum CurveType {
AvoidCollision,
Linear,
ZoomOutOverview
};
Path(Waypoint start, Waypoint end, CurveType type,
std::optional<double> duration = std::nullopt);
Waypoint startPoint() const;
Waypoint endPoint() const;
double duration() const;
double pathLength() const;
std::vector<glm::dvec3> controlPoints() const;
CameraPose traversePath(double dt);
std::string currentAnchor() const;
bool hasReachedEnd() const;
CameraPose interpolatedPose(double distance) const;
private:
glm::dquat interpolateRotation(double u) const;
double speedAlongPath(double traveledDistance);
Waypoint _start;
Waypoint _end;
double _duration;
CurveType _curveType;
std::unique_ptr<PathCurve> _curve;
double _speedFactorFromDuration = 1.0;
// Playback variables
double _traveledDistance = 0.0;
double _progressedTime = 0.0; // Time since playback started
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___PATH___H__

View File

@@ -0,0 +1,63 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___PATHCREATOR___H__
#define __OPENSPACE_CORE___PATHCREATOR___H__
#include <openspace/navigation/path.h>
#include <ghoul/glm.h>
#include <ghoul/misc/dictionary.h>
namespace openspace { class SceneGraphNode; }
namespace openspace::interaction {
struct Waypoint;
class PathCreator {
public:
// Create a path from a dictionary containing the instruction
static Path createPath(const ghoul::Dictionary& dictionary,
Path::CurveType curveType);
private:
struct NodeInfo {
std::string identifier;
std::optional<glm::dvec3> position;
std::optional<double> height;
bool useTargetUpDirection;
};
static Waypoint waypointFromCamera();
static Waypoint computeDefaultWaypoint(const NodeInfo& info,
const Waypoint& startPoint);
// Test if the node lies within a given proximity radius of any relevant node
// in the scene
static SceneGraphNode* findNodeNearTarget(const SceneGraphNode* node);
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___PATHCREATOR___H__

View File

@@ -0,0 +1,81 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___PATHCURVE___H__
#define __OPENSPACE_CORE___PATHCURVE___H__
#include <ghoul/glm.h>
#include <vector>
namespace openspace::interaction {
struct Waypoint;
class PathCurve {
public:
virtual ~PathCurve() = 0;
const double length() const;
glm::dvec3 positionAt(double relativeDistance);
// Compute curve parameter u that matches the input arc length s
double curveParameter(double s);
virtual glm::dvec3 interpolate(double u);
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
void initializeParameterData();
double approximatedDerivative(double u, double h = 0.0001);
double arcLength(double limit = 1.0);
double arcLength(double lowerLimit, double upperLimit);
std::vector<glm::dvec3> _points;
unsigned int _nSegments;
std::vector<double> _curveParameterSteps; // per segment
std::vector<double> _lengthSums; // per segment
double _totalLength;
struct ParameterPair {
double u; // curve parameter
double s; // arc length parameter
};
std::vector<ParameterPair> _parameterSamples;
};
class LinearCurve : public PathCurve {
public:
LinearCurve(const Waypoint& start, const Waypoint& end);
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___PATHCURVE___H__

View File

@@ -0,0 +1,48 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___AVOIDCOLLISIONCURVE___H__
#define __OPENSPACE_CORE___AVOIDCOLLISIONCURVE___H__
#include <openspace/navigation/pathcurve.h>
namespace openspace { class SceneGraphNode; }
namespace openspace::interaction {
struct WayPoint;
class AvoidCollisionCurve : public PathCurve {
public:
AvoidCollisionCurve(const Waypoint& start, const Waypoint& end);
private:
void removeCollisions(int step = 0);
std::vector<SceneGraphNode*> _relevantNodes;
};
} // namespace openspace::interaction
#endif // __OPENSPACE_MODULE_AUTONAVIGATION___AVOIDCOLLISIONCURVE___H__

View File

@@ -0,0 +1,41 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___ZOOMOUTOVERVIEWCURVE___H__
#define __OPENSPACE_CORE___ZOOMOUTOVERVIEWCURVE___H__
#include <openspace/navigation/pathcurve.h>
namespace openspace::interaction {
struct WayPoint;
class ZoomOutOverviewCurve : public PathCurve {
public:
ZoomOutOverviewCurve(const Waypoint& start, const Waypoint& end);
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___ZOOMOUTOVERVIEWCURVE___H__

View File

@@ -0,0 +1,83 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___PATHHELPERFUNCTIONS___H__
#define __OPENSPACE_CORE___PATHHELPERFUNCTIONS___H__
#include <ghoul/glm.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
namespace openspace::interaction::helpers {
// Make interpolator parameter t [0,1] progress only inside a subinterval
double shiftAndScale(double t, double newStart, double newEnd);
glm::dquat lookAtQuaternion(glm::dvec3 eye, glm::dvec3 center, glm::dvec3 up);
glm::dvec3 viewDirection(const glm::dquat& q);
bool lineSphereIntersection(glm::dvec3 linePoint1, glm::dvec3 linePoint2,
glm::dvec3 sphereCenter, double spehereRadius, glm::dvec3& intersectionPoint);
bool isPointInsideSphere(const glm::dvec3& p, const glm::dvec3& c, double r);
double simpsonsRule(double t0, double t1, int n, std::function<double(double)> f);
double fivePointGaussianQuadrature(double t0, double t1,
std::function<double(double)> f);
} // namespace openspace::interaction::helpers
namespace openspace::interaction::interpolation {
glm::dquat easedSlerp(const glm::dquat q1, const glm::dquat q2, double t);
// TODO: make all these into template functions.
// Alternatively, add cubicBezier interpolation in ghoul and only use
// ghoul's interpolator methods
// 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);
glm::dvec3 linear(double t, const glm::dvec3& cp1, const glm::dvec3& cp2);
glm::dvec3 hermite(double t, const glm::dvec3 &cp1, const glm::dvec3 &cp2,
const glm::dvec3 &tangent1, const glm::dvec3 &tangent2);
glm::dvec3 piecewiseCubicBezier(double t, const std::vector<glm::dvec3>& points,
const std::vector<double>& tKnots);
glm::dvec3 piecewiseLinear(double t, const std::vector<glm::dvec3>& points,
const std::vector<double>& tKnots);
} // namespace openspace::interaction::interpolation
#endif // __OPENSPACE_CORE___PATHHELPERFUNCTIONS___H__

View File

@@ -0,0 +1,121 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___PATHNAVIGATOR___H__
#define __OPENSPACE_CORE___PATHNAVIGATOR___H__
#include <openspace/properties/propertyowner.h>
#include <openspace/navigation/path.h>
#include <openspace/properties/list/stringlistproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/doubleproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <ghoul/glm.h>
#include <memory>
namespace openspace {
class Camera;
struct CameraPose;
class SceneGraphNode;
} // namespace openspace
namespace openspace::scripting { struct LuaLibrary; }
namespace openspace::interaction {
class Path;
class PathNavigator : public properties::PropertyOwner {
public:
enum StopBehavior {
None = 0,
Orbit
};
PathNavigator();
~PathNavigator();
// Accessors
Camera* camera() const;
const SceneGraphNode* anchor() const;
double speedScale() const;
bool hasCurrentPath() const;
bool hasFinished() const;
bool isPlayingPath() const;
void updateCamera(double deltaTime);
void createPath(const ghoul::Dictionary& dictionary);
void clearPath();
void startPath();
void abortPath();
void pausePath();
void continuePath();
// TODO: remove functions for debugging
std::vector<glm::dvec3> curvePositions(int nSteps) const;
std::vector<glm::dquat> curveOrientations(int nSteps) const;
std::vector<glm::dvec3> curveViewDirections(int nSteps) const;
std::vector<glm::dvec3> controlPoints() const;
double minValidBoundingSphere() const;
const std::vector<SceneGraphNode*>& relevantNodes();
/**
* \return The Lua library that contains all Lua functions available to affect the
* path navigation
*/
static scripting::LuaLibrary luaLibrary();
private:
void findRelevantNodes();
void removeRollRotation(CameraPose& pose, double deltaTime);
void applyStopBehavior(double deltaTime);
void orbitAnchorNode(double deltaTime);
std::unique_ptr<Path> _currentPath = nullptr;
bool _isPlaying = false;
properties::OptionProperty _defaultCurveOption;
properties::BoolProperty _includeRoll;
properties::FloatProperty _speedScale;
properties::FloatProperty _orbitSpeedFactor;
properties::BoolProperty _applyStopBehaviorWhenIdle;
properties::OptionProperty _stopBehavior;
properties::DoubleProperty _minValidBoundingSphere;
properties::StringListProperty _relevantNodeTags;
std::vector<SceneGraphNode*> _relevantNodes;
bool _hasInitializedRelevantNodes = false;
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___PATHNAVIGATOR___H__

View File

@@ -0,0 +1,55 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2021 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___WAYPOINT___H__
#define __OPENSPACE_CORE___WAYPOINT___H__
#include <openspace/camera/camerapose.h>
#include <ghoul/glm.h>
namespace openspace { class SceneGraphNode; }
namespace openspace::interaction {
struct NavigationState;
struct Waypoint {
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);
glm::dvec3 position() const;
glm::dquat rotation() const;
SceneGraphNode* node() const;
CameraPose pose;
std::string nodeIdentifier;
double validBoundingSphere = 0.0; // to be able to handle nodes with faulty bounding spheres
};
} // namespace openspace::interaction
#endif // __OPENSPACE_CORE___WAYPOINT___H__

View File

@@ -26,9 +26,9 @@
#define __OPENSPACE_CORE___PROFILE___H__
#include <openspace/engine/globals.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/util/keys.h>
#include <ghoul/glm.h>
#include <ghoul/misc/exception.h>
#include <optional>
#include <string>
@@ -37,6 +37,8 @@
namespace openspace {
namespace interaction { struct NavigationState; }
namespace scripting { struct LuaLibrary; }
class Profile {
@@ -127,8 +129,7 @@ public:
* and all of the property & asset changes that were made since startup.
*/
void saveCurrentSettingsToProfile(const properties::PropertyOwner& rootOwner,
std::string currentTime,
interaction::NavigationHandler::NavigationState navState);
std::string currentTime, interaction::NavigationState navState);
/// If the value passed to this function is 'true', the addAsset and removeAsset
/// functions will be no-ops instead

View File

@@ -25,8 +25,8 @@
#ifndef __OPENSPACE_CORE___SCRIPTSCHEDULER___H__
#define __OPENSPACE_CORE___SCRIPTSCHEDULER___H__
#include <openspace/navigation/keyframenavigator.h>
#include <openspace/scripting/lualibrary.h>
#include <openspace/interaction/keyframenavigator.h>
#include <functional>
#include <queue>

View File

@@ -25,7 +25,7 @@
#ifndef __OPENSPACE_CORE___UPDATESTRUCTURES___H__
#define __OPENSPACE_CORE___UPDATESTRUCTURES___H__
#include <openspace/util/camera.h>
#include <openspace/camera/camera.h>
#include <openspace/util/time.h>
namespace openspace {