This commit is contained in:
aap
2019-05-30 00:47:33 +02:00
parent b705be0e87
commit 0a36d49d2c
20 changed files with 115 additions and 302 deletions

View File

@ -1,78 +0,0 @@
#include "common.h"
#include "Vector.h"
void CVector::Normalise()
{
float sq = MagnitudeSqr();
if(sq > 0.0f){
float invsqrt = 1.0f/sqrt(sq); // CMaths::RecipSqrt
x *= invsqrt;
y *= invsqrt;
z *= invsqrt;
}else
x = 1.0f;
}
// operator +
CVector operator + (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x + refRight.x, refLeft.y + refRight.y, refLeft.z + refRight.z);
}
CVector operator + (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x + fRight, refLeft.y + fRight, refLeft.z + fRight);
}
CVector operator + (float fLeft, CVector const &refRight)
{
return CVector(fLeft + refRight.x, fLeft + refRight.y, fLeft + refRight.z);
}
// operator -
CVector operator - (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x - refRight.x, refLeft.y - refRight.y, refLeft.z - refRight.z);
}
CVector operator - (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x - fRight, refLeft.y - fRight, refLeft.z - fRight);
}
CVector operator - (float fLeft, CVector const &refRight)
{
return CVector(fLeft - refRight.x, fLeft - refRight.y, fLeft - refRight.z);
}
// operator *
CVector operator * (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x * refRight.x, refLeft.y * refRight.y, refLeft.z * refRight.z);
}
CVector operator * (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x * fRight, refLeft.y * fRight, refLeft.z * fRight);
}
CVector operator * (float fLeft, CVector const &refRight)
{
return CVector(fLeft * refRight.x, fLeft * refRight.y, fLeft * refRight.z);
}
// operator /
CVector operator / (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x / refRight.x, refLeft.y / refRight.y, refLeft.z / refRight.z);
}
CVector operator / (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x / fRight, refLeft.y / fRight, refLeft.z / fRight);
}
CVector operator / (float fLeft, CVector const &refRight)
{
return CVector(fLeft / refRight.x, fLeft / refRight.y, fLeft / refRight.z);
}

View File

@ -6,128 +6,71 @@ public:
float x, y, z;
CVector(void) {}
CVector(float x, float y, float z) : x(x), y(y), z(z) {}
// 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) {}
CVector(const RwV3d &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;
}
operator RwV3d &(void)
{
return *((RwV3d *)this);
operator RwV3d &(void) {
return *((RwV3d*)this);
}
#endif
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); }
void Normalise(void);
void Normalise(void) {
float sq = MagnitudeSqr();
if(sq > 0.0f){
float invsqrt = 1.0f/sqrt(sq); // CMaths::RecipSqrt
x *= invsqrt;
y *= invsqrt;
z *= invsqrt;
}else
x = 1.0f;
}
inline const CVector &operator+=(CVector const &right) {
x += right.x;
y += right.y;
z += right.z;
return *this;
}
// operator =
inline CVector const& operator = (CVector const &refRight)
{
x = refRight.x;
y = refRight.y;
z = refRight.z;
inline const CVector &operator-=(CVector const &right) {
x -= right.x;
y -= right.y;
z -= right.z;
return *this;
}
inline CVector const& operator = (float fRight)
{
x = fRight;
y = fRight;
z = fRight;
inline const CVector &operator*=(float right) {
x *= right;
y *= right;
z *= right;
return *this;
}
// operator +=
inline CVector const& operator += (CVector const &refRight)
{
x += refRight.x;
y += refRight.y;
z += refRight.z;
inline const CVector &operator/=(float right) {
x /= right;
y /= right;
z /= right;
return *this;
}
inline CVector const& operator += (float fRight)
{
x += fRight;
y += fRight;
z += fRight;
return *this;
inline CVector operator-() const {
return CVector(-x, -y, -z);
}
// 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;
}
// 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;
}
// 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;
}
inline CVector operator - () const
{
return CVector(-x, -y, -z);
}
bool IsZero(void) { return x == 0.0f && y == 0.0f && z == 0.0f; }
};
//extern CVector operator*(CMatrix const& matrix, CVector const& vector);
inline float
DotProduct(const CVector &v1, const CVector &v2)
{
@ -143,22 +86,22 @@ CrossProduct(const CVector &v1, const CVector &v2)
v1.x*v2.y - v1.y*v2.x);
}
// 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);
inline CVector operator+(const CVector &left, const CVector &right)
{
return CVector(left.x + right.x, left.y + right.y, left.z + right.z);
}
// 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);
inline CVector operator-(const CVector &left, const CVector &right)
{
return CVector(left.x - right.x, left.y - right.y, left.z - right.z);
}
inline CVector operator*(const CVector &left, float right)
{
return CVector(left.x * right, left.y * right, left.z * right);
}
inline CVector operator/(const CVector &left, float right)
{
return CVector(left.x / right, left.y / right, left.z / right);
}