1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-06-18 12:33:13 +00:00
re3/src/math/Vector2D.h

68 lines
1.3 KiB
C
Raw Normal View History

2019-05-15 14:52:37 +00:00
#pragma once
class CVector2D
{
public:
float x, y;
CVector2D(void) {}
CVector2D(float x, float y) : x(x), y(y) {}
CVector2D(const CVector &v) : x(v.x), y(v.y) {}
float Heading(void) const { return Atan2(-x, y); }
2019-07-10 15:18:26 +00:00
float Magnitude(void) const { return Sqrt(x*x + y*y); }
2019-05-15 14:52:37 +00:00
float MagnitudeSqr(void) const { return x*x + y*y; }
void Normalise(void){
float sq = MagnitudeSqr();
if(sq > 0.0f){
float invsqrt = RecipSqrt(sq);
2019-05-15 14:52:37 +00:00
x *= invsqrt;
y *= invsqrt;
}else
x = 0.0f;
}
2019-08-03 22:31:00 +00:00
const CVector2D &operator+=(CVector2D const &right) {
x += right.x;
y += right.y;
return *this;
}
const CVector2D &operator-=(CVector2D const &right) {
x -= right.x;
y -= right.y;
return *this;
}
const CVector2D &operator*=(float right) {
x *= right;
y *= right;
return *this;
}
const CVector2D &operator/=(float right) {
x /= right;
y /= right;
return *this;
}
2019-05-15 14:52:37 +00:00
CVector2D operator-(const CVector2D &rhs) const {
return CVector2D(x-rhs.x, y-rhs.y);
}
CVector2D operator+(const CVector2D &rhs) const {
return CVector2D(x+rhs.x, y+rhs.y);
}
CVector2D operator*(float t) const {
return CVector2D(x*t, y*t);
}
};
2019-06-19 12:06:13 +00:00
inline float
DotProduct2D(const CVector2D &v1, const CVector2D &v2)
{
return v1.x*v2.x + v1.y*v2.y;
}
2019-05-15 14:52:37 +00:00
inline float
CrossProduct2D(const CVector2D &v1, const CVector2D &v2)
{
return v1.x*v2.y - v1.y*v2.x;
}