raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Vector3.hpp
1#ifndef RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
2#define RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
3
4#ifndef RAYLIB_CPP_NO_MATH
5#include <cmath>
6#endif
7
8#include <string>
9
10#include "./raylib.hpp"
11#include "./raymath.hpp"
12#include "./raylib-cpp-utils.hpp"
13#include "./RadiansDegrees.hpp"
14
15namespace raylib {
19class Vector3 : public ::Vector3 {
20 public:
21 Vector3(const ::Vector3& vec) : ::Vector3{vec.x, vec.y, vec.z} {}
22
23 Vector3(float x, float y, float z) : ::Vector3{x, y, z} {}
24 Vector3(float x, float y) : ::Vector3{x, y, 0} {}
25 Vector3(float x) : ::Vector3{x, 0, 0} {}
26 Vector3() {}
27
28 Vector3(::Color color) {
29 set(ColorToHSV(color));
30 }
31
32 GETTERSETTER(float, X, x)
33 GETTERSETTER(float, Y, y)
34 GETTERSETTER(float, Z, z)
35
36 Vector3& operator=(const ::Vector3& vector3) {
37 set(vector3);
38 return *this;
39 }
40
41 bool operator==(const ::Vector3& other) const {
42 return x == other.x
43 && y == other.y
44 && z == other.z;
45 }
46
47 bool operator!=(const ::Vector3& other) const {
48 return !(*this == other);
49 }
50
51 std::string ToString() const {
52 return TextFormat("Vector3(%f, %f, %f)", x, y, z);
53 }
54
55 operator std::string() const {
56 return ToString();
57 }
58
59#ifndef RAYLIB_CPP_NO_MATH
63 Vector3 Add(const ::Vector3& vector3) const {
64 return Vector3Add(*this, vector3);
65 }
66
70 Vector3 operator+(const ::Vector3& vector3) const {
71 return Vector3Add(*this, vector3);
72 }
73
74 Vector3& operator+=(const ::Vector3& vector3) {
75 set(Vector3Add(*this, vector3));
76
77 return *this;
78 }
79
83 Vector3 Subtract(const ::Vector3& vector3) const {
84 return Vector3Subtract(*this, vector3);
85 }
86
90 Vector3 operator-(const ::Vector3& vector3) const {
91 return Vector3Subtract(*this, vector3);
92 }
93
94 Vector3& operator-=(const ::Vector3& vector3) {
95 set(Vector3Subtract(*this, vector3));
96
97 return *this;
98 }
99
103 Vector3 Negate() const {
104 return Vector3Negate(*this);
105 }
106
111 return Vector3Negate(*this);
112 }
113
117 Vector3 Multiply(const ::Vector3& vector3) const {
118 return Vector3Multiply(*this, vector3);
119 }
120
124 Vector3 operator*(const ::Vector3& vector3) const {
125 return Vector3Multiply(*this, vector3);
126 }
127
131 Vector3& operator*=(const ::Vector3& vector3) {
132 set(Vector3Multiply(*this, vector3));
133
134 return *this;
135 }
136
140 Vector3 Scale(const float scaler) const {
141 return Vector3Scale(*this, scaler);
142 }
143
147 Vector3 operator*(const float scaler) const {
148 return Vector3Scale(*this, scaler);
149 }
150
154 Vector3& operator*=(const float scaler) {
155 set(Vector3Scale(*this, scaler));
156
157 return *this;
158 }
159
163 Vector3 Divide(const ::Vector3& vector3) const {
164 return Vector3Divide(*this, vector3);
165 }
166
170 Vector3 operator/(const ::Vector3& vector3) const {
171 return Vector3Divide(*this, vector3);
172 }
173
177 Vector3& operator/=(const ::Vector3& vector3) {
178 x /= vector3.x;
179 y /= vector3.y;
180 z /= vector3.z;
181
182 return *this;
183 }
184
188 Vector3 Divide(const float div) const {
189 return ::Vector3{x / div, y / div, z / div};
190 }
191
195 Vector3 operator/(const float div) const {
196 return Divide(div);
197 }
198
202 Vector3& operator/=(const float div) {
203 x /= div;
204 y /= div;
205 z /= div;
206
207 return *this;
208 }
209
213 float Length() const {
214 return Vector3Length(*this);
215 }
216
220 float LengthSqr() const {
221 return Vector3LengthSqr(*this);
222 }
223
224 Vector3 Normalize() const {
225 return Vector3Normalize(*this);
226 }
227
228 float DotProduct(const ::Vector3& vector3) const {
229 return Vector3DotProduct(*this, vector3);
230 }
231
232 float Distance(const ::Vector3& vector3) const {
233 return Vector3Distance(*this, vector3);
234 }
235
236 Vector3 Lerp(const ::Vector3& vector3, const float amount) const {
237 return Vector3Lerp(*this, vector3, amount);
238 }
239
240 Vector3 CrossProduct(const ::Vector3& vector3) const {
241 return Vector3CrossProduct(*this, vector3);
242 }
243
244 Vector3 Perpendicular() const {
245 return Vector3Perpendicular(*this);
246 }
247
248 Vector3 Project(const ::Vector3& vector3) const {
249 return Vector3Project(*this, vector3);
250 }
251
252 Vector3 Reject(const ::Vector3& vector3) const {
253 return Vector3Reject(*this, vector3);
254 }
255
256 void OrthoNormalize(::Vector3* vector3) {
257 Vector3OrthoNormalize(this, vector3);
258 }
259
260 Vector3 Transform(const ::Matrix& matrix) const {
261 return Vector3Transform(*this, matrix);
262 }
263
264 Vector3 RotateByQuaternion(const ::Quaternion& quaternion) const {
265 return Vector3RotateByQuaternion(*this, quaternion);
266 }
267
268 Vector3 Reflect(const ::Vector3& normal) const {
269 return Vector3Reflect(*this, normal);
270 }
271
272 Vector3 Min(const ::Vector3& vector3) const {
273 return Vector3Min(*this, vector3);
274 }
275
276 Vector3 Max(const ::Vector3& vector3) const {
277 return Vector3Max(*this, vector3);
278 }
279
280 Vector3 Barycenter(const ::Vector3& a, const ::Vector3& b, const ::Vector3& c) const {
281 return Vector3Barycenter(*this, a, b, c);
282 }
283
284 static Vector3 Zero() {
285 return Vector3Zero();
286 }
287
288 static Vector3 One() {
289 return Vector3One();
290 }
291
292 static inline Vector3 Left() {
293 return {1, 0, 0};
294 }
295
296 static inline Vector3 Right() {
297 return {-1, 0, 0};
298 }
299
300 static inline Vector3 Up() {
301 return {0, 1, 0};
302 }
303
304 static inline Vector3 Down() {
305 return {0, -1, 0};
306 }
307
308 static inline Vector3 Forward() {
309 return {0, 0, 1};
310 }
311
312 static inline Vector3 Back() {
313 return {0, 0, -1};
314 }
315#endif
316
317 void DrawLine3D(const ::Vector3& endPos, ::Color color) const {
318 ::DrawLine3D(*this, endPos, color);
319 }
320
321 void DrawPoint3D(::Color color) const {
322 ::DrawPoint3D(*this, color);
323 }
324
325 void DrawCircle3D(
326 float radius,
327 const ::Vector3& rotationAxis,
328 Radian rotationAngle,
329 Color color) const {
330 ::DrawCircle3D(*this, radius, rotationAxis, rotationAngle, color);
331 }
332
333 void DrawCube(float width, float height, float length, ::Color color) const {
334 ::DrawCube(*this, width, height, length, color);
335 }
336
337 void DrawCube(const ::Vector3& size, ::Color color) const {
338 ::DrawCubeV(*this, size, color);
339 }
340
341 void DrawCubeWires(float width, float height, float length, ::Color color) const {
342 ::DrawCubeWires(*this, width, height, length, color);
343 }
344
345 void DrawCubeWires(const ::Vector3& size, ::Color color) const {
346 ::DrawCubeWiresV(*this, size, color);
347 }
348
349 void DrawSphere(float radius, ::Color color) const {
350 ::DrawSphere(*this, radius, color);
351 }
352
353 void DrawSphere(float radius, int rings, int slices, ::Color color) const {
354 ::DrawSphereEx(*this, radius, rings, slices, color);
355 }
356
357 void DrawSphereWires(float radius, int rings, int slices, ::Color color) const {
358 ::DrawSphereWires(*this, radius, rings, slices, color);
359 }
360
361 void DrawCylinder(float radiusTop, float radiusBottom, float height,
362 int slices, ::Color color) const {
363 ::DrawCylinder(*this, radiusTop, radiusBottom, height, slices, color);
364 }
365
366 void DrawCylinderWires(float radiusTop, float radiusBottom, float height,
367 int slices, ::Color color) const {
368 ::DrawCylinderWires(*this, radiusTop, radiusBottom, height, slices, color);
369 }
370
371 void DrawPlane(const ::Vector2& size, ::Color color) const {
372 ::DrawPlane(*this, size, color);
373 }
374
378 bool CheckCollision(float radius1, const ::Vector3& center2, float radius2) const {
379 return CheckCollisionSpheres(*this, radius1, center2, radius2);
380 }
381
382 protected:
383 void set(const ::Vector3& vec) {
384 x = vec.x;
385 y = vec.y;
386 z = vec.z;
387 }
388};
389} // namespace raylib
390
392
393#endif // RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
Vector3 type.
Definition: Vector3.hpp:19
Vector3 operator/(const ::Vector3 &vector3) const
Divide vector by vector.
Definition: Vector3.hpp:170
Vector3 Negate() const
Negate provided vector (invert direction)
Definition: Vector3.hpp:103
Vector3 operator-() const
Negate provided vector (invert direction)
Definition: Vector3.hpp:110
Vector3 & operator/=(const ::Vector3 &vector3)
Divide vector by vector.
Definition: Vector3.hpp:177
Vector3 operator*(const ::Vector3 &vector3) const
Multiply vector by vector.
Definition: Vector3.hpp:124
Vector3 & operator*=(const float scaler)
Multiply vector by scalar.
Definition: Vector3.hpp:154
Vector3 & operator*=(const ::Vector3 &vector3)
Multiply vector by vector.
Definition: Vector3.hpp:131
Vector3 operator/(const float div) const
Divide a vector by a value.
Definition: Vector3.hpp:195
float LengthSqr() const
Calculate vector square length.
Definition: Vector3.hpp:220
Vector3 operator+(const ::Vector3 &vector3) const
Add two vectors.
Definition: Vector3.hpp:70
Vector3 Add(const ::Vector3 &vector3) const
Add two vectors.
Definition: Vector3.hpp:63
Vector3 Scale(const float scaler) const
Multiply vector by scalar.
Definition: Vector3.hpp:140
float Length() const
Calculate vector length.
Definition: Vector3.hpp:213
Vector3 Divide(const ::Vector3 &vector3) const
Divide vector by vector.
Definition: Vector3.hpp:163
Vector3 Divide(const float div) const
Divide a vector by a value.
Definition: Vector3.hpp:188
Vector3 Subtract(const ::Vector3 &vector3) const
Subtract two vectors.
Definition: Vector3.hpp:83
Vector3 & operator/=(const float div)
Divide a vector by a value.
Definition: Vector3.hpp:202
Vector3 Multiply(const ::Vector3 &vector3) const
Multiply vector by vector.
Definition: Vector3.hpp:117
Vector3 operator-(const ::Vector3 &vector3) const
Subtract two vectors.
Definition: Vector3.hpp:90
bool CheckCollision(float radius1, const ::Vector3 &center2, float radius2) const
Detect collision between two spheres.
Definition: Vector3.hpp:378
Vector3 operator*(const float scaler) const
Multiply vector by scalar.
Definition: Vector3.hpp:147