Add new 'motion_offset' parameter to motion elements

This commit is contained in:
Simon Detheridge 2015-07-06 15:05:43 +01:00
parent efb39f8160
commit 3fa59be990
5 changed files with 22 additions and 5 deletions

View File

@ -1293,7 +1293,7 @@ public:
point.m_Z -= m_CamZPos;
}
#define APP_FMP(x) x += param.second * Interpolater<T>::MotionFuncs(motion.m_MotionFunc, motion.m_MotionFreq * blend)
#define APP_FMP(x) x += param.second * Interpolater<T>::MotionFuncs(motion.m_MotionFunc, motion.m_MotionFreq * (blend + motion.m_MotionOffset))
/// <summary>
/// Update ember parameters based on stored motion elements
/// </summary>

View File

@ -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 << "<flame_motion motion_frequency=\"" << motion.m_MotionFreq << "\" ";
if (motion.m_MotionOffset > 0)
os << "motion_offset=\"" << motion.m_MotionOffset << "\" ";
os << "motion_func=";
switch(motion.m_MotionFunc)
{

View File

@ -20,6 +20,7 @@ public:
{
m_MotionFreq = 0;
m_MotionFunc = MOTION_SIN;
m_MotionOffset = 0;
}
FlameMotion(const FlameMotion<T> &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<pair<eFlameMotionParam, T>> m_MotionParams;

View File

@ -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<T>::MotionFuncs(func, freq * blend); \
x += currentMot.x * Interpolater<T>::MotionFuncs(func, freq * (blend + offset)); \
} while (0)
/// <summary>
@ -733,6 +736,7 @@ public:
Xform<T>& 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<T>* newVar = motVar->Copy();
newVar->m_Weight = motVar->m_Weight * Interpolater<T>::MotionFuncs(func, freq * blend);
newVar->m_Weight = motVar->m_Weight * Interpolater<T>::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<T>::MotionFuncs(func, freq * blend);
var->m_Weight += motVar->m_Weight * Interpolater<T>::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<T>::MotionFuncs(func, freq * blend);
*(params[k].Param()) += motParams[k].ParamVal() * Interpolater<T>::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<Xform<T>*>(this)->AllVarsFunc([&] (vector<Variation<T>*>& variations, bool& keepGoing)
{
@ -1233,6 +1238,7 @@ public:
T m_Wind[2];
eMotion m_MotionFunc;
T m_MotionFreq;
T m_MotionOffset;
vector<Xform<T>> m_Motion;
string m_Name;

View File

@ -1015,6 +1015,7 @@ private:
attStr = reinterpret_cast<char*>(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"))