2013-09-11 01:26:13 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef _ANIMATOR_HPP_
|
|
|
|
#define _ANIMATOR_HPP_
|
|
|
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <glm/gtx/quaternion.hpp>
|
2014-05-31 13:15:20 +02:00
|
|
|
#include <queue>
|
2014-06-02 05:58:41 +02:00
|
|
|
#include <map>
|
|
|
|
#include <loaders/LoaderIFP.hpp>
|
2013-09-11 01:26:13 +02:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
class Model;
|
2014-03-01 12:19:33 +01:00
|
|
|
class ModelFrame;
|
2013-09-11 01:26:13 +02:00
|
|
|
|
2014-12-11 18:48:47 +01:00
|
|
|
class Skeleton;
|
|
|
|
|
2013-09-11 01:26:13 +02:00
|
|
|
/**
|
2014-07-09 06:04:48 +02:00
|
|
|
* @brief calculates animation frame matrices, as well as procedural frame
|
|
|
|
* animation.
|
2013-09-11 01:26:13 +02:00
|
|
|
*/
|
|
|
|
class Animator
|
|
|
|
{
|
2014-05-31 13:15:20 +02:00
|
|
|
/**
|
|
|
|
* @brief _animations Queue of animations to play.
|
|
|
|
*/
|
|
|
|
std::queue<Animation*> _animations;
|
2013-09-11 01:26:13 +02:00
|
|
|
|
2014-05-31 13:15:20 +02:00
|
|
|
/**
|
|
|
|
* @brief model The model being animated.
|
|
|
|
*/
|
2013-09-11 01:26:13 +02:00
|
|
|
Model* model;
|
2014-12-11 18:48:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Skeleton instance.
|
|
|
|
*/
|
|
|
|
Skeleton* skeleton;
|
2013-09-11 01:26:13 +02:00
|
|
|
|
2014-07-09 06:04:48 +02:00
|
|
|
/**
|
|
|
|
* @brief Stores data required to animate a model frame
|
|
|
|
*/
|
2014-12-11 18:48:47 +01:00
|
|
|
struct BoneInstanceData
|
|
|
|
{
|
|
|
|
unsigned int frameIdx;
|
2014-06-02 05:58:41 +02:00
|
|
|
};
|
|
|
|
|
2014-12-11 18:48:47 +01:00
|
|
|
std::map<AnimationBone*, BoneInstanceData> boneInstances;
|
2014-06-02 05:58:41 +02:00
|
|
|
|
2014-05-31 13:15:20 +02:00
|
|
|
// Used in determining how far the skeleton being animated has moved
|
|
|
|
// From it's local origin.
|
2013-09-11 01:26:13 +02:00
|
|
|
glm::vec3 lastRootPosition;
|
|
|
|
glm::quat lastRootRotation;
|
|
|
|
|
|
|
|
float time;
|
|
|
|
float serverTime;
|
|
|
|
float lastServerTime;
|
2014-05-31 13:15:20 +02:00
|
|
|
|
2014-07-09 03:06:59 +02:00
|
|
|
bool playing;
|
2013-09-30 20:32:14 +02:00
|
|
|
bool repeat;
|
2013-09-11 01:26:13 +02:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-12-11 18:48:47 +01:00
|
|
|
Animator(Model* model, Skeleton* skeleton);
|
2013-09-11 01:26:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief setAnimation Sets the currently active animation.
|
|
|
|
* @param animation
|
2013-09-30 20:32:14 +02:00
|
|
|
* @param repeat If true animation will restart after ending.
|
2013-09-11 01:26:13 +02:00
|
|
|
* @todo Interpolate between the new and old frames.
|
|
|
|
*/
|
2013-09-30 20:32:14 +02:00
|
|
|
void setAnimation(Animation* animation, bool repeat = true);
|
2013-09-11 01:26:13 +02:00
|
|
|
|
2014-05-31 13:15:20 +02:00
|
|
|
void queueAnimation(Animation* animation);
|
|
|
|
|
|
|
|
void next();
|
|
|
|
|
|
|
|
const std::queue<Animation*> getAnimationQueue() const
|
|
|
|
{ return _animations; }
|
|
|
|
|
|
|
|
const Animation* getAnimation() const
|
|
|
|
{ return _animations.empty() ? nullptr : _animations.front(); }
|
2014-03-02 11:38:50 +01:00
|
|
|
|
2013-09-11 01:26:13 +02:00
|
|
|
/**
|
|
|
|
* @brief tick Update animation paramters for server-side data.
|
|
|
|
* @param dt
|
|
|
|
*/
|
|
|
|
void tick(float dt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief render Update frame matricies for client-side animation.
|
|
|
|
* @param dt
|
|
|
|
*/
|
|
|
|
void render(float dt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief getRootTranslation Returns the translation of the root bone from the last server-side frame.
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
glm::vec3 getRootTranslation() const;
|
|
|
|
|
2014-08-05 16:09:42 +02:00
|
|
|
/**
|
2014-12-11 18:48:47 +01:00
|
|
|
* @brief getTimeTranslation returns the translation of the root bone at the current time.
|
2014-08-05 16:09:42 +02:00
|
|
|
* @return
|
|
|
|
*/
|
2014-12-12 13:30:23 +01:00
|
|
|
glm::vec3 getTimeTranslation(float alpha) const;
|
2014-08-05 16:09:42 +02:00
|
|
|
|
2013-09-11 01:26:13 +02:00
|
|
|
/**
|
|
|
|
* @brief getRootRotation see getRootTranslation
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
glm::quat getRootRotation() const;
|
|
|
|
|
2013-10-02 02:27:48 +02:00
|
|
|
/**
|
|
|
|
* Returns true if the animation has finished playing.
|
|
|
|
*/
|
|
|
|
bool isCompleted() const;
|
2014-03-01 12:19:33 +01:00
|
|
|
|
|
|
|
float getAnimationTime(float alpha = 0.f) const;
|
2014-06-29 23:14:46 +02:00
|
|
|
void setAnimationTime(float time);
|
2014-07-09 03:06:59 +02:00
|
|
|
|
|
|
|
void setPlaying( bool play ) { playing = play; }
|
2013-09-11 01:26:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|