summaryrefslogtreecommitdiffstats
path: root/src/uipparser
diff options
context:
space:
mode:
authorMahmoud Badri <mahmoud.badri@qt.io>2019-08-16 16:09:32 +0300
committerMahmoud Badri <mahmoud.badri@qt.io>2019-08-19 10:43:27 +0300
commit7c6278ae87100f1a9ef283a2d91ee4130eba085c (patch)
tree7ecc6995550faa1a2e87023fa169dc8b495e47e4 /src/uipparser
parent8efc601abad8425b2b720f7378347c05ff07d074 (diff)
Fix Easing animation
Changed the logic for easing animation evaluation. Also some cleanups in Qt3DSDMAnimation.h and removing some useless code. Task-number: QT3DS-3874 Change-Id: Ieaa68ec9027ce9f5ad13eba6d49f73c14d1a4a8c Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/uipparser')
-rw-r--r--src/uipparser/Qt3DSUIPParserImpl.cpp103
-rw-r--r--src/uipparser/Qt3DSUIPParserImpl.h14
2 files changed, 51 insertions, 66 deletions
diff --git a/src/uipparser/Qt3DSUIPParserImpl.cpp b/src/uipparser/Qt3DSUIPParserImpl.cpp
index 380a43c..5ac61bc 100644
--- a/src/uipparser/Qt3DSUIPParserImpl.cpp
+++ b/src/uipparser/Qt3DSUIPParserImpl.cpp
@@ -2412,43 +2412,36 @@ BOOL CUIPParserImpl::LoadEaseInOutKeys(IPresentation &inPresentation,
float *theBezierValues = new float[theNumKeys * 6];
float *theBezierPtr = theBezierValues;
- SEaseInEaseOutKeyframe thePreviousKeyframe;
- thePreviousKeyframe.m_Value = 0.0f;
- SEaseInEaseOutKeyframe theCurrentKeyframe;
- theCurrentKeyframe.m_Value = 0.0f;
- SEaseInEaseOutKeyframe theNextKeyframe;
- theNextKeyframe.m_Value = 0.0f;
+ SEaseInEaseOutKeyframe prevKeyframe;
+ SEaseInEaseOutKeyframe currKeyframe;
+ SEaseInEaseOutKeyframe nextKeyframe;
const float *theIter = inValues.begin();
if (theNumKeys > 0) {
- theCurrentKeyframe = ParseEaseInOutKey(theIter);
- float *theNextValuePtr = NULL;
- float theNextValue;
+ currKeyframe = ParseEaseInOutKey(theIter);
+ float nextKfTime = -1.f; // -1 = no value provided
if (theNumKeys > 1) {
- theNextKeyframe = ParseEaseInOutKey(theIter);
- theNextValue = theNextKeyframe.m_Value;
- theNextValuePtr = &theNextValue;
+ nextKeyframe = ParseEaseInOutKey(theIter);
+ nextKfTime = nextKeyframe.m_Time;
}
- CreateBezierKeyframeFromEaseInEaseOutKeyframe(NULL, theCurrentKeyframe, theNextValuePtr,
- theBezierPtr);
+ CreateBezierKeyframeFromEaseInEaseOutKeyframe(-1.f, currKeyframe, nextKfTime, theBezierPtr);
}
for (long theKeyIndex = 1; theKeyIndex < theNumKeys; ++theKeyIndex) {
- thePreviousKeyframe = theCurrentKeyframe;
- theCurrentKeyframe = theNextKeyframe;
+ prevKeyframe = currKeyframe;
+ currKeyframe = nextKeyframe;
+
+ float prevKfTime = prevKeyframe.m_Time;
+ float nextKfTime = -1.f; // -1 = no value provided
- float theLastValue = thePreviousKeyframe.m_Value;
- float *theNextValuePtr = NULL;
- float theNextValue;
if (theKeyIndex + 1 < theNumKeys) {
- theNextKeyframe = ParseEaseInOutKey(theIter);
- theNextValue = theNextKeyframe.m_Value;
- theNextValuePtr = &theNextValue;
+ nextKeyframe = ParseEaseInOutKey(theIter);
+ nextKfTime = nextKeyframe.m_Time;
}
- CreateBezierKeyframeFromEaseInEaseOutKeyframe(&theLastValue, theCurrentKeyframe,
- theNextValuePtr, theBezierPtr);
+ CreateBezierKeyframeFromEaseInEaseOutKeyframe(prevKfTime, currKeyframe, nextKfTime,
+ theBezierPtr);
}
NVConstDataRef<float> theFloatValues = NVConstDataRef<float>(theBezierValues, theNumKeys * 6);
@@ -2458,43 +2451,35 @@ BOOL CUIPParserImpl::LoadEaseInOutKeys(IPresentation &inPresentation,
return theStatus;
}
-inline float AnimationClamp(float inLowerBound, float inUpperBound, float inValue)
+void CUIPParserImpl::CreateBezierKeyframeFromEaseInEaseOutKeyframe(
+ float prevTime, SEaseInEaseOutKeyframe &keyframe, float nextTime, float *&outBezierValues)
{
- if (inValue < inLowerBound)
- return inLowerBound;
- if (inValue > inUpperBound)
- return inUpperBound;
- return inValue;
-}
+ float kfValue = keyframe.m_Value;
+ float kfTime = keyframe.m_Time; // seconds
+ float timeIn = kfTime;
+ float valueIn = kfValue;
+ float timeOut = kfTime;
+ float valueOut = kfValue;
-void CUIPParserImpl::CreateBezierKeyframeFromEaseInEaseOutKeyframe(
- float *inPreviousValue, SEaseInEaseOutKeyframe &inCurrent, float *inNextValue,
- float *&outBezierValues)
-{
- float theValue = inCurrent.m_Value;
- float theSeconds = inCurrent.m_Time;
- float inSeconds = 0.f;
- float inValue = 0.f;
- float outSeconds = 0.f;
- float outValue = 0.f;
- const double oneThird = 1.0 / 3.0;
- if (inPreviousValue) {
- float thePercent = 1.0f - AnimationClamp(0.0f, 1.0f, inCurrent.m_EaseIn / 100.f);
- double theAmount = 1.0f - thePercent * oneThird;
- inValue = *inPreviousValue + (float)(((inCurrent.m_Value - *inPreviousValue) * theAmount));
- }
- if (inNextValue) {
- float thePercent = 1.0f - AnimationClamp(0.0f, 1.0f, inCurrent.m_EaseOut / 100.f);
- double theAmount = thePercent * oneThird;
- outValue = (float)(inCurrent.m_Value + ((*inNextValue - inCurrent.m_Value) * theAmount));
- }
-
- *outBezierValues++ = theSeconds;
- *outBezierValues++ = theValue;
- *outBezierValues++ = inSeconds;
- *outBezierValues++ = inValue;
- *outBezierValues++ = outSeconds;
- *outBezierValues++ = outValue;
+ // at 100 ease, the control point will be midway between the 2 keyframes
+ float maxEasePerc = .5f;
+
+ if (prevTime != -1.f) {
+ float easeInPerc = qBound(0.f, keyframe.m_EaseIn / 100.f, 1.f) * maxEasePerc;
+ timeIn = prevTime + (kfTime - prevTime) * (1 - easeInPerc);
+ }
+
+ if (nextTime != -1.f) {
+ float easeOutPerc = qBound(0.f, keyframe.m_EaseOut / 100.f, 1.f) * maxEasePerc;
+ timeOut = kfTime + (nextTime - kfTime) * easeOutPerc;
+ }
+
+ *outBezierValues++ = kfTime;
+ *outBezierValues++ = kfValue;
+ *outBezierValues++ = timeIn;
+ *outBezierValues++ = valueIn;
+ *outBezierValues++ = timeOut;
+ *outBezierValues++ = valueOut;
}
BOOL CUIPParserImpl::ProcessSlideAnimAction(IPresentation &inPresentation, eastl::string &inSlideId,
diff --git a/src/uipparser/Qt3DSUIPParserImpl.h b/src/uipparser/Qt3DSUIPParserImpl.h
index 3c44e21..f89227b 100644
--- a/src/uipparser/Qt3DSUIPParserImpl.h
+++ b/src/uipparser/Qt3DSUIPParserImpl.h
@@ -442,10 +442,10 @@ protected:
struct SEaseInEaseOutKeyframe
{
- float m_Time;
- float m_Value;
- float m_EaseIn;
- float m_EaseOut;
+ float m_Time = 0.f;
+ float m_Value = 0.f;
+ float m_EaseIn = 100.f;
+ float m_EaseOut = 100.f;
};
struct SGraphSectionCount
@@ -611,9 +611,9 @@ protected: // Animation helper
bool inMaster, qt3dsdm::IDOMReader &inReader);
BOOL AddSlideAction(IPresentation &inPresentation, eastl::string &inSlideId, bool inActive,
qt3dsdm::IDOMReader &inReader);
- void CreateBezierKeyframeFromEaseInEaseOutKeyframe(float *inPreviousValue,
- SEaseInEaseOutKeyframe &inCurrent,
- float *inNextValue, float *&outBezierValues);
+ void CreateBezierKeyframeFromEaseInEaseOutKeyframe(float prevTime,
+ SEaseInEaseOutKeyframe &keyframe,
+ float nextTime, float *&outBezierValues);
protected: // Helper methods
bool IsStringType(ERuntimeDataModelDataType inDataType);