mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 07:22:43 +02:00
clamp frame index between 0 and 100,000
This commit is contained in:
parent
49e350fab2
commit
a0ec2ddfe9
3 changed files with 25 additions and 7 deletions
|
@ -12,16 +12,18 @@
|
|||
#include "AnimationCache.h"
|
||||
#include "AnimationLoop.h"
|
||||
|
||||
const float AnimationLoop::MAXIMUM_POSSIBLE_FRAME = 100000.0f;
|
||||
|
||||
AnimationLoop::AnimationLoop() :
|
||||
_fps(30.0f),
|
||||
_loop(false),
|
||||
_hold(false),
|
||||
_startAutomatically(false),
|
||||
_firstFrame(0.0f),
|
||||
_lastFrame(FLT_MAX),
|
||||
_lastFrame(MAXIMUM_POSSIBLE_FRAME),
|
||||
_running(false),
|
||||
_frameIndex(0.0f),
|
||||
_maxFrameIndexHint(FLT_MAX)
|
||||
_maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -53,10 +55,9 @@ AnimationLoop::AnimationLoop(float fps, bool loop, bool hold, bool startAutomati
|
|||
void AnimationLoop::simulate(float deltaTime) {
|
||||
_frameIndex += deltaTime * _fps;
|
||||
|
||||
|
||||
// If we knew the number of frames from the animation, we'd consider using it here
|
||||
// animationGeometry.animationFrames.size()
|
||||
float maxFrame = _maxFrameIndexHint;
|
||||
float maxFrame = _maxFrameIndexHint;
|
||||
float endFrameIndex = qMin(_lastFrame, maxFrame - (_loop ? 0.0f : 1.0f));
|
||||
float startFrameIndex = qMin(_firstFrame, endFrameIndex);
|
||||
if ((!_loop && (_frameIndex < startFrameIndex || _frameIndex > endFrameIndex)) || startFrameIndex == endFrameIndex) {
|
||||
|
|
|
@ -16,6 +16,8 @@ class AnimationDetails;
|
|||
|
||||
class AnimationLoop {
|
||||
public:
|
||||
static const float MAXIMUM_POSSIBLE_FRAME;
|
||||
|
||||
AnimationLoop();
|
||||
AnimationLoop(const AnimationDetails& animationDetails);
|
||||
AnimationLoop(float fps, bool loop, bool hold, bool startAutomatically, float firstFrame,
|
||||
|
@ -33,10 +35,10 @@ public:
|
|||
void setStartAutomatically(bool startAutomatically);
|
||||
bool getStartAutomatically() const { return _startAutomatically; }
|
||||
|
||||
void setFirstFrame(float firstFrame) { _firstFrame = firstFrame; }
|
||||
void setFirstFrame(float firstFrame) { _firstFrame = glm::clamp(firstFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); }
|
||||
float getFirstFrame() const { return _firstFrame; }
|
||||
|
||||
void setLastFrame(float lastFrame) { _lastFrame = lastFrame; }
|
||||
void setLastFrame(float lastFrame) { _lastFrame = glm::clamp(lastFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); }
|
||||
float getLastFrame() const { return _lastFrame; }
|
||||
|
||||
void setRunning(bool running);
|
||||
|
@ -45,7 +47,7 @@ public:
|
|||
void setFrameIndex(float frameIndex) { _frameIndex = glm::clamp(frameIndex, _firstFrame, _lastFrame); }
|
||||
float getFrameIndex() const { return _frameIndex; }
|
||||
|
||||
void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = value; }
|
||||
void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = glm::clamp(value, 0.0f, MAXIMUM_POSSIBLE_FRAME); }
|
||||
float getMaxFrameIndexHint() const { return _maxFrameIndexHint; }
|
||||
|
||||
void start() { setRunning(true); }
|
||||
|
|
|
@ -402,11 +402,15 @@ void ModelEntityItem::setAnimationURL(const QString& url) {
|
|||
}
|
||||
|
||||
void ModelEntityItem::setAnimationFrameIndex(float value) {
|
||||
#ifdef WANT_DEBUG
|
||||
if (isAnimatingSomething()) {
|
||||
qDebug() << "ModelEntityItem::setAnimationFrameIndex()";
|
||||
qDebug() << " value:" << value;
|
||||
qDebug() << " was:" << _animationLoop.getFrameIndex();
|
||||
qDebug() << " model URL:" << getModelURL();
|
||||
qDebug() << " animation URL:" << getAnimationURL();
|
||||
}
|
||||
#endif
|
||||
_animationLoop.setFrameIndex(value);
|
||||
}
|
||||
|
||||
|
@ -425,6 +429,17 @@ void ModelEntityItem::setAnimationSettings(const QString& value) {
|
|||
|
||||
if (settingsMap.contains("frameIndex")) {
|
||||
float frameIndex = settingsMap["frameIndex"].toFloat();
|
||||
#ifdef WANT_DEBUG
|
||||
if (isAnimatingSomething()) {
|
||||
qDebug() << "ModelEntityItem::setAnimationSettings() calling setAnimationFrameIndex()...";
|
||||
qDebug() << " model URL:" << getModelURL();
|
||||
qDebug() << " animation URL:" << getAnimationURL();
|
||||
qDebug() << " settings:" << value;
|
||||
qDebug() << " settingsMap[frameIndex]:" << settingsMap["frameIndex"];
|
||||
qDebug(" frameIndex: %20.5f", frameIndex);
|
||||
}
|
||||
#endif
|
||||
|
||||
setAnimationFrameIndex(frameIndex);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue