raylib-cpp
C++ object-oriented wrapper library for raylib.
ModelAnimation.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
2 #define RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
3 
4 #include <vector>
5 #include <string>
6 
7 #include "./raylib.hpp"
8 #include "./raylib-cpp-utils.hpp"
9 #include "./Mesh.hpp"
10 
11 namespace raylib {
16  public:
17  ModelAnimation(const ::ModelAnimation& model) {
18  set(model);
19  }
20 
21  ModelAnimation(const ModelAnimation&) = delete;
22 
24  set(other);
25 
26  other.boneCount = 0;
27  other.bones = nullptr;
28  other.frameCount = 0;
29  other.framePoses = nullptr;
30  }
31 
32  ~ModelAnimation() {
33  Unload();
34  }
35 
39  static std::vector<ModelAnimation> Load(const std::string& fileName) {
40  unsigned int count = 0;
41  ::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count);
42  std::vector<ModelAnimation> mats(modelAnimations, modelAnimations + count);
43 
44  RL_FREE(modelAnimations);
45 
46  return mats;
47  }
48 
49  GETTERSETTER(int, BoneCount, boneCount)
50  GETTERSETTER(::BoneInfo*, Bones, bones)
51  GETTERSETTER(int, FrameCount, frameCount)
52  GETTERSETTER(::Transform**, FramePoses, framePoses)
53 
54  ModelAnimation& operator=(const ::ModelAnimation& model) {
55  set(model);
56  return *this;
57  }
58 
59  ModelAnimation& operator=(const ModelAnimation&) = delete;
60 
61  ModelAnimation& operator=(ModelAnimation&& other) {
62  if (this != &other) {
63  return *this;
64  }
65 
66  Unload();
67  set(other);
68 
69  other.boneCount = 0;
70  other.bones = nullptr;
71  other.frameCount = 0;
72  other.framePoses = nullptr;
73 
74  return *this;
75  }
76 
80  inline void Unload() {
81  ::UnloadModelAnimation(*this);
82  }
83 
87  inline ModelAnimation& Update(const ::Model& model, int frame) {
88  ::UpdateModelAnimation(model, *this, frame);
89  return *this;
90  }
91 
95  inline bool IsValid(const ::Model& model) const {
96  return ::IsModelAnimationValid(model, *this);
97  }
98 
99  private:
100  inline void set(const ::ModelAnimation& model) {
101  boneCount = model.boneCount;
102  bones = model.bones;
103  frameCount = model.frameCount;
104  framePoses = model.framePoses;
105  }
106 };
107 } // namespace raylib
108 
109 #endif // RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
raylib::ModelAnimation::Update
ModelAnimation & Update(const ::Model &model, int frame)
Update model animation pose.
Definition: ModelAnimation.hpp:87
raylib::ModelAnimation::Load
static std::vector< ModelAnimation > Load(const std::string &fileName)
Load model animations from file.
Definition: ModelAnimation.hpp:39
raylib::ModelAnimation::Unload
void Unload()
Unload animation data.
Definition: ModelAnimation.hpp:80
raylib::ModelAnimation::IsValid
bool IsValid(const ::Model &model) const
Check model animation skeleton match.
Definition: ModelAnimation.hpp:95
raylib::ModelAnimation
Model animation.
Definition: ModelAnimation.hpp:15