EHS/src/io/model/AnimBone.cpp
karutoh 405acb026f
All checks were successful
Build & Release / Linux-AMD64-Build (push) Successful in 1m21s
Build & Release / Windows-AMD64-Build (push) Successful in 1m48s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m20s
Fixed include errors.
2024-02-20 23:06:58 -08:00

91 lines
1.6 KiB
C++

#include "ehs/io/mdl/AnimBone.h"
#include <algorithm>
namespace ehs
{
AnimBone::AnimBone()
: boneId(0xFF)
{
}
AnimBone::AnimBone(const UInt_8 boneId)
: boneId(boneId)
{
}
AnimBone::AnimBone(const UInt_8 boneId, const UInt_64 size)
: boneId(boneId), keyFrames(size)
{
}
AnimBone::AnimBone(const UInt_8 boneId, Array<KeyFrame> keyFrames)
: boneId(boneId), keyFrames(std::move(keyFrames))
{
}
AnimBone::AnimBone(const AnimBone& anim)
: boneId(anim.boneId), keyFrames(anim.keyFrames)
{
}
AnimBone::AnimBone(AnimBone&& anim) noexcept
: boneId(anim.boneId), keyFrames(std::move(anim.keyFrames))
{
anim.boneId = 0xFF;
}
AnimBone& AnimBone::operator=(AnimBone&& anim) noexcept
{
if (this == &anim)
return *this;
boneId = anim.boneId;
keyFrames = std::move(anim.keyFrames);
anim.boneId = 0xFF;
return *this;
}
AnimBone& AnimBone::operator=(const AnimBone& anim)
{
if (this == &anim)
return *this;
boneId = anim.boneId;
keyFrames = anim.keyFrames;
return *this;
}
UInt_8 AnimBone::GetBoneId() const
{
return boneId;
}
Array<KeyFrame> AnimBone::GetKeyFrames() const
{
return keyFrames;
}
Array<KeyFrame>& AnimBone::GetKeyFrames()
{
return keyFrames;
}
float AnimBone::GetPrevAndNext(KeyFrame& prev, KeyFrame& next, const float elapsed) const
{
prev = keyFrames[0];
next = keyFrames[0];
for (UInt_64 i = 1; i < keyFrames.Size(); ++i)
{
next = keyFrames[i];
if (keyFrames[i].GetTimeStamp() > elapsed)
break;
prev = keyFrames[i];
}
return (elapsed - prev.GetTimeStamp()) / (next.GetTimeStamp() - prev.GetTimeStamp());
}
}