#include "ehs/io/model/KeyFrame.h" #include namespace ehs { KeyFrame::KeyFrame() : num(0.0f), timeStamp(0.0f), scale(1.0f), trans(Mat4_f::Identity()) { } KeyFrame::KeyFrame(const float num, const float timeStamp, const Vec3_f& pos, const Quat_f& rot, const Vec3_f& scale) : num(num), timeStamp(timeStamp), pos(pos), rot(rot), scale(scale), trans(Mat4_f::Translate(pos) * rot.ToMatrix() * Mat4_f::Scale(scale)) { } KeyFrame::KeyFrame(const float num, const float timeStamp) : num(num), timeStamp(timeStamp), scale(1.0f), trans(Mat4_f::Identity()) { } KeyFrame::KeyFrame(const KeyFrame& kf) : num(kf.num), timeStamp(kf.timeStamp), pos(kf.pos), rot(kf.rot), scale(kf.scale), trans(kf.trans) { } KeyFrame& KeyFrame::operator=(const KeyFrame& kf) { if (this == &kf) return *this; num = kf.num; timeStamp = kf.timeStamp; pos = kf.pos; rot = kf.rot; scale = kf.scale; trans = kf.trans; return *this; } float KeyFrame::GetNum() const { return num; } float KeyFrame::GetTimeStamp() const { return timeStamp; } void KeyFrame::SetPos(const Vec3_f& newPos) { pos = newPos; } Vec3_f KeyFrame::GetPos() const { return pos; } void KeyFrame::SetRot(const Quat_f& newRot) { rot = newRot; } Quat_f KeyFrame::GetRot() const { return rot; } void KeyFrame::SetScale(const Vec3_f& newScale) { scale = newScale; } Vec3_f KeyFrame::GetScale() const { return scale; } void KeyFrame::CalculateTransform() { trans = Mat4_f::Translate(pos) * rot.ToMatrix() * Mat4_f::Scale(scale); } Mat4_f KeyFrame::GetTrans() const { return trans; } Mat4_f KeyFrame::Interpolate(const KeyFrame& prev, const KeyFrame& next, const float percentage) { Vec3_f newPos = Vec3_f::Lerp(prev.pos, next.pos, percentage); Quat_f newRot = Quat_f::Slerp(prev.rot, next.rot, percentage).GetNormalized(); Vec3_f newScale = Vec3_f::Lerp(prev.scale, next.scale, percentage); Mat4_f newTrans = Mat4_f::Translate(newPos) * newRot.ToMatrix() * Mat4_f::Scale(newScale); return newTrans; } }