130 lines
2.6 KiB
C++
130 lines
2.6 KiB
C++
#include "ehs/io/mdl/Animation.h"
|
|
|
|
namespace ehs
|
|
{
|
|
Animation::Animation()
|
|
: hashId(0), duration(0.0f)
|
|
{
|
|
}
|
|
|
|
Animation::Animation(Str_8 id, const float duration)
|
|
: hashId(id.Hash_64()), id(std::move(id)), duration(duration)
|
|
{
|
|
}
|
|
|
|
Animation::Animation(Str_8 id, const float duration, UInt_64 size)
|
|
: hashId(id.Hash_64()), id(std::move(id)), duration(duration), animated(size)
|
|
{
|
|
}
|
|
|
|
Animation::Animation(Str_8 id, const float duration, Array<AnimBone> animated)
|
|
: hashId(id.Hash_64()), id(std::move(id)), duration(duration), animated(std::move(animated))
|
|
{
|
|
}
|
|
|
|
Animation::Animation(Animation&& anim) noexcept
|
|
: hashId(anim.hashId), id(std::move(anim.id)), duration(anim.duration), animated(std::move(anim.animated))
|
|
{
|
|
anim.hashId = 0;
|
|
anim.duration = 0.0f;
|
|
}
|
|
|
|
Animation::Animation(const Animation& anim)
|
|
: hashId(anim.hashId), id(anim.id), duration(anim.duration), animated(anim.animated)
|
|
{
|
|
}
|
|
|
|
Animation& Animation::operator=(Animation&& anim) noexcept
|
|
{
|
|
if (this == &anim)
|
|
return *this;
|
|
|
|
hashId = anim.hashId;
|
|
id = std::move(anim.id);
|
|
duration = anim.duration;
|
|
animated = std::move(anim.animated);
|
|
|
|
anim.hashId = 0;
|
|
anim.duration = 0.0f;
|
|
|
|
return *this;
|
|
}
|
|
|
|
Animation& Animation::operator=(const Animation& anim)
|
|
{
|
|
if (this == &anim)
|
|
return *this;
|
|
|
|
hashId = anim.hashId;
|
|
id = anim.id;
|
|
duration = anim.duration;
|
|
animated = anim.animated;
|
|
|
|
return *this;
|
|
}
|
|
|
|
UInt_64 Animation::GetHashId() const
|
|
{
|
|
return hashId;
|
|
}
|
|
|
|
void Animation::SetId(Str_8 newId)
|
|
{
|
|
hashId = newId.Hash_64();
|
|
id = std::move(newId);
|
|
}
|
|
|
|
Str_8 Animation::GetId() const
|
|
{
|
|
return id;
|
|
}
|
|
|
|
float Animation::GetDuration() const
|
|
{
|
|
return duration;
|
|
}
|
|
|
|
Array<AnimBone> Animation::GetAnimated() const
|
|
{
|
|
return animated;
|
|
}
|
|
|
|
Array<AnimBone>& Animation::GetAnimated()
|
|
{
|
|
return animated;
|
|
}
|
|
|
|
Array<Mat4_f> Animation::Interpolate(const UInt_64 boneCount, const float elapsed) const
|
|
{
|
|
Array<Mat4_f> result(boneCount);
|
|
for (UInt_64 i = 0; i < result.Size(); ++i)
|
|
result[i] = Mat4_f::Identity();
|
|
|
|
if (elapsed == 0.0f)
|
|
{
|
|
for (UInt_64 i = 0; i < animated.Size(); ++i)
|
|
{
|
|
Array<KeyFrame> keyFrames = animated[i].GetKeyFrames();
|
|
if (!keyFrames.Size())
|
|
continue;
|
|
|
|
result[animated[i].GetBoneId()] = keyFrames[0].GetTrans();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (UInt_64 i = 0; i < animated.Size(); ++i)
|
|
{
|
|
KeyFrame prev;
|
|
KeyFrame next;
|
|
float perc = animated[i].GetPrevAndNext(prev, next, elapsed);
|
|
if (prev.GetNum() == next.GetNum() || perc <= 0.0f)
|
|
result[animated[i].GetBoneId()] = prev.GetTrans();
|
|
else
|
|
result[animated[i].GetBoneId()] = KeyFrame::Interpolate(prev, next, perc);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
} |