mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 00:38:33 -05:00
Interaction Updates (#353)
* Interaction speed is not dependent on framerate * Split up interaction code in files and perform smooth interpolation when changing focus * Abstract interaction code in to functions. * Interpolation time is dependent on angle to focus node. * Use correct delta time when interpolating * Fix bug regarding decomposition of camera rotation. * Make orbital interaction mode behave as globe browsing and no longer use interactiondepth below ellipsoid. * Do not always rotate with object. Depending on distance * Remove interaction depth below ellipsoid. Now able to interact without renderable * Remove specification of interactionDepthBelowEllipsoid and cameraMinHeight * Remove GlobeBrowsingInteractionMode * Rename OrbitalInteractionMode to OrbitalNavigator and no longer extend interactionmode. * Move properties from interaction handler to orbital navigator * Use smooth step for follow rotation interpolator * Rename KeyframeInteractionMode to KeyframeNavigator * Rename files * Clean up. * Separate mousestate from orbitalnavigator * Clean up * Split keybindingmanager from interactionhandler interactionhandler * Rename interactionhandler to navigationhandler * Rename files * Clean up * Take back usage of gotochunk and gotogeo * Rename lua library navigation * Move functionality from navigationhandler to keyframenavigator * Update scripts for navigation * Comment code * Clean up * Solve but that caused NaN values for camera position when being in center of globe and setting focus to the globe. * Update jenkins file to remove build folder before building. * Fix error in jenkins script * Update jenkins file * Update jenkins file * Revert jenkins file * I hope this makes Jenkins happy. * Line endings God damnit * Line endings * Clean up * Fix compilation issue * Take back default scene. * Fix indentation * Move functions goToGeo and goToChunk to GlobeBrowsingModule. * Include algorithm for std::find * Remove auto and other clean up
This commit is contained in:
@@ -62,7 +62,10 @@ class SyncEngine;
|
||||
class TimeManager;
|
||||
class WindowWrapper;
|
||||
|
||||
namespace interaction { class InteractionHandler; }
|
||||
namespace interaction {
|
||||
class NavigationHandler;
|
||||
class KeyBindingManager;
|
||||
}
|
||||
namespace gui { class GUI; }
|
||||
namespace properties { class PropertyOwner; }
|
||||
namespace scripting {
|
||||
@@ -123,7 +126,8 @@ public:
|
||||
TimeManager& timeManager();
|
||||
WindowWrapper& windowWrapper();
|
||||
ghoul::fontrendering::FontManager& fontManager();
|
||||
interaction::InteractionHandler& interactionHandler();
|
||||
interaction::NavigationHandler& navigationHandler();
|
||||
interaction::KeyBindingManager& keyBindingManager();
|
||||
properties::PropertyOwner& globalPropertyOwner();
|
||||
scripting::ScriptEngine& scriptEngine();
|
||||
scripting::ScriptScheduler& scriptScheduler();
|
||||
@@ -197,7 +201,8 @@ private:
|
||||
std::unique_ptr<WindowWrapper> _windowWrapper;
|
||||
std::unique_ptr<ghoul::cmdparser::CommandlineParser> _commandlineParser;
|
||||
std::unique_ptr<ghoul::fontrendering::FontManager> _fontManager;
|
||||
std::unique_ptr<interaction::InteractionHandler> _interactionHandler;
|
||||
std::unique_ptr<interaction::NavigationHandler> _navigationHandler;
|
||||
std::unique_ptr<interaction::KeyBindingManager> _keyBindingManager;
|
||||
std::unique_ptr<scripting::ScriptEngine> _scriptEngine;
|
||||
std::unique_ptr<scripting::ScriptScheduler> _scriptScheduler;
|
||||
std::unique_ptr<VirtualPropertyManager> _virtualPropertyManager;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
class InteractionHandler;
|
||||
class NavigationHandler;
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
@@ -41,10 +41,10 @@ public:
|
||||
_handler(nullptr)
|
||||
{}
|
||||
|
||||
void setHandler(InteractionHandler* handler);
|
||||
void setHandler(NavigationHandler* handler);
|
||||
|
||||
protected:
|
||||
InteractionHandler* _handler;
|
||||
NavigationHandler* _handler;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
|
||||
59
include/openspace/interaction/delayedvariable.h
Normal file
59
include/openspace/interaction/delayedvariable.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___DELAYEDVARIABLE___H__
|
||||
#define __OPENSPACE_CORE___DELAYEDVARIABLE___H__
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
/**
|
||||
* Class that acts as a smoothing filter to a variable. The filter has a step
|
||||
* response on a form that resembles the function y = 1-e^(-t/scale). The variable
|
||||
* will be updated as soon as it is set to a value (calling the set() function).
|
||||
*/
|
||||
template <typename T, typename ScaleType>
|
||||
class DelayedVariable {
|
||||
public:
|
||||
DelayedVariable(ScaleType scaleFactor, ScaleType friction);
|
||||
void set(T value, double dt);
|
||||
void decelerate(double dt);
|
||||
void setHard(T value);
|
||||
void setFriction(ScaleType friction);
|
||||
void setScaleFactor(ScaleType scaleFactor);
|
||||
T get() const;
|
||||
|
||||
private:
|
||||
ScaleType _scaleFactor;
|
||||
ScaleType _friction;
|
||||
T _targetValue;
|
||||
T _currentValue;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#include "delayedvariable.inl"
|
||||
|
||||
#endif // __OPENSPACE_CORE___DELAYEDVARIABLE___H__
|
||||
76
include/openspace/interaction/delayedvariable.inl
Normal file
76
include/openspace/interaction/delayedvariable.inl
Normal file
@@ -0,0 +1,76 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
template <typename T, typename ScaleType>
|
||||
DelayedVariable<T, ScaleType>::DelayedVariable(ScaleType scaleFactor, ScaleType friction)
|
||||
: _scaleFactor(std::move(scaleFactor))
|
||||
, _friction(friction)
|
||||
{
|
||||
ghoul_assert(_friction >= ScaleType(0.0), "Friction must be positive");
|
||||
}
|
||||
|
||||
template <typename T, typename ScaleType>
|
||||
void DelayedVariable<T, ScaleType>::set(T value, double dt) {
|
||||
_targetValue = value;
|
||||
_currentValue = _currentValue + (_targetValue - _currentValue) *
|
||||
glm::min(_scaleFactor * dt, 1.0); // less or equal to 1.0 keeps it stable
|
||||
}
|
||||
|
||||
template <typename T, typename ScaleType>
|
||||
void DelayedVariable<T, ScaleType>::decelerate(double dt) {
|
||||
_currentValue = _currentValue + (- _currentValue) *
|
||||
glm::min(_scaleFactor * _friction * dt, 1.0);
|
||||
// less or equal to 1.0 keeps it stable
|
||||
}
|
||||
|
||||
template <typename T, typename ScaleType>
|
||||
void DelayedVariable<T, ScaleType>::setHard(T value) {
|
||||
_targetValue = value;
|
||||
_currentValue = value;
|
||||
}
|
||||
|
||||
template <typename T, typename ScaleType>
|
||||
void DelayedVariable<T, ScaleType>::setFriction(ScaleType friction) {
|
||||
_friction = friction;
|
||||
ghoul_assert(_friction >= ScaleType(0.0), "Friction must be positive");
|
||||
}
|
||||
|
||||
template <typename T, typename ScaleType>
|
||||
void DelayedVariable<T, ScaleType>::setScaleFactor(ScaleType scaleFactor) {
|
||||
_scaleFactor = scaleFactor;
|
||||
}
|
||||
|
||||
template <typename T, typename ScaleType>
|
||||
T DelayedVariable<T, ScaleType>::get() const {
|
||||
return _currentValue;
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
70
include/openspace/interaction/inputstate.h
Normal file
70
include/openspace/interaction/inputstate.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___INPUTSTATE___H__
|
||||
#define __OPENSPACE_CORE___INPUTSTATE___H__
|
||||
|
||||
#include <openspace/util/keys.h>
|
||||
#include <openspace/util/mouse.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
class InputState {
|
||||
public:
|
||||
InputState() = default;
|
||||
~InputState() = default;
|
||||
|
||||
// Callback functions
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
void mouseButtonCallback(MouseButton button, MouseAction action);
|
||||
void mousePositionCallback(double mouseX, double mouseY);
|
||||
void mouseScrollWheelCallback(double mouseScrollDelta);
|
||||
|
||||
// Accessors
|
||||
const std::list<std::pair<Key, KeyModifier>>& getPressedKeys() const;
|
||||
const std::list<MouseButton>& getPressedMouseButtons() const;
|
||||
glm::dvec2 getMousePosition() const;
|
||||
double getMouseScrollDelta() const;
|
||||
|
||||
bool isKeyPressed(std::pair<Key, KeyModifier> keyModPair) const;
|
||||
bool isKeyPressed(Key key) const;
|
||||
bool isMouseButtonPressed(MouseButton mouseButton) const;
|
||||
|
||||
private:
|
||||
// Input from keyboard and mouse
|
||||
std::list<std::pair<Key, KeyModifier>> _keysDown;
|
||||
std::list<MouseButton> _mouseButtonsDown;
|
||||
glm::dvec2 _mousePosition;
|
||||
double _mouseScrollDelta;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___INPUTSTATE___H__
|
||||
@@ -1,286 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___INTERACTIONMODE___H__
|
||||
#define __OPENSPACE_CORE___INTERACTIONMODE___H__
|
||||
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/util/mouse.h>
|
||||
#include <openspace/util/keys.h>
|
||||
#include <openspace/util/timeline.h>
|
||||
|
||||
#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED
|
||||
#include <modules/globebrowsing/tile/tileindex.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic2.h>
|
||||
#include <modules/globebrowsing/geometry/geodetic3.h>
|
||||
#endif
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera;
|
||||
class SceneGraphNode;
|
||||
|
||||
namespace globebrowsing {
|
||||
class RenderableGlobe;
|
||||
}
|
||||
|
||||
namespace interaction {
|
||||
|
||||
template <typename T>
|
||||
class Interpolator
|
||||
{
|
||||
public:
|
||||
Interpolator(std::function<T(double)> transferFunction)
|
||||
: _t(0.0)
|
||||
, _transferFunction(transferFunction) {};
|
||||
~Interpolator() {};
|
||||
|
||||
void start() { _t = 0.0; };
|
||||
void end() { _t = 1.0; };
|
||||
void step(double delta) { _t += delta; };
|
||||
|
||||
T value() { return _transferFunction(_t); };
|
||||
bool isInterpolating() { return _t < 1.0; };
|
||||
private:
|
||||
std::function<T(double)> _transferFunction;
|
||||
double _t;
|
||||
};
|
||||
|
||||
class InputState
|
||||
{
|
||||
public:
|
||||
InputState();
|
||||
~InputState();
|
||||
|
||||
// Callback functions
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
void mouseButtonCallback(MouseButton button, MouseAction action);
|
||||
void mousePositionCallback(double mouseX, double mouseY);
|
||||
void mouseScrollWheelCallback(double mouseScrollDelta);
|
||||
|
||||
// Accessors
|
||||
const std::list<std::pair<Key, KeyModifier> >& getPressedKeys() const;
|
||||
const std::list<MouseButton>& getPressedMouseButtons() const;
|
||||
glm::dvec2 getMousePosition() const;
|
||||
double getMouseScrollDelta() const;
|
||||
const std::vector<datamessagestructures::CameraKeyframe>& keyframes() const;
|
||||
|
||||
bool isKeyPressed(std::pair<Key, KeyModifier> keyModPair) const;
|
||||
bool isKeyPressed(Key key) const;
|
||||
bool isMouseButtonPressed(MouseButton mouseButton) const;
|
||||
private:
|
||||
// Input from keyboard and mouse
|
||||
std::list<std::pair<Key, KeyModifier> > _keysDown;
|
||||
std::list<MouseButton> _mouseButtonsDown;
|
||||
glm::dvec2 _mousePosition;
|
||||
double _mouseScrollDelta;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class InteractionMode {
|
||||
public:
|
||||
InteractionMode();
|
||||
virtual ~InteractionMode();
|
||||
|
||||
// Mutators
|
||||
virtual void setFocusNode(SceneGraphNode* focusNode);
|
||||
|
||||
// Accessors
|
||||
SceneGraphNode* focusNode();
|
||||
Interpolator<double>& rotateToFocusNodeInterpolator();
|
||||
virtual bool followingNodeRotation() const = 0;
|
||||
|
||||
virtual void updateMouseStatesFromInput(const InputState& inputState, double deltaTime) = 0;
|
||||
virtual void updateCameraStateFromMouseStates(Camera& camera, double deltaTime) = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
Inner class that acts as a smoothing filter to a variable. The filter has a step
|
||||
response on a form that resembles the function y = 1-e^(-t/scale). The variable
|
||||
will be updates as soon as it is set to a value (calling the set() function).
|
||||
*/
|
||||
template <typename T, typename ScaleType>
|
||||
class DelayedVariable {
|
||||
public:
|
||||
DelayedVariable(ScaleType scaleFactor, ScaleType friction) {
|
||||
_scaleFactor = scaleFactor;
|
||||
_friction = glm::max(friction, ScaleType(0.0));
|
||||
}
|
||||
void set(T value, double dt) {
|
||||
_targetValue = value;
|
||||
_currentValue = _currentValue + (_targetValue - _currentValue) *
|
||||
std::min(_scaleFactor * dt, 1.0); // less or equal to 1.0 keeps it stable
|
||||
}
|
||||
void decelerate(double dt) {
|
||||
_currentValue = _currentValue + (- _currentValue) *
|
||||
std::min(_scaleFactor * _friction * dt, 1.0); // less or equal to 1.0 keeps it stable
|
||||
}
|
||||
void setHard(T value) {
|
||||
_targetValue = value;
|
||||
_currentValue = value;
|
||||
}
|
||||
void setFriction(ScaleType friction) {
|
||||
_friction = glm::max(friction, ScaleType(0.0));
|
||||
}
|
||||
void setScaleFactor(ScaleType scaleFactor) {
|
||||
_scaleFactor = scaleFactor;
|
||||
}
|
||||
T get() {
|
||||
return _currentValue;
|
||||
}
|
||||
private:
|
||||
ScaleType _scaleFactor;
|
||||
ScaleType _friction;
|
||||
T _targetValue;
|
||||
T _currentValue;
|
||||
};
|
||||
|
||||
struct MouseState {
|
||||
MouseState(double scaleFactor)
|
||||
: velocity(scaleFactor, 1)
|
||||
, previousPosition(0.0, 0.0) {}
|
||||
void setFriction(double friction) {
|
||||
velocity.setFriction(friction);
|
||||
}
|
||||
void setVelocityScaleFactor(double scaleFactor) {
|
||||
velocity.setScaleFactor(scaleFactor);
|
||||
}
|
||||
glm::dvec2 previousPosition;
|
||||
DelayedVariable<glm::dvec2, double> velocity;
|
||||
};
|
||||
|
||||
SceneGraphNode* _focusNode = nullptr;
|
||||
glm::dvec3 _previousFocusNodePosition;
|
||||
glm::dquat _previousFocusNodeRotation;
|
||||
|
||||
|
||||
Interpolator<double> _rotateToFocusNodeInterpolator;
|
||||
};
|
||||
|
||||
class KeyframeInteractionMode : public InteractionMode
|
||||
{
|
||||
public:
|
||||
struct CameraPose {
|
||||
glm::dvec3 position;
|
||||
glm::quat rotation;
|
||||
std::string focusNode;
|
||||
bool followFocusNodeRotation;
|
||||
};
|
||||
|
||||
KeyframeInteractionMode();
|
||||
~KeyframeInteractionMode();
|
||||
|
||||
virtual void updateMouseStatesFromInput(const InputState& inputState, double deltaTime);
|
||||
virtual void updateCameraStateFromMouseStates(Camera& camera, double deltaTime);
|
||||
bool followingNodeRotation() const override;
|
||||
Timeline<CameraPose>& timeline();
|
||||
|
||||
private:
|
||||
Timeline<CameraPose> _cameraPoseTimeline;
|
||||
};
|
||||
|
||||
class GlobeBrowsingInteractionMode;
|
||||
|
||||
class OrbitalInteractionMode : public InteractionMode
|
||||
{
|
||||
public:
|
||||
class MouseStates
|
||||
{
|
||||
public:
|
||||
/**
|
||||
\param sensitivity
|
||||
\param velocityScaleFactor can be set to 60 to remove the inertia of the
|
||||
interaction. Lower value will make it harder to move the camera.
|
||||
*/
|
||||
MouseStates(double sensitivity, double velocityScaleFactor);
|
||||
void updateMouseStatesFromInput(const InputState& inputState, double deltaTime);
|
||||
void setRotationalFriction(double friction);
|
||||
void setHorizontalFriction(double friction);
|
||||
void setVerticalFriction(double friction);
|
||||
void setSensitivity(double sensitivity);
|
||||
void setVelocityScaleFactor(double scaleFactor);
|
||||
|
||||
glm::dvec2 synchedGlobalRotationMouseVelocity();
|
||||
glm::dvec2 synchedLocalRotationMouseVelocity();
|
||||
glm::dvec2 synchedTruckMovementMouseVelocity();
|
||||
glm::dvec2 synchedLocalRollMouseVelocity();
|
||||
glm::dvec2 synchedGlobalRollMouseVelocity();
|
||||
|
||||
private:
|
||||
double _sensitivity;
|
||||
|
||||
MouseState _globalRotationMouseState;
|
||||
MouseState _localRotationMouseState;
|
||||
MouseState _truckMovementMouseState;
|
||||
MouseState _localRollMouseState;
|
||||
MouseState _globalRollMouseState;
|
||||
};
|
||||
|
||||
OrbitalInteractionMode(std::shared_ptr<MouseStates> mouseStates);
|
||||
~OrbitalInteractionMode();
|
||||
|
||||
//virtual void update(Camera& camera, const InputState& inputState, double deltaTime);
|
||||
|
||||
virtual void updateMouseStatesFromInput(const InputState& inputState, double deltaTime);
|
||||
virtual void updateCameraStateFromMouseStates(Camera& camera, double deltaTime);
|
||||
bool followingNodeRotation() const override;
|
||||
|
||||
protected:
|
||||
//void updateCameraStateFromMouseStates(Camera& camera, double deltaTime);
|
||||
std::shared_ptr<MouseStates> _mouseStates;
|
||||
};
|
||||
|
||||
class GlobeBrowsingInteractionMode : public OrbitalInteractionMode
|
||||
{
|
||||
public:
|
||||
GlobeBrowsingInteractionMode(std::shared_ptr<MouseStates> mouseStates);
|
||||
~GlobeBrowsingInteractionMode();
|
||||
|
||||
virtual void setFocusNode(SceneGraphNode* focusNode);
|
||||
//virtual void update(Camera& camera, const InputState& inputState, double deltaTime);
|
||||
virtual void updateCameraStateFromMouseStates(Camera& camera, double deltaTime);
|
||||
bool followingNodeRotation() const override;
|
||||
#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED
|
||||
void goToChunk(Camera& camera, globebrowsing::TileIndex ti, glm::vec2 uv,
|
||||
bool resetCameraDirection);
|
||||
void goToGeodetic2(Camera& camera, globebrowsing::Geodetic2 geo2,
|
||||
bool resetCameraDirection);
|
||||
|
||||
void goToGeodetic3(Camera& camera, globebrowsing::Geodetic3 geo3);
|
||||
void resetCameraDirection(Camera& camera, globebrowsing::Geodetic2 geo2);
|
||||
#endif
|
||||
private:
|
||||
//void updateCameraStateFromMouseStates(Camera& camera, double deltaTime);
|
||||
#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED
|
||||
globebrowsing::RenderableGlobe* _globe;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___INTERACTIONMODE___H__
|
||||
65
include/openspace/interaction/interpolator.h
Normal file
65
include/openspace/interaction/interpolator.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___INTERPOLATOR___H__
|
||||
#define __OPENSPACE_CORE___INTERPOLATOR___H__
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
/*
|
||||
* Interpolates a typename T using a transfer function.
|
||||
*/
|
||||
template <typename T>
|
||||
class Interpolator {
|
||||
public:
|
||||
Interpolator();
|
||||
~Interpolator() = default;
|
||||
|
||||
void start();
|
||||
void end();
|
||||
void setDeltaTime(float deltaTime);
|
||||
void setTransferFunction(std::function<T(float)> transferFunction);
|
||||
void setInterpolationTime(float interpolationTime);
|
||||
void step();
|
||||
|
||||
float deltaTimeScaled() const;
|
||||
T value() const;
|
||||
bool isInterpolating() const;
|
||||
|
||||
private:
|
||||
std::function<T(float)> _transferFunction;
|
||||
float _t;
|
||||
float _interpolationTime;
|
||||
float _scaledDeltaTime;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#include "interpolator.inl"
|
||||
|
||||
#endif // __OPENSPACE_CORE___INTERPOLATOR___H__
|
||||
85
include/openspace/interaction/interpolator.inl
Normal file
85
include/openspace/interaction/interpolator.inl
Normal file
@@ -0,0 +1,85 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
template <typename T>
|
||||
Interpolator<T>::Interpolator()
|
||||
: _transferFunction([](float t){ return t; })
|
||||
, _t(0.0)
|
||||
, _interpolationTime(1.0) {};
|
||||
|
||||
template <typename T>
|
||||
void Interpolator<T>::start() {
|
||||
_t = 0.0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void Interpolator<T>::end() {
|
||||
_t = 1.0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Interpolator<T>::setDeltaTime(float deltaTime) {
|
||||
_scaledDeltaTime = deltaTime / _interpolationTime;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Interpolator<T>::setTransferFunction(std::function<T(float)> transferFunction) {
|
||||
_transferFunction = transferFunction;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Interpolator<T>::setInterpolationTime(float interpolationTime) {
|
||||
_interpolationTime = interpolationTime;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Interpolator<T>::step() {
|
||||
_t += _scaledDeltaTime;
|
||||
_t = glm::clamp(_t, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
float Interpolator<T>::deltaTimeScaled() const {
|
||||
return _scaledDeltaTime;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Interpolator<T>::value() const {
|
||||
return _transferFunction(_t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Interpolator<T>::isInterpolating() const {
|
||||
return _t < 1.0 && _t >= 0.0;
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
87
include/openspace/interaction/keybindingmanager.h
Normal file
87
include/openspace/interaction/keybindingmanager.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___KEYBINDINGMANAGER___H__
|
||||
#define __OPENSPACE_CORE___KEYBINDINGMANAGER___H__
|
||||
|
||||
#include <openspace/documentation/documentationgenerator.h>
|
||||
#include <openspace/scripting/lualibrary.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
#include <ghoul/misc/boolean.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera;
|
||||
class SceneGraphNode;
|
||||
|
||||
namespace interaction {
|
||||
|
||||
class KeyBindingManager : public DocumentationGenerator
|
||||
{
|
||||
public:
|
||||
KeyBindingManager();
|
||||
~KeyBindingManager() = default;
|
||||
|
||||
void resetKeyBindings();
|
||||
|
||||
void bindKeyLocal(
|
||||
Key key,
|
||||
KeyModifier modifier,
|
||||
std::string luaCommand,
|
||||
std::string documentation = ""
|
||||
);
|
||||
|
||||
void bindKey(
|
||||
Key key,
|
||||
KeyModifier modifier,
|
||||
std::string luaCommand,
|
||||
std::string documentation = ""
|
||||
);
|
||||
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
|
||||
// Callback functions
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
|
||||
private:
|
||||
using Synchronized = ghoul::Boolean;
|
||||
|
||||
struct KeyInformation {
|
||||
std::string command;
|
||||
Synchronized synchronization;
|
||||
std::string documentation;
|
||||
};
|
||||
|
||||
std::string generateJson() const override;
|
||||
|
||||
bool _cameraUpdatedFromScript = false;
|
||||
|
||||
std::multimap<KeyWithModifier, KeyInformation> _keyLua;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___KEYBINDINGMANAGER___H__
|
||||
69
include/openspace/interaction/keyframenavigator.h
Normal file
69
include/openspace/interaction/keyframenavigator.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___KEYFRAMENAVIGATOR___H__
|
||||
#define __OPENSPACE_CORE___KEYFRAMENAVIGATOR___H__
|
||||
|
||||
#include <openspace/util/timeline.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera;
|
||||
|
||||
namespace interaction {
|
||||
|
||||
class KeyframeNavigator
|
||||
{
|
||||
public:
|
||||
struct CameraPose {
|
||||
glm::dvec3 position;
|
||||
glm::quat rotation;
|
||||
std::string focusNode;
|
||||
bool followFocusNodeRotation;
|
||||
};
|
||||
|
||||
KeyframeNavigator() = default;
|
||||
~KeyframeNavigator() = default;
|
||||
|
||||
void updateCamera(Camera& camera);
|
||||
Timeline<CameraPose>& timeline();
|
||||
|
||||
void addKeyframe(double timestamp, KeyframeNavigator::CameraPose pose);
|
||||
void removeKeyframesAfter(double timestamp);
|
||||
void clearKeyframes();
|
||||
size_t nKeyframes() const;
|
||||
const std::vector<datamessagestructures::CameraKeyframe>& keyframes() const;
|
||||
|
||||
private:
|
||||
Timeline<CameraPose> _cameraPoseTimeline;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___KEYFRAMENAVIGATOR___H__
|
||||
80
include/openspace/interaction/mousestate.h
Normal file
80
include/openspace/interaction/mousestate.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___MOUSESTATE___H__
|
||||
#define __OPENSPACE_CORE___MOUSESTATE___H__
|
||||
|
||||
#include <openspace/interaction/delayedvariable.h>
|
||||
#include <openspace/interaction/inputstate.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
struct MouseState {
|
||||
MouseState(double scaleFactor);
|
||||
void setFriction(double friction);
|
||||
void setVelocityScaleFactor(double scaleFactor);
|
||||
|
||||
glm::dvec2 previousPosition;
|
||||
DelayedVariable<glm::dvec2, double> velocity;
|
||||
};
|
||||
|
||||
class MouseStates
|
||||
{
|
||||
public:
|
||||
/**
|
||||
\param sensitivity
|
||||
\param velocityScaleFactor can be set to 60 to remove the inertia of the
|
||||
interaction. Lower value will make it harder to move the camera.
|
||||
*/
|
||||
MouseStates(double sensitivity, double velocityScaleFactor);
|
||||
void updateMouseStatesFromInput(const InputState& inputState, double deltaTime);
|
||||
void setRotationalFriction(double friction);
|
||||
void setHorizontalFriction(double friction);
|
||||
void setVerticalFriction(double friction);
|
||||
void setSensitivity(double sensitivity);
|
||||
void setVelocityScaleFactor(double scaleFactor);
|
||||
|
||||
glm::dvec2 globalRotationMouseVelocity() const;
|
||||
glm::dvec2 localRotationMouseVelocity() const;
|
||||
glm::dvec2 truckMovementMouseVelocity() const;
|
||||
glm::dvec2 localRollMouseVelocity() const;
|
||||
glm::dvec2 globalRollMouseVelocity() const;
|
||||
|
||||
private:
|
||||
double _sensitivity;
|
||||
|
||||
MouseState _globalRotationMouseState;
|
||||
MouseState _localRotationMouseState;
|
||||
MouseState _truckMovementMouseState;
|
||||
MouseState _localRollMouseState;
|
||||
MouseState _globalRollMouseState;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___MOUSESTATE___H__
|
||||
@@ -22,14 +22,13 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
#define __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
#ifndef __OPENSPACE_CORE___NAVIGATIONHANDLER___H__
|
||||
#define __OPENSPACE_CORE___NAVIGATIONHANDLER___H__
|
||||
|
||||
#include <openspace/documentation/documentationgenerator.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/interaction/interactionmode.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/interaction/orbitalnavigator.h>
|
||||
#include <openspace/interaction/keyframenavigator.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
@@ -38,10 +37,6 @@
|
||||
|
||||
#include <ghoul/misc/boolean.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera;
|
||||
@@ -49,11 +44,10 @@ class SceneGraphNode;
|
||||
|
||||
namespace interaction {
|
||||
|
||||
class InteractionHandler : public properties::PropertyOwner, public DocumentationGenerator
|
||||
{
|
||||
class NavigationHandler : public properties::PropertyOwner {
|
||||
public:
|
||||
InteractionHandler();
|
||||
~InteractionHandler();
|
||||
NavigationHandler();
|
||||
~NavigationHandler();
|
||||
|
||||
void initialize();
|
||||
void deinitialize();
|
||||
@@ -63,39 +57,9 @@ public:
|
||||
void setCamera(Camera* camera);
|
||||
void resetCameraDirection();
|
||||
|
||||
// Interaction mode setters
|
||||
void setCameraStateFromDictionary(const ghoul::Dictionary& cameraDict);
|
||||
InteractionMode* interactionMode();
|
||||
void setCameraStateFromDictionary(const ghoul::Dictionary& cameraDict);
|
||||
|
||||
void goToChunk(int x, int y, int level);
|
||||
void goToGeo(double latitude, double longitude);
|
||||
|
||||
void resetKeyBindings();
|
||||
|
||||
void addKeyframe(double timestamp, KeyframeInteractionMode::CameraPose pose);
|
||||
void removeKeyframesAfter(double timestamp);
|
||||
void clearKeyframes();
|
||||
size_t nKeyframes() const;
|
||||
const std::vector<datamessagestructures::CameraKeyframe>& keyframes() const;
|
||||
|
||||
void bindKeyLocal(
|
||||
Key key,
|
||||
KeyModifier modifier,
|
||||
std::string luaCommand,
|
||||
std::string documentation = ""
|
||||
);
|
||||
void bindKey(
|
||||
Key key,
|
||||
KeyModifier modifier,
|
||||
std::string luaCommand,
|
||||
std::string documentation = ""
|
||||
);
|
||||
void lockControls();
|
||||
void unlockControls();
|
||||
|
||||
//void update(double deltaTime);
|
||||
void updateCamera(double deltaTime);
|
||||
void updateInputStates(double timeSinceLastUpdate);
|
||||
|
||||
// Accessors
|
||||
ghoul::Dictionary getCameraStateDictionary();
|
||||
@@ -104,15 +68,8 @@ public:
|
||||
glm::quat focusNodeToCameraRotation() const;
|
||||
Camera* camera() const;
|
||||
const InputState& inputState() const;
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to affect the
|
||||
* interaction. The functions contained are
|
||||
* - openspace::luascriptfunctions::setOrigin
|
||||
* \return The Lua library that contains all Lua functions available to affect the
|
||||
* interaction
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
const OrbitalNavigator& orbitalNavigator() const;
|
||||
KeyframeNavigator& keyframeNavigator() const;
|
||||
|
||||
// Callback functions
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
@@ -123,47 +80,26 @@ public:
|
||||
void saveCameraStateToFile(const std::string& filepath);
|
||||
void restoreCameraStateFromFile(const std::string& filepath);
|
||||
|
||||
/**
|
||||
* \return The Lua library that contains all Lua functions available to affect the
|
||||
* interaction
|
||||
*/
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
private:
|
||||
using Synchronized = ghoul::Boolean;
|
||||
|
||||
struct KeyInformation {
|
||||
std::string command;
|
||||
Synchronized synchronization;
|
||||
std::string documentation;
|
||||
};
|
||||
|
||||
std::string generateJson() const override;
|
||||
|
||||
void setInteractionMode(InteractionMode* interactionMode);
|
||||
|
||||
bool _cameraUpdatedFromScript = false;
|
||||
|
||||
std::multimap<KeyWithModifier, KeyInformation> _keyLua;
|
||||
|
||||
std::unique_ptr<InputState> _inputState;
|
||||
Camera* _camera;
|
||||
|
||||
InteractionMode* _currentInteractionMode;
|
||||
|
||||
std::shared_ptr<OrbitalInteractionMode::MouseStates> _mouseStates;
|
||||
|
||||
std::unique_ptr<OrbitalInteractionMode> _orbitalInteractionMode;
|
||||
std::unique_ptr<GlobeBrowsingInteractionMode> _globeBrowsingInteractionMode;
|
||||
std::unique_ptr<KeyframeInteractionMode> _keyframeInteractionMode;
|
||||
std::unique_ptr<OrbitalNavigator> _orbitalNavigator;
|
||||
std::unique_ptr<KeyframeNavigator> _keyframeNavigator;
|
||||
|
||||
// Properties
|
||||
properties::StringProperty _origin;
|
||||
properties::OptionProperty _interactionModeOption;
|
||||
|
||||
properties::BoolProperty _rotationalFriction;
|
||||
properties::BoolProperty _horizontalFriction;
|
||||
properties::BoolProperty _verticalFriction;
|
||||
|
||||
properties::FloatProperty _sensitivity;
|
||||
properties::FloatProperty _rapidness;
|
||||
properties::BoolProperty _useKeyFrameInteraction;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
#endif // __OPENSPACE_CORE___NAVIGATIONHANDLER___H__
|
||||
197
include/openspace/interaction/orbitalnavigator.h
Normal file
197
include/openspace/interaction/orbitalnavigator.h
Normal file
@@ -0,0 +1,197 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* 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___ORBITALNAVIGATOR___H__
|
||||
#define __OPENSPACE_CORE___ORBITALNAVIGATOR___H__
|
||||
|
||||
#include <openspace/interaction/delayedvariable.h>
|
||||
#include <openspace/interaction/inputstate.h>
|
||||
#include <openspace/interaction/interpolator.h>
|
||||
#include <openspace/interaction/mousestate.h>
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraphNode;
|
||||
class Camera;
|
||||
class SurfacePositionHandle;
|
||||
|
||||
namespace interaction {
|
||||
|
||||
class OrbitalNavigator : public properties::PropertyOwner {
|
||||
public:
|
||||
OrbitalNavigator();
|
||||
~OrbitalNavigator();
|
||||
|
||||
void updateMouseStatesFromInput(const InputState& inputState, double deltaTime);
|
||||
void updateCameraStateFromMouseStates(Camera& camera, double deltaTime);
|
||||
void setFocusNode(SceneGraphNode* focusNode);
|
||||
void startInterpolateCameraDirection(const Camera& camera);
|
||||
|
||||
bool followingNodeRotation() const;
|
||||
SceneGraphNode* focusNode() const;
|
||||
|
||||
private:
|
||||
struct CameraRotationDecomposition {
|
||||
glm::dquat localRotation;
|
||||
glm::dquat globalRotation;
|
||||
};
|
||||
|
||||
// Properties
|
||||
properties::BoolProperty _rotationalFriction;
|
||||
properties::BoolProperty _horizontalFriction;
|
||||
properties::BoolProperty _verticalFriction;
|
||||
properties::FloatProperty _followFocusNodeRotationDistance;
|
||||
properties::FloatProperty _minimumAllowedDistance;
|
||||
properties::FloatProperty _sensitivity;
|
||||
properties::FloatProperty _motionLag;
|
||||
|
||||
MouseStates _mouseStates;
|
||||
|
||||
SceneGraphNode* _focusNode = nullptr;
|
||||
glm::dvec3 _previousFocusNodePosition;
|
||||
glm::dquat _previousFocusNodeRotation;
|
||||
|
||||
Interpolator<double> _rotateToFocusNodeInterpolator;
|
||||
Interpolator<double> _followRotationInterpolator;
|
||||
|
||||
/**
|
||||
* Decomposes the cameras rotation in to a global and a local rotation defined by
|
||||
* CameraRotationDecomposition. The global rotation defines the rotation so that the
|
||||
* camera points towards the focus node in the direction opposite to the direction
|
||||
* out from the surface of the object. The local rotation defines the differential
|
||||
* from the global to the current total rotation so that
|
||||
* <code>cameraRotation = globalRotation * localRotation</code>.
|
||||
*/
|
||||
CameraRotationDecomposition decomposeCameraRotation(
|
||||
const glm::dvec3& cameraPosition,
|
||||
const glm::dquat& cameraRotation,
|
||||
const glm::dvec3& cameraLookUp,
|
||||
const glm::dvec3& cameraViewDirection);
|
||||
|
||||
/*
|
||||
* Perform a camera roll on the local camera rotation
|
||||
* \returns a local camera rotation modified with a roll.
|
||||
*/
|
||||
glm::dquat roll(double deltaTime, const glm::dquat& localCameraRotation) const;
|
||||
|
||||
/**
|
||||
* Performs rotation around the cameras x and y axes.
|
||||
* \returns a local camera rotation modified with two degrees of freedom.
|
||||
*/
|
||||
glm::dquat rotateLocally(double deltaTime,
|
||||
const glm::dquat& localCameraRotation) const;
|
||||
|
||||
/**
|
||||
* Interpolates the local rotation towards a 0 rotation.
|
||||
* \returns a modified local rotation interpolated towards 0.
|
||||
*/
|
||||
glm::dquat interpolateLocalRotation(double deltaTime,
|
||||
const glm::dquat& localCameraRotation);
|
||||
|
||||
/**
|
||||
* Translates the horizontal direction. If far from the focus object, this will
|
||||
* result in an orbital rotation around the object. This function does not affect the
|
||||
* rotation but only the position.
|
||||
* \returns a position vector adjusted in the horizontal direction.
|
||||
*/
|
||||
glm::dvec3 translateHorizontally(double deltaTime, const glm::dvec3& cameraPosition,
|
||||
const glm::dvec3& objectPosition,
|
||||
const glm::dquat& focusNodeRotationDiff,
|
||||
const glm::dquat& globalCameraRotation,
|
||||
const SurfacePositionHandle& positionHandle) const;
|
||||
|
||||
/*
|
||||
* Adds rotation to the camera position so that it follows the rotation of the focus
|
||||
* node defined by the differential focusNodeRotationDiff.
|
||||
* \returns a position updated with the rotation defined by focusNodeRotationDiff
|
||||
*/
|
||||
glm::dvec3 followFocusNodeRotation(const glm::dvec3& cameraPosition,
|
||||
const glm::dvec3& objectPosition,
|
||||
const glm::dquat& focusNodeRotationDiff) const;
|
||||
|
||||
/**
|
||||
* Updates the global rotation so that it points towards the focus node.
|
||||
* \returns a global rotation quaternion defining a rotation towards the focus node.
|
||||
*/
|
||||
glm::dquat rotateGlobally(const glm::dquat& globalCameraRotation,
|
||||
const glm::dvec3& objectPosition,
|
||||
const glm::dquat& focusNodeRotationDiff,
|
||||
const glm::dvec3& cameraPosition,
|
||||
const SurfacePositionHandle& positionHandle) const;
|
||||
|
||||
/**
|
||||
* Translates the camera position towards or away from the focus node.
|
||||
* \returns a position vector adjusted in the vertical direction.
|
||||
*/
|
||||
glm::dvec3 translateVertically(double deltaTime, const glm::dvec3& cameraPosition,
|
||||
const glm::dvec3& objectPosition,
|
||||
const SurfacePositionHandle& positionHandle) const;
|
||||
|
||||
/**
|
||||
* Rotates the camera around the out vector of the surface.
|
||||
* \returns a quaternion adjusted to rotate around the out vector of the surface.
|
||||
*/
|
||||
glm::dquat rotateHorizontally(double deltaTime,
|
||||
const glm::dquat& globalCameraRotation,
|
||||
const glm::dvec3& cameraPosition,
|
||||
const SurfacePositionHandle& positionHandle) const;
|
||||
|
||||
/**
|
||||
* Push the camera out to the surface of the object.
|
||||
* \returns a position vector adjusted to be at least minHeightAboveGround meters
|
||||
* above the actual surface of the object
|
||||
*/
|
||||
glm::dvec3 pushToSurface(double minHeightAboveGround,
|
||||
const glm::dvec3& cameraPosition,
|
||||
const glm::dvec3& objectPosition,
|
||||
const SurfacePositionHandle& positionHandle) const;
|
||||
|
||||
/**
|
||||
* Interpolates between rotationDiff and a 0 rotation.
|
||||
*/
|
||||
glm::dquat interpolateRotationDifferential(
|
||||
double deltaTime, double interpolationTime,
|
||||
const glm::dquat& rotationDiff,
|
||||
const glm::dvec3& objectPosition,
|
||||
const glm::dvec3& cameraPosition,
|
||||
const SurfacePositionHandle& positionHandle);
|
||||
|
||||
/**
|
||||
* Calculates a SurfacePositionHandle given a camera position in world space.
|
||||
*/
|
||||
SurfacePositionHandle calculateSurfacePositionHandle(
|
||||
const glm::dvec3 cameraPositionWorldSpace);
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___ORBITALNAVIGATOR___H__
|
||||
@@ -42,6 +42,7 @@ namespace openspace {
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
struct RendererTasks;
|
||||
struct SurfacePositionHandle;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
@@ -78,6 +79,8 @@ public:
|
||||
virtual void render(const RenderData& data);
|
||||
virtual void render(const RenderData& data, RendererTasks& rendererTask);
|
||||
virtual void update(const UpdateData& data);
|
||||
virtual SurfacePositionHandle calculateSurfacePositionHandle(
|
||||
const glm::dvec3& targetModelSpace);
|
||||
|
||||
RenderBin renderBin() const;
|
||||
void setRenderBin(RenderBin bin);
|
||||
|
||||
@@ -48,6 +48,7 @@ class Translation;
|
||||
class Scale;
|
||||
class Scene;
|
||||
struct UpdateData;
|
||||
struct SurfacePositionHandle;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
@@ -91,6 +92,8 @@ public:
|
||||
void removeDependency(SceneGraphNode& dependency, UpdateScene updateScene = UpdateScene::Yes);
|
||||
void clearDependencies(UpdateScene updateScene = UpdateScene::Yes);
|
||||
void setDependencies(const std::vector<SceneGraphNode*>& dependencies, UpdateScene updateScene = UpdateScene::Yes);
|
||||
SurfacePositionHandle calculateSurfacePositionHandle(
|
||||
const glm::dvec3& targetModelSpace);
|
||||
|
||||
const std::vector<SceneGraphNode*>& dependencies() const;
|
||||
const std::vector<SceneGraphNode*>& dependentNodes() const;
|
||||
|
||||
@@ -75,6 +75,21 @@ struct RaycastData {
|
||||
std::string namespaceName;
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines the position of an object relative to a surface. The surface is defined as
|
||||
* a reference surface together with a height offset from that reference surface.
|
||||
*/
|
||||
struct SurfacePositionHandle {
|
||||
/// Vector from the center of the object to the reference surface of the object
|
||||
glm::dvec3 centerToReferenceSurface;
|
||||
/// Direction out from the reference. Can conincide with the surface normal but does
|
||||
/// not have to.
|
||||
glm::dvec3 referenceSurfaceOutDirection;
|
||||
/// Height from the reference surface out to the actual surface in the direction of
|
||||
/// the surface normal. Can be positive or negative.
|
||||
double heightToSurface;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___UPDATESTRUCTURES___H__
|
||||
|
||||
Reference in New Issue
Block a user