raylib-cpp
C++ object-oriented wrapper library for raylib.
Vector3.hpp
1 #ifndef RAYLIB_CPP_VECTOR3_HPP_
2 #define RAYLIB_CPP_VECTOR3_HPP_
3 
4 #ifdef __cplusplus
5 extern "C"{
6 #endif
7 #include "raylib.h"
8 #ifndef RAYLIB_CPP_NO_MATH
9 #include "raymath.h"
10 #endif
11 #ifdef __cplusplus
12 }
13 #endif
14 
15 #include "utils.hpp"
16 #ifndef RAYLIB_CPP_NO_MATH
17 #include <cmath>
18 #endif
19 
20 namespace raylib {
21  class Vector3 : public ::Vector3 {
22  public:
23  Vector3(::Vector3 vec) {
24  set(vec);
25  };
26  Vector3(float X = 0, float Y = 0, float Z = 0) {
27  x = X;
28  y = Y;
29  z = Z;
30  };
31 
32  Vector3(::Color color) {
33  set(ColorToHSV(color));
34  }
35  inline void set(::Vector3 vec) {
36  x = vec.x;
37  y = vec.y;
38  z = vec.z;
39  }
40 
41  GETTERSETTER(float,X,x)
42  GETTERSETTER(float,Y,y)
43  GETTERSETTER(float,Z,z)
44 
45  Vector3& operator=(const ::Vector3& vector3) {
46  set(vector3);
47  return *this;
48  }
49 
50  Vector3& operator=(const Vector3& vector3) {
51  set(vector3);
52  return *this;
53  }
54 
55  bool operator==(const Vector3& other) {
56  return x == other.x
57  && y == other.y
58  && z == other.z;
59  }
60 
61 #ifndef RAYLIB_CPP_NO_MATH
62  Vector3 Add(const Vector3& vector3) {
63  return Vector3Add(*this, vector3);
64  }
65 
66  Vector3 operator+(const Vector3& vector3) {
67  return Vector3Add(*this, vector3);
68  }
69 
70  Vector3 Subtract(const Vector3& vector3) {
71  return Vector3Subtract(*this, vector3);
72  }
73 
74  Vector3 operator-(const Vector3& vector3) {
75  return Vector3Subtract(*this, vector3);
76  }
77 
79  return Vector3Negate(*this);
80  }
81 
83  return Vector3Negate(*this);
84  }
85 
86  Vector3 Multiply(const Vector3& vector3) {
87  return Vector3Multiply(*this, vector3);
88  }
89 
90  Vector3 operator*(const Vector3& vector3) {
91  return Vector3Multiply(*this, vector3);
92  }
93 
94  Vector3 Scale(const float scale) {
95  return Vector3Scale(*this, scale);
96  }
97 
98  Vector3 operator*(const float scale) {
99  return Vector3Scale(*this, scale);
100  }
101 
102  Vector3 Divide(const Vector3& vector3) {
103  return Vector3DivideV(*this, vector3);
104  }
105 
106  Vector3 operator/(const Vector3& vector3) {
107  return Vector3DivideV(*this, vector3);
108  }
109 
110  Vector3 Divide(const float div) {
111  return Vector3Divide(*this, div);
112  }
113 
114  Vector3 operator/(const float div) {
115  return Vector3Divide(*this, div);
116  }
117 
118  Vector3& operator+=(const Vector3& vector3) {
119  set(Vector3Add(*this, vector3));
120 
121  return *this;
122  }
123 
124  Vector3& operator-=(const Vector3& vector3) {
125  set(Vector3Subtract(*this, vector3));
126 
127  return *this;
128  }
129 
130 
131  Vector3& operator*=(const Vector3& vector3) {
132  set(Vector3Multiply(*this, vector3));
133 
134  return *this;
135  }
136 
137  Vector3& operator*=(const float scale) {
138  set(Vector3Scale(*this, scale));
139 
140  return *this;
141  }
142 
143  Vector3& operator/=(const Vector3& vector3) {
144  set(Vector3DivideV(*this, vector3));
145 
146  return *this;
147  }
148 
149  Vector3& operator/=(const float div) {
150  set(Vector3Divide(*this, div));
151 
152  return *this;
153  }
154 
155  float Length() {
156  return Vector3Length(*this);
157  }
158 
160  return Vector3Normalize(*this);
161  }
162 
163  float DotProduct(const Vector3& vector3) {
164  return Vector3DotProduct(*this, vector3);
165  }
166 
167  float Distance(const Vector3& vector3) {
168  return Vector3Distance(*this, vector3);
169  }
170 
171  Vector3 Lerp(const Vector3& vector3, const float amount) {
172  return Vector3Lerp(*this, vector3, amount);
173  }
174 
175  Vector3 CrossProduct(const Vector3& vector3) {
176  return Vector3CrossProduct(*this, vector3);
177  }
178 
180  return Vector3Perpendicular(*this);
181  }
182 
183  void OrthoNormalize(Vector3* vector3) {
184  return Vector3OrthoNormalize(this, vector3);
185  }
186 
187  Vector3 Transform(const ::Matrix& matrix) {
188  return Vector3Transform(*this, matrix);
189  }
190 
192  return Vector3RotateByQuaternion(*this, quaternion);
193  }
194 
195  Vector3 Reflect(const Vector3& normal) {
196  return Vector3Reflect(*this, normal);
197  }
198 
199  Vector3 Min(const Vector3& vector3) {
200  return Vector3Min(*this, vector3);
201  }
202 
203  Vector3 Max(const Vector3& vector3) {
204  return Vector3Max(*this, vector3);
205  }
206 
207  Vector3 Barycenter(const Vector3& a, const Vector3& b, const Vector3& c) {
208  return Vector3Barycenter(*this, a, b, c);
209  }
210 
211  static Vector3 Zero() {
212  return Vector3Zero();
213  }
214 
215  static Vector3 One() {
216  return Vector3One();
217  }
218 #endif
219 
220  inline Vector3& DrawLine3D(::Vector3 endPos, ::Color color) {
221  ::DrawLine3D(*this, endPos, color);
222  return *this;
223  }
224  inline Vector3& DrawPoint3D(::Color color) {
225  ::DrawPoint3D(*this, color);
226  return *this;
227  }
228  inline Vector3& DrawCircle3D(float radius, Vector3 rotationAxis, float rotationAngle, Color color) {
229  ::DrawCircle3D(*this, radius, rotationAxis, rotationAngle, color);
230  return *this;
231  }
232 
233  inline Vector3& DrawCube(float width, float height, float length, ::Color color) {
234  ::DrawCube(*this, width, height, length, color);
235  return *this;
236  }
237  inline Vector3& DrawCube(::Vector3 size, ::Color color) {
238  ::DrawCubeV(*this, size, color);
239  return *this;
240  }
241 
242  inline Vector3& DrawCubeWires(float width, float height, float length, ::Color color) {
243  ::DrawCubeWires(*this, width, height, length, color);
244  return *this;
245  }
246  inline Vector3& DrawCubeWires(::Vector3 size, ::Color color) {
247  ::DrawCubeWiresV(*this, size, color);
248  return *this;
249  }
250 
251  inline Vector3& DrawCubeTexture(::Texture2D texture, float width, float height, float length, ::Color color) {
252  ::DrawCubeTexture(texture, *this, width, height, length, color);
253  return *this;
254  }
255 
256  inline Vector3& DrawSphere(float radius, Color color) {
257  ::DrawSphere(*this, radius, color);
258  return *this;
259  }
260 
261  inline Vector3& DrawSphere(float radius, int rings, int slices, Color color) {
262  ::DrawSphereEx(*this, radius, rings, slices, color);
263  return *this;
264  }
265 
266  inline Vector3& DrawSphereWires(float radius, int rings, int slices, Color color) {
267  ::DrawSphereWires(*this, radius, rings, slices, color);
268  return *this;
269  }
270 
271  inline Vector3& DrawCylinder(float radiusTop, float radiusBottom, float height, int slices, Color color) {
272  ::DrawCylinder(*this, radiusTop, radiusBottom, height, slices, color);
273  return *this;
274  }
275 
276  inline Vector3& DrawCylinderWires(float radiusTop, float radiusBottom, float height, int slices, Color color) {
277  ::DrawCylinderWires(*this, radiusTop, radiusBottom, height, slices, color);
278  return *this;
279  }
280 
281  inline Vector3& DrawPlane(::Vector2 size, ::Color color) {
282  ::DrawPlane(*this, size, color);
283  return *this;
284  }
285 
286  inline Vector3& DrawGizmo() {
287  ::DrawGizmo(*this);
288  return *this;
289  }
290 
291  inline bool CheckCollision(float radiusA, Vector3 centerB, float radiusB) {
292  return CheckCollisionSpheres(*this, radiusA, centerB, radiusB);
293  }
294  };
295 }
296 
297 #endif
Vector3 Subtract(const Vector3 &vector3)
Definition: Vector3.hpp:70
Vector3 & DrawPlane(::Vector2 size, ::Color color)
Definition: Vector3.hpp:281
Vector3 Multiply(const Vector3 &vector3)
Definition: Vector3.hpp:86
Vector3 Divide(const Vector3 &vector3)
Definition: Vector3.hpp:102
Vector3 Reflect(const Vector3 &normal)
Definition: Vector3.hpp:195
Vector3 & DrawSphere(float radius, Color color)
Definition: Vector3.hpp:256
void OrthoNormalize(Vector3 *vector3)
Definition: Vector3.hpp:183
Vector3 Normalize()
Definition: Vector3.hpp:159
float Length()
Definition: Vector3.hpp:155
Vector3 & DrawCylinderWires(float radiusTop, float radiusBottom, float height, int slices, Color color)
Definition: Vector3.hpp:276
Vector3 Max(const Vector3 &vector3)
Definition: Vector3.hpp:203
Vector3 Perpendicular()
Definition: Vector3.hpp:179
Vector3 Barycenter(const Vector3 &a, const Vector3 &b, const Vector3 &c)
Definition: Vector3.hpp:207
Vector3 & DrawCircle3D(float radius, Vector3 rotationAxis, float rotationAngle, Color color)
Definition: Vector3.hpp:228
Vector3 CrossProduct(const Vector3 &vector3)
Definition: Vector3.hpp:175
Vector3 & operator-=(const Vector3 &vector3)
Definition: Vector3.hpp:124
Vector3 Divide(const float div)
Definition: Vector3.hpp:110
Vector3 operator+(const Vector3 &vector3)
Definition: Vector3.hpp:66
Vector3 operator*(const float scale)
Definition: Vector3.hpp:98
Vector3 & DrawSphereWires(float radius, int rings, int slices, Color color)
Definition: Vector3.hpp:266
Vector3 operator/(const Vector3 &vector3)
Definition: Vector3.hpp:106
Vector3 & DrawCubeWires(::Vector3 size, ::Color color)
Definition: Vector3.hpp:246
Vector3(::Color color)
Definition: Vector3.hpp:32
Vector3 Add(const Vector3 &vector3)
Definition: Vector3.hpp:62
Vector3 & DrawGizmo()
Definition: Vector3.hpp:286
Vector3 & operator=(const Vector3 &vector3)
Definition: Vector3.hpp:50
Vector3 & DrawSphere(float radius, int rings, int slices, Color color)
Definition: Vector3.hpp:261
Vector3 & DrawCylinder(float radiusTop, float radiusBottom, float height, int slices, Color color)
Definition: Vector3.hpp:271
Vector3(float X=0, float Y=0, float Z=0)
Definition: Vector3.hpp:26
Vector3 Min(const Vector3 &vector3)
Definition: Vector3.hpp:199
Vector3 operator/(const float div)
Definition: Vector3.hpp:114
Vector3 Transform(const ::Matrix &matrix)
Definition: Vector3.hpp:187
bool operator==(const Vector3 &other)
Definition: Vector3.hpp:55
Vector3 & operator*=(const Vector3 &vector3)
Definition: Vector3.hpp:131
static Vector3 Zero()
Definition: Vector3.hpp:211
Vector3 & DrawCubeTexture(::Texture2D texture, float width, float height, float length, ::Color color)
Definition: Vector3.hpp:251
Vector3 & operator/=(const float div)
Definition: Vector3.hpp:149
Vector3 Scale(const float scale)
Definition: Vector3.hpp:94
float DotProduct(const Vector3 &vector3)
Definition: Vector3.hpp:163
Vector3 operator-()
Definition: Vector3.hpp:82
Vector3 & DrawCube(::Vector3 size, ::Color color)
Definition: Vector3.hpp:237
Vector3 RotateByQuaternion(Quaternion quaternion)
Definition: Vector3.hpp:191
Vector3 & DrawCube(float width, float height, float length, ::Color color)
Definition: Vector3.hpp:233
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:14
static Vector3 One()
Definition: Vector3.hpp:215
Vector3 & DrawPoint3D(::Color color)
Definition: Vector3.hpp:224
Vector3 & operator*=(const float scale)
Definition: Vector3.hpp:137
Vector3 & DrawLine3D(::Vector3 endPos, ::Color color)
Definition: Vector3.hpp:220
Vector3 & operator/=(const Vector3 &vector3)
Definition: Vector3.hpp:143
Vector3 & DrawCubeWires(float width, float height, float length, ::Color color)
Definition: Vector3.hpp:242
Vector3 & operator+=(const Vector3 &vector3)
Definition: Vector3.hpp:118
Vector3 Lerp(const Vector3 &vector3, const float amount)
Definition: Vector3.hpp:171
Vector3 Negate()
Definition: Vector3.hpp:78
float Distance(const Vector3 &vector3)
Definition: Vector3.hpp:167
Vector3(::Vector3 vec)
Definition: Vector3.hpp:23
bool CheckCollision(float radiusA, Vector3 centerB, float radiusB)
Definition: Vector3.hpp:291
Vector3 operator*(const Vector3 &vector3)
Definition: Vector3.hpp:90
Vector3 operator-(const Vector3 &vector3)
Definition: Vector3.hpp:74