Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __KEY_FRAME__
- #define __KEY_FRAME__
- #include "Core/Math/Numeric/Common.h"
- #include "Core/Math/Numeric/Float4.h"
- #include "Core/Math/Numeric/Quat.h"
- #include "Core/Math/Numeric/Mat4.h"
- namespace Engine
- {
- /// <summary>
- /// Class holding single keyframe for animation
- /// </summary>
- class __declspec(align(16)) KeyFrame
- {
- public:
- /// <summary>
- /// Keyframe type (whether keyframe is defining position, rotation or scale)
- /// </summary>
- enum class Type : unsigned int
- {
- POSITION = 0,
- ROTATION,
- SCALE
- };
- private:
- /// <summary>
- /// 16-byte field holding keyframe data
- /// </summary>
- union
- {
- float4 mPosition;
- quat mRotation;
- float4 mScaling;
- };
- /// <summary>
- /// Timestamp in animation for keyframe (in seconds)
- /// </summary>
- float mTime;
- /// <summary>
- /// Type of keyframe (position, rotation or scaling) - see enum class Type
- /// </summary>
- Type mType;
- /// <summary>
- /// Pad to align on 16-byte boundaries
- /// </summary>
- float mPad[2];
- public:
- /// <summary>
- /// Default constructor
- /// </summary>
- inline KeyFrame()
- {
- mPosition = float4(0.0f, 0.0f, 0.0f, 1.0f);
- mTime = 0.0f;
- mType = Type::POSITION;
- mPad[0] = mPad[1] = 0.0f;
- }
- /// <summary>
- /// Copy constructor
- /// </summary>
- /// <param name="kf">Keyframe to copy</param>
- inline KeyFrame(const KeyFrame& kf)
- {
- mPosition = kf.mPosition;
- mTime = kf.mTime;
- mType = kf.mType;
- mPad[0] = mPad[1] = 0.0f;
- }
- /// <summary>
- /// Constructor for position keyframe
- /// </summary>
- /// <param name="time">Time for keyframe inside animation (in seconds)</param>
- /// <param name="value">Value representing position at specified time</param>
- inline KeyFrame(float time, const float4& value)
- {
- mTime = time;
- mPosition = value;
- mType = Type::POSITION;
- mPad[0] = mPad[1] = 0.0f;
- }
- /// <summary>
- /// Constructor for rotation keyframe
- /// </summary>
- /// <param name="time">Time for keyframe inside animation (in seconds)</param>
- /// <param name="value">Quaternion representing rotation at specified time</param>
- inline KeyFrame(float time, const quat& value)
- {
- mTime = time;
- mRotation = value;
- mType = Type::ROTATION;
- mPad[0] = mPad[1] = 0.0f;
- }
- /// <summary>
- /// Static method to create position keyframe
- /// </summary>
- /// <param name="time">Time for keyframe inside animation (in seconds)</param>
- /// <param name="position">Value representing position at specified time</param>
- /// <returns>Position keyframe by value</returns>
- inline static KeyFrame InitializePosition(float time, const float4& position)
- {
- KeyFrame kf = KeyFrame(time, position);
- return kf;
- }
- /// <summary>
- /// Static method to create rotation keyframe
- /// </summary>
- /// <param name="time">Time for keyframe inside animation (in seconds)</param>
- /// <param name="rotation">Quaternion representing rotation at specified time</param>
- /// <returns>Rotation keyframe by value</returns>
- inline static KeyFrame InitializeRotation(float time, const quat& rotation)
- {
- KeyFrame kf = KeyFrame(time, rotation);
- return kf;
- }
- /// <summary>
- /// Static method to create scaling keyframe
- /// </summary>
- /// <param name="time">Time for keyframe inside animation (in seconds)</param>
- /// <param name="scale">Value representing scale at specified time</param>
- /// <returns>Scaling keyframe by value</returns>
- inline static KeyFrame InitializeScale(float time, const float4& scale)
- {
- KeyFrame kf;
- kf.mTime = time;
- kf.mScaling = scale;
- kf.mType = Type::SCALE;
- return kf;
- }
- ALIGNED_NEW_DELETE("Engine::KeyFrame")
- };
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement