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  inline ::Rectangle ToRectangle() {
52  return {x, y, z, w};
53  }
54 
55  operator ::Rectangle() const {
56  return {x, y, z, w};
57  }
58 
59 #ifndef RAYLIB_CPP_NO_MATH
60  Vector4 Multiply(const ::Vector4& vector4) const {
61  return QuaternionMultiply(*this, vector4);
62  }
63 
64  Vector4 operator*(const ::Vector4& vector4) const {
65  return QuaternionMultiply(*this, vector4);
66  }
67 
68  Vector4 Lerp(const ::Vector4& vector4, float amount) const {
69  return QuaternionLerp(*this, vector4, amount);
70  }
71 
72  Vector4 Nlerp(const ::Vector4& vector4, float amount) const {
73  return QuaternionNlerp(*this, vector4, amount);
74  }
75 
76  Vector4 Slerp(const ::Vector4& vector4, float amount) const {
77  return QuaternionSlerp(*this, vector4, amount);
78  }
79 
80  Matrix ToMatrix() const {
81  return QuaternionToMatrix(*this);
82  }
83 
84  float Length() const {
85  return QuaternionLength(*this);
86  }
87 
88  Vector4 Normalize() const {
89  return QuaternionNormalize(*this);
90  }
91 
92  Vector4 Invert() const {
93  return QuaternionInvert(*this);
94  }
95 
96  void ToAxisAngle(::Vector3 *outAxis, float *outAngle) {
97  QuaternionToAxisAngle(*this, outAxis, outAngle);
98  }
99 
100  std::pair<Vector3, float> ToAxisAngle() {
101  Vector3 outAxis;
102  float outAngle;
103 
104  QuaternionToAxisAngle(*this, &outAxis, &outAngle);
105 
106  std::pair<Vector3, float> out(outAxis, outAngle);
107 
108  return out;
109  }
110 
111  Vector4 Transform(const ::Matrix& matrix) {
112  return ::QuaternionTransform(*this, matrix);
113  }
114 
115  static Vector4 Identity() {
116  return ::QuaternionIdentity();
117  }
118 
119  static Vector4 FromVector3ToVector3(const ::Vector3& from , const ::Vector3& to) {
120  return ::QuaternionFromVector3ToVector3(from , to);
121  }
122 
123  static Vector4 FromMatrix(const ::Matrix& matrix) {
124  return ::QuaternionFromMatrix(matrix);
125  }
126 
127  static Vector4 FromAxisAngle(const ::Vector3& axis, const float angle) {
128  return ::QuaternionFromAxisAngle(axis, angle);
129  }
130 
131  static Vector4 FromEuler(const float yaw, const float pitch, const float roll) {
132  return ::QuaternionFromEuler(yaw, pitch, roll);
133  }
134 
135  static Vector4 FromEuler(const ::Vector3& vector3) {
136  return ::QuaternionFromEuler(vector3.x, vector3.y, vector3.z);
137  }
138 
139  Vector3 ToEuler() {
140  return ::QuaternionToEuler(*this);
141  }
142 #endif
143 
144  inline Color ColorFromNormalized() const {
145  return ::ColorFromNormalized(*this);
146  }
147 
148  operator Color() {
149  return ColorFromNormalized();
150  }
151 
152  private:
153  inline void set(const ::Vector4& vec4) {
154  x = vec4.x;
155  y = vec4.y;
156  z = vec4.z;
157  w = vec4.w;
158  }
159 };
160 
161 // Alias the Vector4 as Quaternion.
162 typedef Vector4 Quaternion;
163 } // namespace raylib
164 
165 #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