Advertisement
Zgragselus

Untitled

Nov 14th, 2021
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.74 KB | None | 0 0
  1. #ifndef __KEY_FRAME__
  2. #define __KEY_FRAME__
  3.  
  4. #include "Core/Math/Numeric/Common.h"
  5. #include "Core/Math/Numeric/Float4.h"
  6. #include "Core/Math/Numeric/Quat.h"
  7. #include "Core/Math/Numeric/Mat4.h"
  8.  
  9. namespace Engine
  10. {
  11.     /// <summary>
  12.     /// Class holding single keyframe for animation
  13.     /// </summary>
  14.     class __declspec(align(16)) KeyFrame
  15.     {
  16.     public:
  17.         /// <summary>
  18.         /// Keyframe type (whether keyframe is defining position, rotation or scale)
  19.         /// </summary>
  20.         enum class Type : unsigned int
  21.         {
  22.             POSITION = 0,
  23.             ROTATION,
  24.             SCALE
  25.         };
  26.  
  27.     private:
  28.         /// <summary>
  29.         /// 16-byte field holding keyframe data
  30.         /// </summary>
  31.         union
  32.         {
  33.             float4 mPosition;
  34.             quat mRotation;
  35.             float4 mScaling;
  36.         };
  37.  
  38.         /// <summary>
  39.         /// Timestamp in animation for keyframe (in seconds)
  40.         /// </summary>
  41.         float mTime;
  42.  
  43.         /// <summary>
  44.         /// Type of keyframe (position, rotation or scaling) - see enum class Type
  45.         /// </summary>
  46.         Type mType;
  47.  
  48.         /// <summary>
  49.         /// Pad to align on 16-byte boundaries
  50.         /// </summary>
  51.         float mPad[2];
  52.  
  53.     public:
  54.         /// <summary>
  55.         /// Default constructor
  56.         /// </summary>
  57.         inline KeyFrame()
  58.         {
  59.             mPosition = float4(0.0f, 0.0f, 0.0f, 1.0f);
  60.             mTime = 0.0f;
  61.             mType = Type::POSITION;
  62.             mPad[0] = mPad[1] = 0.0f;
  63.         }
  64.  
  65.         /// <summary>
  66.         /// Copy constructor
  67.         /// </summary>
  68.         /// <param name="kf">Keyframe to copy</param>
  69.         inline KeyFrame(const KeyFrame& kf)
  70.         {
  71.             mPosition = kf.mPosition;
  72.             mTime = kf.mTime;
  73.             mType = kf.mType;
  74.             mPad[0] = mPad[1] = 0.0f;
  75.         }
  76.  
  77.         /// <summary>
  78.         /// Constructor for position keyframe
  79.         /// </summary>
  80.         /// <param name="time">Time for keyframe inside animation (in seconds)</param>
  81.         /// <param name="value">Value representing position at specified time</param>
  82.         inline KeyFrame(float time, const float4& value)
  83.         {
  84.             mTime = time;
  85.             mPosition = value;
  86.             mType = Type::POSITION;
  87.             mPad[0] = mPad[1] = 0.0f;
  88.         }
  89.  
  90.         /// <summary>
  91.         /// Constructor for rotation keyframe
  92.         /// </summary>
  93.         /// <param name="time">Time for keyframe inside animation (in seconds)</param>
  94.         /// <param name="value">Quaternion representing rotation at specified time</param>
  95.         inline KeyFrame(float time, const quat& value)
  96.         {
  97.             mTime = time;
  98.             mRotation = value;
  99.             mType = Type::ROTATION;
  100.             mPad[0] = mPad[1] = 0.0f;
  101.         }
  102.  
  103.         /// <summary>
  104.         /// Static method to create position keyframe
  105.         /// </summary>
  106.         /// <param name="time">Time for keyframe inside animation (in seconds)</param>
  107.         /// <param name="position">Value representing position at specified time</param>
  108.         /// <returns>Position keyframe by value</returns>
  109.         inline static KeyFrame InitializePosition(float time, const float4& position)
  110.         {
  111.             KeyFrame kf = KeyFrame(time, position);
  112.             return kf;
  113.         }
  114.  
  115.         /// <summary>
  116.         /// Static method to create rotation keyframe
  117.         /// </summary>
  118.         /// <param name="time">Time for keyframe inside animation (in seconds)</param>
  119.         /// <param name="rotation">Quaternion representing rotation at specified time</param>
  120.         /// <returns>Rotation keyframe by value</returns>
  121.         inline static KeyFrame InitializeRotation(float time, const quat& rotation)
  122.         {
  123.             KeyFrame kf = KeyFrame(time, rotation);
  124.             return kf;
  125.         }
  126.  
  127.         /// <summary>
  128.         /// Static method to create scaling keyframe
  129.         /// </summary>
  130.         /// <param name="time">Time for keyframe inside animation (in seconds)</param>
  131.         /// <param name="scale">Value representing scale at specified time</param>
  132.         /// <returns>Scaling keyframe by value</returns>
  133.         inline static KeyFrame InitializeScale(float time, const float4& scale)
  134.         {
  135.             KeyFrame kf;
  136.             kf.mTime = time;
  137.             kf.mScaling = scale;
  138.             kf.mType = Type::SCALE;
  139.             return kf;
  140.         }
  141.  
  142.         ALIGNED_NEW_DELETE("Engine::KeyFrame")
  143.     };
  144. }
  145.  
  146. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement