From 3fa59be990bff27ea6e2d6d0b14eda99da6c04ca Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Mon, 6 Jul 2015 15:05:43 +0100 Subject: [PATCH] Add new 'motion_offset' parameter to motion elements --- Source/Ember/Ember.h | 2 +- Source/Ember/EmberToXml.h | 6 ++++++ Source/Ember/FlameMotion.h | 3 +++ Source/Ember/Xform.h | 14 ++++++++++---- Source/Ember/XmlToEmber.h | 2 ++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Source/Ember/Ember.h b/Source/Ember/Ember.h index de18c0f..b02cd76 100644 --- a/Source/Ember/Ember.h +++ b/Source/Ember/Ember.h @@ -1293,7 +1293,7 @@ public: point.m_Z -= m_CamZPos; } -#define APP_FMP(x) x += param.second * Interpolater::MotionFuncs(motion.m_MotionFunc, motion.m_MotionFreq * blend) +#define APP_FMP(x) x += param.second * Interpolater::MotionFuncs(motion.m_MotionFunc, motion.m_MotionFreq * (blend + motion.m_MotionOffset)) /// /// Update ember parameters based on stored motion elements /// diff --git a/Source/Ember/EmberToXml.h b/Source/Ember/EmberToXml.h index 45a2810..f79ba8a 100644 --- a/Source/Ember/EmberToXml.h +++ b/Source/Ember/EmberToXml.h @@ -493,6 +493,9 @@ private: os << "motion_function=\"hill\" "; else if (xform.m_MotionFunc== MOTION_SAW) os << "motion_function=\"saw\" "; + + if (xform.m_MotionOffset != 0) + os << "motion_offset=\"" << xform.m_MotionOffset << "\" "; } else { @@ -731,6 +734,9 @@ private: ostringstream os; os << " 0) + os << "motion_offset=\"" << motion.m_MotionOffset << "\" "; + os << "motion_func="; switch(motion.m_MotionFunc) { diff --git a/Source/Ember/FlameMotion.h b/Source/Ember/FlameMotion.h index 6700f42..7f47d90 100644 --- a/Source/Ember/FlameMotion.h +++ b/Source/Ember/FlameMotion.h @@ -20,6 +20,7 @@ public: { m_MotionFreq = 0; m_MotionFunc = MOTION_SIN; + m_MotionOffset = 0; } FlameMotion(const FlameMotion &other) @@ -51,10 +52,12 @@ public: m_MotionFunc = other.m_MotionFunc; m_MotionFreq = T(other.m_MotionFreq); + m_MotionOffset = T(other.m_MotionOffset); return *this; } T m_MotionFreq; + T m_MotionOffset; eMotion m_MotionFunc; vector> m_MotionParams; diff --git a/Source/Ember/Xform.h b/Source/Ember/Xform.h index cffc862..f36edec 100644 --- a/Source/Ember/Xform.h +++ b/Source/Ember/Xform.h @@ -165,6 +165,7 @@ public: m_Wind[1] = T(xform.m_Wind[1]); m_MotionFreq = xform.m_MotionFreq; m_MotionFunc = xform.m_MotionFunc; + m_MotionOffset = xform.m_MotionOffset; ClearAndDeleteVariations(); @@ -234,6 +235,7 @@ public: m_Wind[0] = 0; m_Wind[1] = 0; m_MotionFreq = 0; + m_MotionOffset = 0; } else { @@ -262,6 +264,7 @@ public: m_Wind[0] = EMPTYFIELD; m_Wind[1] = EMPTYFIELD; m_MotionFreq = EMPTYFIELD; + m_MotionOffset = EMPTYFIELD; } m_MotionFunc = MOTION_SIN; @@ -716,7 +719,7 @@ public: do \ { \ if (currentMot.x != EMPTYFIELD) \ - x += currentMot.x * Interpolater::MotionFuncs(func, freq * blend); \ + x += currentMot.x * Interpolater::MotionFuncs(func, freq * (blend + offset)); \ } while (0) /// @@ -733,6 +736,7 @@ public: Xform& currentMot = xform.m_Motion[i]; T freq = currentMot.m_MotionFreq; eMotion func = currentMot.m_MotionFunc; + T offset = currentMot.m_MotionOffset; //Clamp these to the appropriate range after all are applied. APPMOT(m_Weight); @@ -753,13 +757,13 @@ public: if (!var)//It wasn't present, so add it and set the weight. { Variation* newVar = motVar->Copy(); - newVar->m_Weight = motVar->m_Weight * Interpolater::MotionFuncs(func, freq * blend); + newVar->m_Weight = motVar->m_Weight * Interpolater::MotionFuncs(func, freq * (blend + offset)); AddVariation(newVar); var = newVar;//Use this below for params. } else//It was present, so apply the motion func to the weight. { - var->m_Weight += motVar->m_Weight * Interpolater::MotionFuncs(func, freq * blend); + var->m_Weight += motVar->m_Weight * Interpolater::MotionFuncs(func, freq * (blend + offset)); } //At this point, we've added if needed, or just applied the motion func to the weight. @@ -773,7 +777,7 @@ public: for (size_t k = 0; k < motParVar->ParamCount(); k++) { if (!motParams[k].IsPrecalc()) - *(params[k].Param()) += motParams[k].ParamVal() * Interpolater::MotionFuncs(func, freq * blend); + *(params[k].Param()) += motParams[k].ParamVal() * Interpolater::MotionFuncs(func, freq * (blend + offset)); } } } @@ -1157,6 +1161,7 @@ public: ss << "Wind: " << m_Wind[0] << ", " << m_Wind[1] << endl; ss << "Motion Frequency: " << m_MotionFreq << endl; ss << "Motion Func: " << m_MotionFunc << endl; + ss << "Motion Offset: " << m_MotionOffset << endl; const_cast*>(this)->AllVarsFunc([&] (vector*>& variations, bool& keepGoing) { @@ -1233,6 +1238,7 @@ public: T m_Wind[2]; eMotion m_MotionFunc; T m_MotionFreq; + T m_MotionOffset; vector> m_Motion; string m_Name; diff --git a/Source/Ember/XmlToEmber.h b/Source/Ember/XmlToEmber.h index 290b43e..b823ed0 100644 --- a/Source/Ember/XmlToEmber.h +++ b/Source/Ember/XmlToEmber.h @@ -1015,6 +1015,7 @@ private: attStr = reinterpret_cast(xmlGetProp(childNode, curAtt->name)); if (ParseAndAssignFloat(curAtt->name, attStr, "motion_frequency", motion.m_MotionFreq, ret)) { } + else if (ParseAndAssignFloat(curAtt->name, attStr, "motion_offset", motion.m_MotionOffset, ret)) { } else if (!Compare(curAtt->name, "motion_function")) { string func(attStr); @@ -1180,6 +1181,7 @@ private: else if (ParseAndAssignFloat(curAtt->name, attStr, "opacity", xform.m_Opacity, success)) { } else if (ParseAndAssignFloat(curAtt->name, attStr, "var_color", xform.m_DirectColor, success)) { } else if (ParseAndAssignFloat(curAtt->name, attStr, "motion_frequency", xform.m_MotionFreq, success)) { } + else if (ParseAndAssignFloat(curAtt->name, attStr, "motion_offset", xform.m_MotionOffset, success)) { } //Parse more complicated reads that have multiple possible values. else if (!Compare(curAtt->name, "name"))