raylib-cpp
C++ object-oriented wrapper library for raylib.
Vector4.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
2 #define RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
3 
4 #ifndef RAYLIB_CPP_NO_MATH
5 #include <cmath>
6 #include <utility>
7 #endif
8 
9 #include "./raylib.hpp"
10 #include "./raymath.hpp"
11 #include "./raylib-cpp-utils.hpp"
12 
13 namespace raylib {
17 class Vector4 : public ::Vector4 {
18  public:
19  Vector4(const ::Vector4& vec) : ::Vector4{vec.x, vec.y, vec.z, vec.w} {}
20 
21  Vector4(float x, float y, float z, float w) : ::Vector4{x, y, z, w} {}
22  Vector4(float x, float y, float z) : ::Vector4{x, y, z, 0} {}
23  Vector4(float x, float y) : ::Vector4{x, y, 0, 0} {}
24  Vector4(float x) : ::Vector4{x, 0, 0, 0} {}
25  Vector4() : ::Vector4{0, 0, 0, 0} {}
26  Vector4(::Rectangle rectangle) : ::Vector4{rectangle.x, rectangle.y, rectangle.width, rectangle.height} {}
27 
28  Vector4(::Color color) {
29  set(ColorNormalize(color));
30  }
31 
32  GETTERSETTER(float, X, x)
33  GETTERSETTER(float, Y, y)
34  GETTERSETTER(float, Z, z)
35  GETTERSETTER(float, W, w)
36 
37  Vector4& operator=(const ::Vector4& vector4) {
38  set(vector4);
39  return *this;
40  }
41 
42  bool operator==(const ::Vector4& other) {
43  return x == other.x
44  && y == other.y
45  && z == other.z
46  && w == other.w;
47  }
48 
49  bool operator!=(const ::Vector4& other) {
50  return !(*this == other);
51  }
52 
53  inline ::Rectangle ToRectangle() {
54  return {x, y, z, w};
55  }
56 
57  operator ::Rectangle() const {
58  return {x, y, z, w};
59  }
60 
61 #ifndef RAYLIB_CPP_NO_MATH
62  inline Vector4 Multiply(const ::Vector4& vector4) const {
63  return QuaternionMultiply(*this, vector4);
64  }
65 
66  inline Vector4 operator*(const ::Vector4& vector4) const {
67  return QuaternionMultiply(*this, vector4);
68  }
69 
70  inline Vector4 Lerp(const ::Vector4& vector4, float amount) const {
71  return QuaternionLerp(*this, vector4, amount);
72  }
73 
74  inline Vector4 Nlerp(const ::Vector4& vector4, float amount) const {
75  return QuaternionNlerp(*this, vector4, amount);
76  }
77 
78  inline Vector4 Slerp(const ::Vector4& vector4, float amount) const {
79  return QuaternionSlerp(*this, vector4, amount);
80  }
81 
82  inline Matrix ToMatrix() const {
83  return QuaternionToMatrix(*this);
84  }
85 
86  inline float Length() const {
87  return QuaternionLength(*this);
88  }
89 
90  inline Vector4 Normalize() const {
91  return QuaternionNormalize(*this);
92  }
93 
94  inline Vector4 Invert() const {
95  return QuaternionInvert(*this);
96  }
97 
98  inline void ToAxisAngle(::Vector3 *outAxis, float *outAngle) {
99  QuaternionToAxisAngle(*this, outAxis, outAngle);
100  }
101 
105  std::pair<Vector3, float> ToAxisAngle() {
106  Vector3 outAxis;
107  float outAngle;
108  QuaternionToAxisAngle(*this, &outAxis, &outAngle);
109 
110  return std::pair<Vector3, float>(outAxis, outAngle);
111  }
112 
113  inline Vector4 Transform(const ::Matrix& matrix) {
114  return ::QuaternionTransform(*this, matrix);
115  }
116 
117  static inline Vector4 Identity() {
118  return ::QuaternionIdentity();
119  }
120 
121  static inline Vector4 FromVector3ToVector3(const ::Vector3& from , const ::Vector3& to) {
122  return ::QuaternionFromVector3ToVector3(from , to);
123  }
124 
125  static inline Vector4 FromMatrix(const ::Matrix& matrix) {
126  return ::QuaternionFromMatrix(matrix);
127  }
128 
129  static inline Vector4 FromAxisAngle(const ::Vector3& axis, const float angle) {
130  return ::QuaternionFromAxisAngle(axis, angle);
131  }
132 
133  static inline Vector4 FromEuler(const float yaw, const float pitch, const float roll) {
134  return ::QuaternionFromEuler(yaw, pitch, roll);
135  }
136 
137  static inline Vector4 FromEuler(const ::Vector3& vector3) {
138  return ::QuaternionFromEuler(vector3.x, vector3.y, vector3.z);
139  }
140 
141  inline Vector3 ToEuler() {
142  return ::QuaternionToEuler(*this);
143  }
144 #endif
145 
146  inline Color ColorFromNormalized() const {
147  return ::ColorFromNormalized(*this);
148  }
149 
150  operator Color() {
151  return ColorFromNormalized();
152  }
153 
154  private:
155  void set(const ::Vector4& vec4) {
156  x = vec4.x;
157  y = vec4.y;
158  z = vec4.z;
159  w = vec4.w;
160  }
161 };
162 
163 // Alias the Vector4 as Quaternion.
164 typedef Vector4 Quaternion;
165 } // namespace raylib
166 
167 using RVector4 = raylib::Vector4;
169 
170 #endif // RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
Color type, RGBA (32bit)
Definition: Color.hpp:14
Rectangle type.
Definition: Rectangle.hpp:12
Vector3 type.
Definition: Vector3.hpp:16
Vector4 type.
Definition: Vector4.hpp:17
std::pair< Vector3, float > ToAxisAngle()
Get the rotation angle and axis for a given quaternion.
Definition: Vector4.hpp:105
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8