mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-02 16:59:37 -05:00
Make all animations depend on system time instead of fps. This will make the animations robust with low fps. Add easing functions.
This commit is contained in:
@@ -39,8 +39,6 @@ class ScreenSpaceSkyBrowser;
|
||||
|
||||
class RenderableSkyTarget : public RenderablePlane {
|
||||
public:
|
||||
constexpr static const float DeltaTimeThreshold = 0.03f;
|
||||
|
||||
explicit RenderableSkyTarget(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void initializeGL() override;
|
||||
|
||||
@@ -38,8 +38,6 @@ namespace openspace {
|
||||
class ScreenSpaceSkyBrowser : public ScreenSpaceRenderable, public WwtCommunicator
|
||||
{
|
||||
public:
|
||||
constexpr static const double FovThreshold = 0.001;
|
||||
|
||||
explicit ScreenSpaceSkyBrowser(const ghoul::Dictionary& dictionary);
|
||||
~ScreenSpaceSkyBrowser();
|
||||
|
||||
@@ -49,11 +47,6 @@ public:
|
||||
void render() override;
|
||||
void update() override;
|
||||
|
||||
// Animation
|
||||
bool isAnimated() const;
|
||||
void startFovAnimation(double fov);
|
||||
void incrementallyAnimateToFov(float deltaTime);
|
||||
|
||||
float opacity() const;
|
||||
glm::vec2 size() const;
|
||||
|
||||
@@ -72,7 +65,6 @@ public:
|
||||
void removeRenderCopy();
|
||||
|
||||
private:
|
||||
properties::DoubleProperty _animationSpeed;
|
||||
properties::FloatProperty _textureQuality;
|
||||
properties::BoolProperty _renderOnlyOnMaster;
|
||||
std::vector<std::unique_ptr<properties::Vec3Property>> _renderCopies;
|
||||
@@ -81,13 +73,10 @@ private:
|
||||
|
||||
// Flags
|
||||
bool _isSyncedWithWwt = false;
|
||||
bool _isFovAnimated = false;
|
||||
bool _textureDimensionsIsDirty = false;
|
||||
bool _sizeIsDirty = false;
|
||||
|
||||
glm::vec2 _size = glm::vec2(1.f, 0.8f);
|
||||
// Animation of fieldOfView
|
||||
double _endVfov = 0.0;
|
||||
};
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ class SceneGraphNode;
|
||||
|
||||
class TargetBrowserPair {
|
||||
public:
|
||||
constexpr static const float DeltaTimeThreshold = 0.03f;
|
||||
|
||||
TargetBrowserPair(SceneGraphNode* target, ScreenSpaceSkyBrowser* browser);
|
||||
TargetBrowserPair& operator=(TargetBrowserPair other);
|
||||
|
||||
@@ -51,10 +49,10 @@ public:
|
||||
void removeHighlight(const glm::ivec3& color);
|
||||
void highlight(const glm::ivec3& color);
|
||||
// Animation
|
||||
void startAnimation(glm::dvec3 coordsEnd, double fovEnd, bool shouldLockAfter = true);
|
||||
void incrementallyAnimateToCoordinate(double deltaTime);
|
||||
void startAnimation(glm::dvec3 coordsEnd, double fovEnd);
|
||||
void incrementallyAnimateToCoordinate();
|
||||
void startFading(float goal, float fadeTime);
|
||||
void incrementallyFade(float deltaTime);
|
||||
void incrementallyFade();
|
||||
// Mouse interaction
|
||||
bool checkMouseIntersection(const glm::vec2& mousePosition);
|
||||
glm::vec2 selectedScreenSpacePosition() const;
|
||||
@@ -69,7 +67,6 @@ public:
|
||||
|
||||
// Target
|
||||
void centerTargetOnScreen();
|
||||
void incrementallyAnimateTarget(float deltaTime);
|
||||
|
||||
bool hasFinishedFading() const;
|
||||
bool isFacingCamera() const;
|
||||
@@ -125,13 +122,12 @@ private:
|
||||
SceneGraphNode* _targetNode = nullptr;
|
||||
|
||||
// Animation
|
||||
glm::dvec3 _animationStart = glm::dvec3(0);
|
||||
glm::dvec3 _animationEnd = glm::dvec3(0);
|
||||
bool _shouldLockAfterAnimation = false;
|
||||
bool _targetIsAnimated = false;
|
||||
|
||||
skybrowser::Animation _fadeBrowser = skybrowser::Animation(0.f, 0.f, 0.0);
|
||||
skybrowser::Animation _fadeTarget = skybrowser::Animation(0.f, 0.f, 0.0);
|
||||
skybrowser::Animation<float> _fadeBrowser = skybrowser::Animation(0.f, 0.f, 0.0);
|
||||
skybrowser::Animation<float> _fadeTarget = skybrowser::Animation(0.f, 0.f, 0.0);
|
||||
skybrowser::Animation<double> _fovAnimation = skybrowser::Animation(0.0, 0.0, 0.0);
|
||||
skybrowser::Animation<glm::dvec3> _moveTarget =
|
||||
skybrowser::Animation(glm::dvec3(0.0), glm::dvec3(0.0), 0.0);
|
||||
bool _targetIsAnimating = false;
|
||||
|
||||
glm::dvec2 _equatorialAim = glm::dvec2(0.0);
|
||||
glm::ivec3 _borderColor = glm::ivec3(255);
|
||||
|
||||
@@ -171,12 +171,12 @@ double angleBetweenVectors(const glm::dvec3& start, const glm::dvec3& end);
|
||||
* multiple times in order to animate.
|
||||
* \param start Cartesian vector
|
||||
* \param end Cartesian vector
|
||||
* \param deltaTime The time between the current frame and the last
|
||||
* \param speedFactor Factor that determines how fast the animation will be
|
||||
* \param percentage Percentage of the angle between the vectors that the matrix should
|
||||
* rotate
|
||||
* \return 4x4 matrix for incremental rotation animation of a vector
|
||||
*/
|
||||
glm::dmat4 incrementalAnimationMatrix(const glm::dvec3& start, const glm::dvec3& end,
|
||||
double deltaTime, double speedFactor = 1.0);
|
||||
double percentage);
|
||||
/**
|
||||
* Returns the size in meters that for example a plane would need to have in order to
|
||||
* display a specified field of view.
|
||||
@@ -186,17 +186,53 @@ glm::dmat4 incrementalAnimationMatrix(const glm::dvec3& start, const glm::dvec3&
|
||||
*/
|
||||
double sizeFromFov(double fov, glm::dvec3 worldPosition);
|
||||
|
||||
template<typename T>
|
||||
class Animation {
|
||||
public:
|
||||
Animation(float start, float goal, double time);
|
||||
void start();
|
||||
bool isFinished() const;
|
||||
float getNewValue();
|
||||
Animation(T start, T goal, double time)
|
||||
: _start(start), _goal(goal)
|
||||
{
|
||||
_animationTime = std::chrono::milliseconds(static_cast<int>(time * 1000));
|
||||
}
|
||||
void start() {
|
||||
_isStarted = true;
|
||||
_startTime = std::chrono::system_clock::now();
|
||||
}
|
||||
void stop() {
|
||||
_isStarted = false;
|
||||
}
|
||||
bool isAnimating() const {
|
||||
bool timeLeft = timeSpent().count() < _animationTime.count() ? true : false;
|
||||
return timeLeft && _isStarted;
|
||||
}
|
||||
T getNewValue();
|
||||
glm::dmat4 getRotationMatrix();
|
||||
|
||||
private:
|
||||
std::chrono::duration<double, std::milli> timeSpent() const {
|
||||
using namespace std::chrono;
|
||||
system_clock::time_point now = system_clock::now();
|
||||
std::chrono::duration<double, std::milli> timeSpent = now - _startTime;
|
||||
return timeSpent;
|
||||
}
|
||||
double percentageSpent() const {
|
||||
return timeSpent().count() / _animationTime.count();
|
||||
}
|
||||
|
||||
double easeOutExpo(double x) {
|
||||
double epsilon = std::numeric_limits<double>::epsilon();
|
||||
return std::abs(x - 1.0) < epsilon ? 1.0 : 1.0 - pow(2.0, -10.0 * x);
|
||||
}
|
||||
|
||||
double easeInOutSine(double x) {
|
||||
return -(cos(glm::pi<double>() * x) - 1.0) / 2.0;
|
||||
}
|
||||
|
||||
// Animation
|
||||
bool _isAnimating = false;
|
||||
float _goal = 1.0f;
|
||||
float _start = 1.0f;
|
||||
bool _isStarted = false;
|
||||
double _lastPercentage = 0;
|
||||
T _goal;
|
||||
T _start;
|
||||
std::chrono::milliseconds _animationTime = std::chrono::milliseconds(2000);
|
||||
std::chrono::system_clock::time_point _startTime;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user