Skip to content

Commit 7323fb3

Browse files
authored
Merge pull request #205 from TokyoSU/master
Add default constructors for BoundingBox and Model
2 parents be4b649 + 4d0a16f commit 7323fb3

File tree

6 files changed

+88
-52
lines changed

6 files changed

+88
-52
lines changed

include/BoundingBox.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ namespace raylib {
99
* Bounding box type
1010
*/
1111
class BoundingBox : public ::BoundingBox {
12-
public:
12+
public:
13+
/*
14+
* Set the bounding box to default: min (0, 0, 0) and max (0, 0, 0).
15+
*/
16+
BoundingBox() {
17+
set(::Vector3{ 0, 0, 0 }, ::Vector3{ 0, 0, 0 });
18+
}
19+
20+
/*
21+
* Copy a bounding box from another bounding box.
22+
*/
1323
BoundingBox(const ::BoundingBox& box) {
1424
set(box);
1525
}
@@ -68,11 +78,15 @@ class BoundingBox : public ::BoundingBox {
6878
return GetRayCollisionBox(ray, *this);
6979
}
7080

71-
private:
81+
private:
7282
void set(const ::BoundingBox& box) {
7383
min = box.min;
7484
max = box.max;
7585
}
86+
void set(const ::Vector3& _min, const ::Vector3& _max) {
87+
min = _min;
88+
max = _max;
89+
}
7690
};
7791
} // namespace raylib
7892
using RBoundingBox = raylib::BoundingBox;

