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