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