#ifndef SKEL_ANIM_H
#define SKEL_ANIM_H

#include "m/Math.h"
#include "util/Vec.h"
#include "util/Accessors.h"


/// Bone pose
struct BonePose
{
	public:
		BonePose(const Quat& r, const Vec3& trs);

		/// Copy constructor
		BonePose(const BonePose& b);

		/// @name Accessors
		/// @{
		GETTER_R(Quat, rotation, getRotation)
		GETTER_R(Vec3, translation, getTranslation)
		/// @}

	private:
		Quat rotation;
		Vec3 translation;
};


inline BonePose::BonePose(const Quat& r, const Vec3& trs)
:	rotation(r),
 	translation(trs)
{}


inline BonePose::BonePose(const BonePose& b)
:	rotation(b.rotation),
 	translation(b.translation)
{}


/// Bone animation
class BoneAnim
{
	friend class SkelAnim;

	public:
		/// @name Accessors
		/// @{
		GETTER_R(Vec<BonePose>, bonePoses, getBonePoses)
		/// @}

	private:
		/// The poses for every keyframe. Its empty if the bone doesnt have
		/// any animation
		Vec<BonePose> bonePoses;
};


/// Skeleton animation resource
///
/// The binary file format:
/// @code
/// magic: ANKIANIM
/// uint: Keyframes number m
/// m * uint: The keyframe numbers
/// uint: Bone animations num, n, The n is equal to skeleton's bone number
/// n * BoneAnim: Bone animations
///
/// BoneAnim:
/// uint: Bone poses number. Its zero or m
/// m * BonePose: Bone poses
///
/// BonePose:
/// 4 * float: Quaternion for rotation
/// 3 * float: Traslation
/// @endcode
class SkelAnim
{
	public:
		/// @name Accessors
		/// @{
		GETTER_R(Vec<uint>, keyframes, getKeyframes)
		GETTER_R_BY_VAL(uint, framesNum, getFramesNum)
		GETTER_R(Vec<BoneAnim>, boneAnims, getBoneAnims)
		/// @}

		/// Load
		void load(const char* filename);

	private:
		Vec<uint> keyframes;
		uint framesNum;
		Vec<BoneAnim> boneAnims;
};


#endif
