2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 04:27:42 +00:00

All animation nodes implemented

This commit is contained in:
Jack Andersen
2018-01-29 15:04:01 -10:00
parent bb10423267
commit 36f1473f3e
31 changed files with 809 additions and 179 deletions

View File

@@ -1,80 +1,107 @@
#include "CTimeScaleFunctions.hpp"
#include "CCharAnimTime.hpp"
#include "zeus/Math.hpp"
namespace urde
{
std::shared_ptr<IVaryingAnimationTimeScale> IVaryingAnimationTimeScale::Clone() const
std::unique_ptr<IVaryingAnimationTimeScale> IVaryingAnimationTimeScale::Clone() const
{
return VClone();
}
float CConstantAnimationTimeScale::VTimeScaleIntegral(const float& a, const float& b) const { return (b - a) * x4_; }
float CConstantAnimationTimeScale::VFindUpperLimit(const float& a, const float& b) const { return (b / x4_) + a; }
std::shared_ptr<IVaryingAnimationTimeScale> CConstantAnimationTimeScale::VClone() const
float CConstantAnimationTimeScale::VTimeScaleIntegral(float lowerLimit, float upperLimit) const
{
CConstantAnimationTimeScale* ret = new CConstantAnimationTimeScale(x4_);
return std::shared_ptr<IVaryingAnimationTimeScale>(ret);
return (upperLimit - lowerLimit) * x4_scale;
}
std::shared_ptr<IVaryingAnimationTimeScale> CConstantAnimationTimeScale::VGetFunctionMirrored(const float&) const
float CConstantAnimationTimeScale::VFindUpperLimit(float lowerLimit, float root) const
{
return (root / x4_scale) + lowerLimit;
}
std::unique_ptr<IVaryingAnimationTimeScale> CConstantAnimationTimeScale::VClone() const
{
return std::make_unique<CConstantAnimationTimeScale>(x4_scale);
}
std::unique_ptr<IVaryingAnimationTimeScale> CConstantAnimationTimeScale::VGetFunctionMirrored(float) const
{
return Clone();
}
float CLinearAnimationTimeScale::VTimeScaleIntegral(const float&, const float&) const
CLinearAnimationTimeScale::CLinearAnimationTimeScale(const CCharAnimTime& t1, float y1,
const CCharAnimTime& t2, float y2)
{
return 0.f;
float y2my1 = y2 - y1;
float t2mt1 = (t2 - t1).GetSeconds();
x4_desc.x4_slope = y2my1 / t2mt1;
x4_desc.x8_yIntercept = y1 - y2my1 / t2mt1 * t1.GetSeconds();
x4_desc.xc_t1 = t1.GetSeconds();
x4_desc.x10_t2 = t2.GetSeconds();
}
std::unique_ptr<IVaryingAnimationTimeScale>
CLinearAnimationTimeScale::CFunctionDescription::FunctionMirroredAround(float value) const
{
float slope = -x4_slope;
float t1 = 2.f * value - x10_t2;
float t2 = 2.f * value - xc_t1;
float newYInt = x8_yIntercept - x4_slope * 2.f * value;
float y1 = slope * t1 + newYInt;
float y2 = slope * t2 + newYInt;
return std::make_unique<CLinearAnimationTimeScale>(t1, y1, t2, y2);
}
float CLinearAnimationTimeScale::VTimeScaleIntegral(float lowerLimit, float upperLimit) const
{
if (lowerLimit <= upperLimit)
return TimeScaleIntegralWithSortedLimits(x4_desc, lowerLimit, upperLimit);
else
return -TimeScaleIntegralWithSortedLimits(x4_desc, upperLimit, lowerLimit);
}
float CLinearAnimationTimeScale::TimeScaleIntegralWithSortedLimits(const CFunctionDescription& desc,
const float&, const float&)
float lowerLimit, float upperLimit)
{
return 0.f;
float lowerEval = desc.x4_slope * lowerLimit + desc.x8_yIntercept;
float upperEval = desc.x4_slope * upperLimit + desc.x8_yIntercept;
return (upperLimit - lowerLimit) * 0.5f * (lowerEval + upperEval);
}
float CLinearAnimationTimeScale::VFindUpperLimit(const float&, const float&) const
float CLinearAnimationTimeScale::VFindUpperLimit(float lowerLimit, float root) const
{
return 0.f;
return FindUpperLimitFromRoot(x4_desc, lowerLimit, root);
}
float CLinearAnimationTimeScale::FindUpperLimitFromRoot(const CFunctionDescription& desc,
const float&, const float&)
float lowerLimit, float root)
{
return 0.f;
float M = 0.5f * desc.x4_slope;
float upperLimit = lowerLimit;
float m = 2.f * M;
float lowerIntegration = M * lowerLimit * lowerLimit + desc.x8_yIntercept * lowerLimit;
for (int i=0 ; i<16 ; ++i)
{
float factor = (M * upperLimit * upperLimit + desc.x8_yIntercept * upperLimit - lowerIntegration - root) /
(m * upperLimit + desc.x8_yIntercept);
upperLimit -= factor;
if (zeus::close_enough(factor, 0.f))
return upperLimit;
}
return -1.f;
}
std::shared_ptr<IVaryingAnimationTimeScale> CLinearAnimationTimeScale::VClone() const
std::unique_ptr<IVaryingAnimationTimeScale> CLinearAnimationTimeScale::VClone() const
{
CCharAnimTime timeA(x10_);
CCharAnimTime timeB(xc_);
CLinearAnimationTimeScale* ret = new CLinearAnimationTimeScale();
float f30 = x4_ * xc_ + x8_;
ret->x4_ = (x4_ * x10_ + x8_ - f30) / timeB.GetSeconds();
ret->x8_ = -((x4_ * x10_ + x8_ - f30) / (timeA - timeB).GetSeconds() * timeB.GetSeconds() - f30);
ret->xc_ = timeB.GetSeconds();
ret->x10_ = timeA.GetSeconds();
return std::shared_ptr<IVaryingAnimationTimeScale>(ret);
float y1 = x4_desc.x4_slope * x4_desc.xc_t1 + x4_desc.x8_yIntercept;
float y2 = x4_desc.x4_slope * x4_desc.x10_t2 + x4_desc.x8_yIntercept;
return std::make_unique<CLinearAnimationTimeScale>(x4_desc.xc_t1, y1, x4_desc.x10_t2, y2);
}
std::shared_ptr<IVaryingAnimationTimeScale>
CLinearAnimationTimeScale::VGetFunctionMirrored(const float& parm) const
std::unique_ptr<IVaryingAnimationTimeScale>
CLinearAnimationTimeScale::VGetFunctionMirrored(float value) const
{
float f27 = -(x4_ * parm * 2.f - x8_);
float f31 = -x4_ * parm * 2.f - x10_ + f27;
CCharAnimTime timeA(2.f * parm - xc_);
CCharAnimTime timeB(2.f * parm - x10_);
CLinearAnimationTimeScale* ret = new CLinearAnimationTimeScale();
ret->x4_ = (-x4_ * 2.f * parm - xc_ + f27 - f31) / (timeA - timeB).GetSeconds();
ret->x8_ = -(((-x4_ * 2.f * parm - xc_ + f27 - f31) /
(timeA - timeB).GetSeconds()) * timeB.GetSeconds() - f31);
ret->xc_ = timeB.GetSeconds();
ret->x10_ = timeA.GetSeconds();
return std::shared_ptr<IVaryingAnimationTimeScale>(ret);
return x4_desc.FunctionMirroredAround(value);
}
}