2023-08-27 03:12:04 +08:00
|
|
|
#pragma once
|
2024-07-15 23:12:40 +08:00
|
|
|
#include <cmath>
|
2023-08-27 03:12:04 +08:00
|
|
|
|
2024-07-15 23:12:40 +08:00
|
|
|
#pragma pack(push, 0x10)
|
2023-08-27 03:12:04 +08:00
|
|
|
namespace rage
|
|
|
|
{
|
|
|
|
template<typename T>
|
2024-07-15 23:12:40 +08:00
|
|
|
class vector2
|
2023-08-27 03:12:04 +08:00
|
|
|
{
|
2024-07-15 23:12:40 +08:00
|
|
|
public:
|
|
|
|
T x, y;
|
2023-08-27 03:12:04 +08:00
|
|
|
|
2023-09-30 05:45:35 +08:00
|
|
|
constexpr vector2(T x, T y) :
|
2023-08-27 03:12:04 +08:00
|
|
|
x(x),
|
|
|
|
y(y)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-09-30 05:45:35 +08:00
|
|
|
constexpr vector2() :
|
2023-08-27 03:12:04 +08:00
|
|
|
x(),
|
|
|
|
y()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
2024-07-15 23:12:40 +08:00
|
|
|
class vector3
|
2023-08-27 03:12:04 +08:00
|
|
|
{
|
2024-07-15 23:12:40 +08:00
|
|
|
public:
|
|
|
|
T x, y, z;
|
2023-08-27 03:12:04 +08:00
|
|
|
|
2023-09-30 05:45:35 +08:00
|
|
|
constexpr vector3(T x, T y, T z) :
|
2023-08-27 03:12:04 +08:00
|
|
|
x(x),
|
|
|
|
y(y),
|
|
|
|
z(z)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-09-30 05:45:35 +08:00
|
|
|
constexpr vector3() :
|
2023-08-27 03:12:04 +08:00
|
|
|
x(),
|
|
|
|
y(),
|
|
|
|
z()
|
|
|
|
{
|
|
|
|
}
|
2024-07-07 23:32:27 +08:00
|
|
|
|
|
|
|
template<typename T>
|
2024-07-15 23:12:40 +08:00
|
|
|
bool operator==(const vector3<T>& other) const
|
2024-07-07 23:32:27 +08:00
|
|
|
{
|
|
|
|
return this->x == other.x && this->y == other.y && this->z == other.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2024-07-15 23:12:40 +08:00
|
|
|
bool operator!=(const vector3<T>& other) const
|
2024-07-07 23:32:27 +08:00
|
|
|
{
|
|
|
|
return this->x != other.x || this->y != other.y || this->z != other.z;
|
|
|
|
}
|
2023-08-27 03:12:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
2024-07-15 23:12:40 +08:00
|
|
|
class vector4
|
2023-08-27 03:12:04 +08:00
|
|
|
{
|
2024-07-15 23:12:40 +08:00
|
|
|
public:
|
|
|
|
T x, y, z, w;
|
2023-08-27 03:12:04 +08:00
|
|
|
|
2023-09-30 05:45:35 +08:00
|
|
|
constexpr vector4(T x, T y, T z, T w) :
|
2023-08-27 03:12:04 +08:00
|
|
|
x(x),
|
|
|
|
y(y),
|
|
|
|
z(z),
|
|
|
|
w(w)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-09-30 05:45:35 +08:00
|
|
|
constexpr vector4() :
|
2023-08-27 03:12:04 +08:00
|
|
|
x(),
|
|
|
|
y(),
|
|
|
|
z(),
|
|
|
|
w()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
union matrix34
|
|
|
|
{
|
|
|
|
T data[3][4];
|
|
|
|
struct { struct { T x, y, z, w; } rows[3]; };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
union matrix44
|
|
|
|
{
|
|
|
|
T data[4][4];
|
|
|
|
struct { struct { T x, y, z, w; } rows[4]; };
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef vector2<float> fvector2;
|
|
|
|
typedef vector4<float> fvector4;
|
|
|
|
typedef matrix34<float> fmatrix34;
|
|
|
|
typedef matrix44<float> fmatrix44;
|
2024-07-15 23:12:40 +08:00
|
|
|
|
|
|
|
class fvector3 : public vector3<float>
|
|
|
|
{
|
2024-07-15 23:59:35 +08:00
|
|
|
public:
|
2024-07-15 23:12:40 +08:00
|
|
|
using vector3::vector3;
|
|
|
|
|
|
|
|
fvector3 operator+(const fvector3& other) const
|
|
|
|
{
|
|
|
|
fvector3 vec;
|
|
|
|
vec.x = this->x + other.x;
|
|
|
|
vec.y = this->y + other.y;
|
|
|
|
vec.z = this->z + other.z;
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
fvector3 operator-(const fvector3& other) const
|
|
|
|
{
|
|
|
|
fvector3 vec;
|
|
|
|
vec.x = this->x - other.x;
|
|
|
|
vec.y = this->y - other.y;
|
|
|
|
vec.z = this->z - other.z;
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
fvector3 operator*(const fvector3& other) const
|
|
|
|
{
|
|
|
|
fvector3 vec;
|
|
|
|
vec.x = this->x * other.x;
|
|
|
|
vec.y = this->y * other.y;
|
|
|
|
vec.z = this->z * other.z;
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
fvector3 operator*(const float& other) const
|
|
|
|
{
|
|
|
|
fvector3 vec;
|
|
|
|
vec.x = this->x * other;
|
|
|
|
vec.y = this->y * other;
|
|
|
|
vec.z = this->z * other;
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float GetMagnitude() const
|
|
|
|
{
|
|
|
|
return std::sqrt(x * x + y * y + z * z);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float GetDistance(const rage::fvector3& other) const
|
|
|
|
{
|
|
|
|
return (*this - other).GetMagnitude();
|
|
|
|
}
|
|
|
|
};
|
2023-10-09 21:01:36 +08:00
|
|
|
}
|
2024-07-15 23:12:40 +08:00
|
|
|
#pragma pack(pop)
|