raylib-cpp
C++ object-oriented wrapper library for raylib.
Model.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_MODEL_HPP_
2 #define RAYLIB_CPP_INCLUDE_MODEL_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 #include "./Mesh.hpp"
9 
10 namespace raylib {
14 class Model : public ::Model {
15  public:
16  Model(const ::Model& model) {
17  set(model);
18  }
19 
20  Model(const std::string& fileName) {
21  set(::LoadModel(fileName.c_str()));
22  }
23 
24  Model(const ::Mesh& mesh) {
25  set(::LoadModelFromMesh(mesh));
26  }
27 
28  ~Model() {
29  Unload();
30  }
31 
32  Model(const Model&) = delete;
33 
34  Model(Model&& other) {
35  set(other);
36 
37  other.bones = nullptr;
38  other.boneCount = 0;
39  other.materials = nullptr;
40  other.materialCount = 0;
41  other.meshes = nullptr;
42  other.meshCount = 0;
43  other.bindPose = nullptr;
44  }
45 
46  GETTERSETTER(::Matrix, Transform, transform)
47  GETTERSETTER(int, MeshCount, meshCount)
48  GETTERSETTER(int, MaterialCount, materialCount)
49  GETTERSETTER(::Mesh *, Meshes, meshes)
50  GETTERSETTER(::Material *, Materials, materials)
51  GETTERSETTER(int *, MeshMaterial, meshMaterial)
52  GETTERSETTER(int, BoneCount, boneCount)
53  GETTERSETTER(::BoneInfo *, Bones, bones)
54  GETTERSETTER(::Transform *, BindPoe, bindPose)
55 
56  Model& operator=(const ::Model& model) {
57  set(model);
58  return *this;
59  }
60 
61  Model& operator=(const Model&) = delete;
62 
63  Model& operator=(Model&& other) {
64  if (this != &other) {
65  return *this;
66  }
67 
68  Unload();
69  set(other);
70 
71  other.bones = nullptr;
72  other.boneCount = 0;
73  other.materials = nullptr;
74  other.materialCount = 0;
75  other.meshes = nullptr;
76  other.meshCount = 0;
77  other.bindPose = nullptr;
78 
79  return *this;
80  }
81 
85  inline void Unload() {
86  if (meshes != nullptr || materials != nullptr) {
87  ::UnloadModel(*this);
88  meshes = nullptr;
89  materials = nullptr;
90  }
91  }
92 
96  inline Model& UnloadKeepMeshes() {
97  ::UnloadModelKeepMeshes(*this);
98  return *this;
99  }
100 
104  inline Model& SetMeshMaterial(int meshId, int materialId) {
105  ::SetModelMeshMaterial(this, meshId, materialId);
106  return *this;
107  }
108 
112  inline RayCollision GetCollision(const ::Ray& ray) const {
113  return ::GetRayCollisionModel(ray, *this);
114  }
115 
119  inline Model& UpdateAnimation(const ::ModelAnimation& anim, int frame) {
120  ::UpdateModelAnimation(*this, anim, frame);
121  return *this;
122  }
123 
127  inline bool IsModelAnimationValid(const ::ModelAnimation& anim) const {
128  return ::IsModelAnimationValid(*this, anim);
129  }
130 
134  inline Model& Draw(::Vector3 position,
135  float scale = 1.0f,
136  ::Color tint = {255, 255, 255, 255}) {
137  ::DrawModel(*this, position, scale, tint);
138  return *this;
139  }
140 
144  inline Model& Draw(
145  ::Vector3 position,
146  ::Vector3 rotationAxis,
147  float rotationAngle = 0.0f,
148  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
149  ::Color tint = {255, 255, 255, 255}) {
150  ::DrawModelEx(*this, position, rotationAxis, rotationAngle, scale, tint);
151  return *this;
152  }
153 
157  inline Model& DrawWires(::Vector3 position,
158  float scale = 1.0f,
159  ::Color tint = {255, 255, 255, 255}) {
160  ::DrawModelWires(*this, position, scale, tint);
161  return *this;
162  }
163 
167  inline Model& DrawWires(
168  ::Vector3 position,
169  ::Vector3 rotationAxis,
170  float rotationAngle = 0.0f,
171  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
172  ::Color tint = {255, 255, 255, 255}) {
173  ::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint);
174  return *this;
175  }
176 
180  inline BoundingBox GetBoundingBox() const {
181  return ::GetModelBoundingBox(*this);
182  }
183 
187  operator BoundingBox() const {
188  return ::GetModelBoundingBox(*this);
189  }
190 
191  private:
192  inline void set(const ::Model& model) {
193  transform = model.transform;
194 
195  meshCount = model.meshCount;
196  materialCount = model.materialCount;
197  meshes = model.meshes;
198  materials = model.materials;
199  meshMaterial = model.meshMaterial;
200 
201  boneCount = model.boneCount;
202  bones = model.bones;
203  bindPose = model.bindPose;
204  }
205 };
206 } // namespace raylib
207 
208 #endif // RAYLIB_CPP_INCLUDE_MODEL_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Matrix
Matrix type (OpenGL style 4x4 - right handed, column major)
Definition: Matrix.hpp:16
raylib::Model::DrawWires
Model & DrawWires(::Vector3 position, float scale=1.0f, ::Color tint={255, 255, 255, 255})
Draw a model wires (with texture if set)
Definition: Model.hpp:157
raylib::Model::DrawWires
Model & DrawWires(::Vector3 position, ::Vector3 rotationAxis, float rotationAngle=0.0f, ::Vector3 scale={1.0f, 1.0f, 1.0f}, ::Color tint={255, 255, 255, 255})
Draw a model wires (with texture if set) with extended parameters.
Definition: Model.hpp:167
raylib::Model::SetMeshMaterial
Model & SetMeshMaterial(int meshId, int materialId)
Set material for a mesh.
Definition: Model.hpp:104
raylib::Model::Draw
Model & Draw(::Vector3 position, float scale=1.0f, ::Color tint={255, 255, 255, 255})
Draw a model (with texture if set)
Definition: Model.hpp:134
raylib::RayCollision
Raycast hit information.
Definition: RayCollision.hpp:11
raylib::Model::Draw
Model & Draw(::Vector3 position, ::Vector3 rotationAxis, float rotationAngle=0.0f, ::Vector3 scale={1.0f, 1.0f, 1.0f}, ::Color tint={255, 255, 255, 255})
Draw a model with extended parameters.
Definition: Model.hpp:144
raylib::Model::IsModelAnimationValid
bool IsModelAnimationValid(const ::ModelAnimation &anim) const
Check model animation skeleton match.
Definition: Model.hpp:127
raylib::Vector3
Vector3 type.
Definition: Vector3.hpp:16
raylib::Model::UpdateAnimation
Model & UpdateAnimation(const ::ModelAnimation &anim, int frame)
Update model animation pose.
Definition: Model.hpp:119
raylib::Mesh
Vertex data definning a mesh.
Definition: Mesh.hpp:16
raylib::Model::GetBoundingBox
BoundingBox GetBoundingBox() const
Compute model bounding box limits (considers all meshes)
Definition: Model.hpp:180
raylib::Color
Color type, RGBA (32bit)
Definition: Color.hpp:14
raylib::Model
Model type.
Definition: Model.hpp:14
raylib::Model::GetCollision
RayCollision GetCollision(const ::Ray &ray) const
Get collision info between ray and model.
Definition: Model.hpp:112
raylib::BoundingBox
Bounding box type.
Definition: BoundingBox.hpp:11
raylib::Material
Material type (generic)
Definition: Material.hpp:14
raylib::Model::Unload
void Unload()
Unload model (including meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:85
raylib::Model::UnloadKeepMeshes
Model & UnloadKeepMeshes()
Unload model (but not meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:96