mirror of
https://github.com/YimMenu/RDR-Classes.git
synced 2024-12-22 22:47:31 +08:00
Vector Improvements (#25)
Co-authored-by: maybegreat48 <email@hostname>
This commit is contained in:
parent
d62a02a6d7
commit
3887e8cce5
117
rage/vector.hpp
117
rage/vector.hpp
@ -1,12 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#pragma pack(push, 0x10)
|
||||||
namespace rage
|
namespace rage
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
union vector2
|
class vector2
|
||||||
{
|
{
|
||||||
T data[2];
|
public:
|
||||||
struct { T x, y; };
|
T x, y;
|
||||||
|
|
||||||
constexpr vector2(T x, T y) :
|
constexpr vector2(T x, T y) :
|
||||||
x(x),
|
x(x),
|
||||||
@ -22,10 +24,10 @@ namespace rage
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
union vector3
|
class vector3
|
||||||
{
|
{
|
||||||
T data[3];
|
public:
|
||||||
struct { T x, y, z; };
|
T x, y, z;
|
||||||
|
|
||||||
constexpr vector3(T x, T y, T z) :
|
constexpr vector3(T x, T y, T z) :
|
||||||
x(x),
|
x(x),
|
||||||
@ -42,63 +44,23 @@ namespace rage
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
vector3<T> operator+(const vector3<T>& other)
|
bool operator==(const vector3<T>& other) const
|
||||||
{
|
|
||||||
vector3<T> vec;
|
|
||||||
vec.x = this->x + other.x;
|
|
||||||
vec.y = this->y + other.y;
|
|
||||||
vec.z = this->z + other.z;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
vector3<T> operator-(const vector3<T>& other)
|
|
||||||
{
|
|
||||||
vector3<T> vec;
|
|
||||||
vec.x = this->x - other.x;
|
|
||||||
vec.y = this->y - other.y;
|
|
||||||
vec.z = this->z - other.z;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
vector3<T> operator*(const vector3<T>& other)
|
|
||||||
{
|
|
||||||
vector3<T> vec;
|
|
||||||
vec.x = this->x * other.x;
|
|
||||||
vec.y = this->y * other.y;
|
|
||||||
vec.z = this->z * other.z;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
vector3<T> operator*(const float& other)
|
|
||||||
{
|
|
||||||
vector3<T> vec;
|
|
||||||
vec.x = this->x * other;
|
|
||||||
vec.y = this->y * other;
|
|
||||||
vec.z = this->z * other;
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool operator==(const vector3<T>& other)
|
|
||||||
{
|
{
|
||||||
return this->x == other.x && this->y == other.y && this->z == other.z;
|
return this->x == other.x && this->y == other.y && this->z == other.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool operator!=(const vector3<T>& other)
|
bool operator!=(const vector3<T>& other) const
|
||||||
{
|
{
|
||||||
return this->x != other.x || this->y != other.y || this->z != other.z;
|
return this->x != other.x || this->y != other.y || this->z != other.z;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
union vector4
|
class vector4
|
||||||
{
|
{
|
||||||
T data[4];
|
public:
|
||||||
struct { T x, y, z, w; };
|
T x, y, z, w;
|
||||||
|
|
||||||
constexpr vector4(T x, T y, T z, T w) :
|
constexpr vector4(T x, T y, T z, T w) :
|
||||||
x(x),
|
x(x),
|
||||||
@ -132,8 +94,59 @@ namespace rage
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef vector2<float> fvector2;
|
typedef vector2<float> fvector2;
|
||||||
typedef vector3<float> fvector3;
|
|
||||||
typedef vector4<float> fvector4;
|
typedef vector4<float> fvector4;
|
||||||
typedef matrix34<float> fmatrix34;
|
typedef matrix34<float> fmatrix34;
|
||||||
typedef matrix44<float> fmatrix44;
|
typedef matrix44<float> fmatrix44;
|
||||||
|
|
||||||
|
class fvector3 : public vector3<float>
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#pragma pack(pop)
|
Loading…
Reference in New Issue
Block a user