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