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