2019-05-15 16:52:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class CVector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
float x, y, z;
|
|
|
|
CVector(void) {}
|
|
|
|
CVector(float x, float y, float z) : x(x), y(y), z(z) {}
|
2019-05-29 02:52:30 +02:00
|
|
|
// CVector(CVector &refVector) : x(refVector.x), y(refVector.y), z(refVector.z) { }
|
|
|
|
// CVector(const CVector &refVector) : x(refVector.x), y(refVector.y), z(refVector.z) {}
|
|
|
|
// CVector(CVector2D &refVector, float _z = 0.0f) : x(refVector.x), y(refVector.y), z(_z) {}
|
|
|
|
#ifdef RWCORE_H
|
|
|
|
CVector(RwV3d const &v) : x(v.x), y(v.y), z(v.z) {}
|
|
|
|
|
|
|
|
operator RwV3d (void) const {
|
|
|
|
RwV3d vecRw = { this->x, this->y, this->z };
|
|
|
|
return vecRw;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator RwV3d *(void)
|
|
|
|
{
|
|
|
|
return (RwV3d *)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator RwV3d &(void)
|
|
|
|
{
|
|
|
|
return *((RwV3d *)this);
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-15 16:52:37 +02:00
|
|
|
float Magnitude(void) const { return sqrt(x*x + y*y + z*z); }
|
|
|
|
float MagnitudeSqr(void) const { return x*x + y*y + z*z; }
|
|
|
|
float Magnitude2D(void) const { return sqrt(x*x + y*y); }
|
2019-05-29 02:52:30 +02:00
|
|
|
void Normalise(void);
|
|
|
|
|
|
|
|
|
|
|
|
// operator =
|
|
|
|
inline CVector const& operator = (CVector const &refRight)
|
|
|
|
{
|
|
|
|
x = refRight.x;
|
|
|
|
y = refRight.y;
|
|
|
|
z = refRight.z;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline CVector const& operator = (float fRight)
|
|
|
|
{
|
|
|
|
x = fRight;
|
|
|
|
y = fRight;
|
|
|
|
z = fRight;
|
|
|
|
return *this;
|
2019-05-15 16:52:37 +02:00
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
// operator +=
|
|
|
|
inline CVector const& operator += (CVector const &refRight)
|
|
|
|
{
|
|
|
|
x += refRight.x;
|
|
|
|
y += refRight.y;
|
|
|
|
z += refRight.z;
|
|
|
|
return *this;
|
2019-05-15 16:52:37 +02:00
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
inline CVector const& operator += (float fRight)
|
|
|
|
{
|
|
|
|
x += fRight;
|
|
|
|
y += fRight;
|
|
|
|
z += fRight;
|
|
|
|
return *this;
|
2019-05-15 16:52:37 +02:00
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
// operator -=
|
|
|
|
inline CVector const& operator -= (CVector const &refRight)
|
|
|
|
{
|
|
|
|
x -= refRight.x;
|
|
|
|
y -= refRight.y;
|
|
|
|
z -= refRight.z;
|
|
|
|
return *this;
|
2019-05-15 16:52:37 +02:00
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
inline CVector const& operator -= (float fRight)
|
|
|
|
{
|
|
|
|
x -= fRight;
|
|
|
|
y -= fRight;
|
|
|
|
z -= fRight;
|
|
|
|
return *this;
|
2019-05-15 16:52:37 +02:00
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
// operator *=
|
|
|
|
inline CVector const& operator *= (CVector const &refRight)
|
|
|
|
{
|
|
|
|
x *= refRight.x;
|
|
|
|
y *= refRight.y;
|
|
|
|
z *= refRight.z;
|
2019-05-15 16:52:37 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
inline CVector const& operator *= (float fRight)
|
|
|
|
{
|
|
|
|
x *= fRight;
|
|
|
|
y *= fRight;
|
|
|
|
z *= fRight;
|
2019-05-15 16:52:37 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
// operator /=
|
|
|
|
inline CVector const& operator /= (CVector const &refRight)
|
|
|
|
{
|
|
|
|
x /= refRight.x;
|
|
|
|
y /= refRight.y;
|
|
|
|
z /= refRight.z;
|
2019-05-15 16:52:37 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
inline CVector const& operator /= (float fRight)
|
|
|
|
{
|
|
|
|
x /= fRight;
|
|
|
|
y /= fRight;
|
|
|
|
z /= fRight;
|
2019-05-15 16:52:37 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
inline CVector operator - () const
|
|
|
|
{
|
|
|
|
return CVector(-x, -y, -z);
|
|
|
|
}
|
|
|
|
|
2019-05-19 21:28:10 +02:00
|
|
|
bool IsZero(void) { return x == 0.0f && y == 0.0f && z == 0.0f; }
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|
|
|
|
|
2019-05-29 02:52:30 +02:00
|
|
|
//extern CVector operator*(CMatrix const& matrix, CVector const& vector);
|
|
|
|
|
2019-05-15 16:52:37 +02:00
|
|
|
inline float
|
|
|
|
DotProduct(const CVector &v1, const CVector &v2)
|
|
|
|
{
|
|
|
|
return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline CVector
|
|
|
|
CrossProduct(const CVector &v1, const CVector &v2)
|
|
|
|
{
|
|
|
|
return CVector(
|
|
|
|
v1.y*v2.z - v1.z*v2.y,
|
|
|
|
v1.z*v2.x - v1.x*v2.z,
|
|
|
|
v1.x*v2.y - v1.y*v2.x);
|
|
|
|
}
|
2019-05-29 02:52:30 +02:00
|
|
|
|
|
|
|
// operator +
|
|
|
|
extern CVector operator + (CVector const &refLeft, CVector const &refRight);
|
|
|
|
extern CVector operator + (CVector const &refLeft, float fRight);
|
|
|
|
extern CVector operator + (float fLeft, CVector const &refRight);
|
|
|
|
|
|
|
|
// operator -
|
|
|
|
extern CVector operator - (CVector const &refLeft, CVector const &refRight);
|
|
|
|
extern CVector operator - (CVector const &refLeft, float fRight);
|
|
|
|
extern CVector operator - (float fLeft, CVector const &refRight);
|
|
|
|
|
|
|
|
// operator *
|
|
|
|
extern CVector operator * (CVector const &refLeft, CVector const &refRight);
|
|
|
|
extern CVector operator * (CVector const &refLeft, float fRight);
|
|
|
|
extern CVector operator * (float fLeft, CVector const &refRight);
|
|
|
|
|
|
|
|
// operator /
|
|
|
|
extern CVector operator / (CVector const &refLeft, CVector const &refRight);
|
|
|
|
extern CVector operator / (CVector const &refLeft, float fRight);
|
|
|
|
extern CVector operator / (float fLeft, CVector const &refRight);
|