diff options
author | Fire-Head <Fire-Head@users.noreply.github.com> | 2019-05-29 02:52:30 +0200 |
---|---|---|
committer | Fire-Head <Fire-Head@users.noreply.github.com> | 2019-05-29 02:52:30 +0200 |
commit | 31e7428bdf788a465c2f72f75793cac88ec5d77a (patch) | |
tree | c05bad8c041335995af7ce47c15f9f2496c03a7e /src/math/Vector.cpp | |
parent | more CVehicleModelInfo (diff) | |
download | re3-31e7428bdf788a465c2f72f75793cac88ec5d77a.tar re3-31e7428bdf788a465c2f72f75793cac88ec5d77a.tar.gz re3-31e7428bdf788a465c2f72f75793cac88ec5d77a.tar.bz2 re3-31e7428bdf788a465c2f72f75793cac88ec5d77a.tar.lz re3-31e7428bdf788a465c2f72f75793cac88ec5d77a.tar.xz re3-31e7428bdf788a465c2f72f75793cac88ec5d77a.tar.zst re3-31e7428bdf788a465c2f72f75793cac88ec5d77a.zip |
Diffstat (limited to 'src/math/Vector.cpp')
-rw-r--r-- | src/math/Vector.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/math/Vector.cpp b/src/math/Vector.cpp new file mode 100644 index 00000000..d9cc590f --- /dev/null +++ b/src/math/Vector.cpp @@ -0,0 +1,78 @@ +#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); +}
\ No newline at end of file |