include/Model.hpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@ namespace raylib {
1313
* Model type
1414
*/
1515
class Model : public ::Model {
16-
public:
16+
public:
17+
Model() {
18+
}
19+
20+
/*
21+
* Copy a model from another model.
22+
*/
1723
Model(const ::Model& model) {
1824
set(model);
1925
}
2026

27+
/*
28+
* Load a model from a file.
29+
*/
2130
Model(const std::string& fileName) {
22-
if (!Load(fileName)) {
23-
throw RaylibException("Failed to load Model from filename");
24-
}
31+
Load(fileName);
2532
}
2633

34+
/*
35+
* Load a model from a mesh.
36+
*/
2737
Model(const ::Mesh& mesh) {
28-
if (!Load(mesh)) {
29-
throw RaylibException("Failed to load Model from Mesh");
30-
}
38+
Load(mesh);
3139
}
3240

3341
~Model() {
@@ -51,12 +59,12 @@ class Model : public ::Model {
5159
GETTERSETTER(::Matrix, Transform, transform)
5260
GETTERSETTER(int, MeshCount, meshCount)
5361
GETTERSETTER(int, MaterialCount, materialCount)
54-
GETTERSETTER(::Mesh *, Meshes, meshes)
55-
GETTERSETTER(::Material *, Materials, materials)
56-
GETTERSETTER(int *, MeshMaterial, meshMaterial)
62+
GETTERSETTER(::Mesh*, Meshes, meshes)
63+
GETTERSETTER(::Material*, Materials, materials)
64+
GETTERSETTER(int*, MeshMaterial, meshMaterial)
5765
GETTERSETTER(int, BoneCount, boneCount)
58-
GETTERSETTER(::BoneInfo *, Bones, bones)
59-
GETTERSETTER(::Transform *, BindPose, bindPose)
66+
GETTERSETTER(::BoneInfo*, Bones, bones)
67+
GETTERSETTER(::Transform*, BindPose, bindPose)
6068

6169
Model& operator=(const ::Model& model) {
6270
set(model);
@@ -207,6 +215,9 @@ class Model : public ::Model {
207215
*/
208216
bool Load(const std::string& fileName) {
209217
set(::LoadModel(fileName.c_str()));
218+
if (!IsReady()) {
219+
throw RaylibException("Failed to load Model from " + fileName);
220+
}
210221
return IsReady();
211222
}
212223

@@ -217,10 +228,13 @@ class Model : public ::Model {
217228
*/
218229
bool Load(const ::Mesh& mesh) {
219230
set(::LoadModelFromMesh(mesh));
231+
if (!IsReady()) {
232+
throw RaylibException("Failed to load Model from Mesh");
233+
}
220234
return IsReady();
221235
}
222236

223-
private:
237+
private:
224238
void set(const ::Model& model) {
225239
transform = model.transform;
226240

include/RaylibException.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ class RaylibException : public std::runtime_error {
3232
};
3333

3434
} // namespace raylib
35+
using RRaylibException = raylib::RaylibException;
3536

3637
#endif // RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_

include/Texture.hpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ namespace raylib {
1414
* Texture type
1515
*/
1616
class Texture : public ::Texture {
17-
public:
17+
public:
1818
/**
19-
* Default constructor to create an empty Texture object.
19+
* Default texture constructor.
2020
*/
21-
Texture(unsigned int id = 0,
22-
int width = 0,
23-
int height = 0,
24-
int mipmaps = 0,
25-
int format = 0) : ::Texture{id, width, height, mipmaps, format} {
26-
// Nothing.
21+
Texture() {
22+
set(::Texture{0, 0, 0, 0, 0});
23+
}
24+
25+
/**
26+
* Move/Create a texture structure manually.
27+
*/
28+
Texture(unsigned int id, int width, int height, int mipmaps, int format) {
29+
set(::Texture{id, width, height, mipmaps, format});
2730
}
2831

2932
/**
@@ -39,9 +42,7 @@ class Texture : public ::Texture {
3942
* @throws raylib::RaylibException Throws if failed to create the texture from the given image.
4043
*/
4144
Texture(const ::Image& image) {
42-
if (!Load(image)) {
43-
throw RaylibException("Failed to load Texture from Image");
44-
}
45+
Load(image);
4546
}
4647

4748
/**
@@ -52,9 +53,7 @@ class Texture : public ::Texture {
5253
* @see LoadTextureCubemap()
5354
*/
5455
Texture(const ::Image& image, int layout) {
55-
if (!Load(image, layout)) {
56-
throw RaylibException("Failed to load Texture from Cubemap");
57-
}
56+
Load(image, layout);
5857
}
5958

6059
/**
@@ -63,9 +62,7 @@ class Texture : public ::Texture {
6362
* @throws raylib::RaylibException Throws if failed to create the texture from the given file.
6463
*/
6564
Texture(const std::string& fileName) {
66-
if (!Load(fileName)) {
67-
throw RaylibException(TextFormat("Failed to load Texture from file: %s", fileName.c_str()));
68-
}
65+
Load(fileName);
6966
}
7067

7168
Texture(const Texture&) = delete;
@@ -124,25 +121,31 @@ class Texture : public ::Texture {
124121
/**
125122
* Load texture from image data
126123
*/
127-
bool Load(const ::Image& image) {
124+
void Load(const ::Image& image) {
128125
set(::LoadTextureFromImage(image));
129-
return IsReady();
126+
if (!IsReady()) {
127+
throw RaylibException("Failed to load Texture from Image");
128+
}
130129
}
131130

132131
/**
133132
* Load cubemap from image, multiple image cubemap layouts supported
134133
*/
135-
bool Load(const ::Image& image, int layoutType) {
134+
void Load(const ::Image& image, int layoutType) {
136135
set(::LoadTextureCubemap(image, layoutType));
137-
return IsReady();
136+
if (!IsReady()) {
137+
throw RaylibException("Failed to load Texture from Cubemap");
138+
}
138139
}
139140

140141
/**
141142
* Load texture from file into GPU memory (VRAM)
142143
*/
143-
bool Load(const std::string& fileName) {
144+
void Load(const std::string& fileName) {
144145
set(::LoadTexture(fileName.c_str()));
145-
return IsReady();
146+
if (!IsReady()) {
147+
throw RaylibException("Failed to load Texture from file: " + fileName);
148+
}
146149
}
147150

148151
/**
@@ -306,7 +309,7 @@ class Texture : public ::Texture {
306309
return id != 0;
307310
}
308311

309-
private:
312+
private:
310313
void set(const ::Texture& texture) {
311314
id = texture.id;
312315
width = texture.width;

include/Window.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ namespace raylib {
1111
* Window and Graphics Device Functions.
1212
*/
1313
class Window {
14-
public:
14+
public:
15+
Window() {
16+
// need to create it manually with Init().
17+
}
18+
1519
/**
1620
* Initialize window and OpenGL context.
17-
*
18-
* @throws raylib::RaylibException Thrown if the window failed to initiate.
1921
*/
20-
Window(int width = 800, int height = 450, const std::string& title = "raylib",
21-
bool lateInit = false) {
22-
if (!lateInit) {
23-
if (!Init(width, height, title)) {
24-
throw RaylibException("Failed to create Window");
25-
}
26-
}
22+
Window(int width, int height, const std::string& title) {
23+
Init(width, height, title);
2724
}
2825

2926
/**
@@ -36,11 +33,14 @@ class Window {
3633
/**
3734
* Initializes the window.
3835
*
36+
* @throws raylib::RaylibException Thrown if the window failed to initiate.
3937
* @return True or false, depending on if the Window initialized properly.
4038
*/
41-
bool Init(int width = 800, int height = 450, const std::string& title = "raylib") {
39+
void Init(int width = 800, int height = 450, const std::string& title = "raylib") {
4240
::InitWindow(width, height, title.c_str());
43-
return IsWindowReady();
41+
if (!IsWindowReady()) {
42+
throw RaylibException("Failed to create Window");
43+
}
4444
}
4545

4646
/**

include/raymath.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ extern "C" {
1111
#ifndef RAYMATH_STATIC_INLINE
1212
#define RAYMATH_STATIC_INLINE
1313
#endif
14-
#pragma GCC diagnostic push
14+
#ifdef __GNUC__
15+
#pragma GCC diagnostic push // these throw a warning on visual studio, need to check if __GNUC__ is defined to use it.
1516
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
17+
#endif
1618
#include "raymath.h" // NOLINT
19+
#ifdef __GNUC__
1720
#pragma GCC diagnostic pop
1821
#endif
22+
#endif
1923
#ifdef __cplusplus
2024
}
2125
#endif

0 commit comments

Comments
 (0)