metaforce/Runtime/Character/CAnimTreeTweenBase.cpp

84 lines
2.6 KiB
C++

#include "CAnimTreeTweenBase.hpp"
namespace urde
{
s32 CAnimTreeTweenBase::sAdvancementDepth = 0;
CAnimTreeTweenBase::CAnimTreeTweenBase(bool b1, const std::weak_ptr<CAnimTreeNode>& a,
const std::weak_ptr<CAnimTreeNode>& b, int flags, std::string_view name)
: CAnimTreeDoubleChild(a, b, name), x1c_flags(flags)
{
x20_24_b1 = b1;
x20_25_ = 0;
}
void CAnimTreeTweenBase::VGetWeightedReaders(
rstl::reserved_vector<std::pair<float, std::weak_ptr<IAnimReader>>, 16>& out, float w) const
{
float weight = GetBlendingWeight();
x14_a->VGetWeightedReaders(out, (1.f - weight) * w);
x18_b->VGetWeightedReaders(out, weight * w);
}
void CAnimTreeTweenBase::VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut) const {}
void CAnimTreeTweenBase::VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut,
const CCharAnimTime& time) const
{
}
bool CAnimTreeTweenBase::VHasOffset(const CSegId& seg) const
{
return (x14_a->VHasOffset(seg) || x18_b->VHasOffset(seg));
}
zeus::CVector3f CAnimTreeTweenBase::VGetOffset(const CSegId& seg) const
{
const float weight = GetBlendingWeight();
if (weight >= 1.0f)
return x18_b->VGetOffset(seg);
const zeus::CVector3f oA = x14_a->VGetOffset(seg);
const zeus::CVector3f oB = x18_b->VGetOffset(seg);
return zeus::CVector3f::lerp(oA, oB, weight);
}
zeus::CQuaternion CAnimTreeTweenBase::VGetRotation(const CSegId& seg) const
{
const float weight = GetBlendingWeight();
if (weight >= 1.0f)
return x18_b->VGetRotation(seg);
const zeus::CQuaternion qA = x14_a->VGetRotation(seg);
const zeus::CQuaternion qB = x18_b->VGetRotation(seg);
return zeus::CQuaternion::slerp(qA, qB, weight);
}
std::experimental::optional<std::unique_ptr<IAnimReader>> CAnimTreeTweenBase::VSimplified()
{
if (x20_25_ == 0)
{
auto simpA = x14_a->Simplified();
auto simpB = x18_b->Simplified();
if (!simpA && !simpB)
return {};
auto clone = Clone();
if (simpA)
static_cast<CAnimTreeTweenBase&>(*clone).x14_a = CAnimTreeNode::Cast(std::move(*simpA));
if (simpB)
static_cast<CAnimTreeTweenBase&>(*clone).x18_b = CAnimTreeNode::Cast(std::move(*simpB));
return {std::move(clone)};
}
else
{
auto tmp = (x20_25_ == 1) ? x18_b : x14_a;
auto tmpUnblended = tmp->GetBestUnblendedChild();
if (!tmpUnblended)
return {tmp->Clone()};
else
return {tmpUnblended->Clone()};
}
}
}