summaryrefslogtreecommitdiffstats
path: root/src/math/Vector2D.h
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2020-09-26 12:28:33 +0200
committerNikolay Korolev <nickvnuk@gmail.com>2020-09-26 12:28:33 +0200
commiteefb0c817f1c86cb24d3a730da848e1f98277948 (patch)
treed4872bafd56e69213a6e973ac539c01942042a01 /src/math/Vector2D.h
parentMerge remote-tracking branch 'upstream/master' (diff)
parentFix MASTER build with glfw (diff)
downloadre3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.gz
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.bz2
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.lz
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.xz
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.zst
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.zip
Diffstat (limited to 'src/math/Vector2D.h')
-rw-r--r--src/math/Vector2D.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/math/Vector2D.h b/src/math/Vector2D.h
index 0885a5d2..0235dbe5 100644
--- a/src/math/Vector2D.h
+++ b/src/math/Vector2D.h
@@ -11,7 +11,13 @@ public:
float Magnitude(void) const { return Sqrt(x*x + y*y); }
float MagnitudeSqr(void) const { return x*x + y*y; }
- void Normalise(void);
+ void Normalise(void) {
+ float sq = MagnitudeSqr();
+ // assert(sq != 0.0f); // just be safe here
+ float invsqrt = RecipSqrt(sq);
+ x *= invsqrt;
+ y *= invsqrt;
+ }
void NormaliseSafe(void) {
float sq = MagnitudeSqr();
@@ -20,7 +26,7 @@ public:
x *= invsqrt;
y *= invsqrt;
}else
- y = 1.0f;
+ x = 1.0f;
}
const CVector2D &operator+=(CVector2D const &right) {