summaryrefslogtreecommitdiffstats
path: root/src/math/Vector2D.h
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2019-08-10 09:44:39 +0200
committerNikolay Korolev <nickvnuk@gmail.com>2019-08-10 09:44:39 +0200
commit6a7fdadeaab25e7b17557c30cea4c8be094d9bd9 (patch)
tree76a3086f2819de9248a2a2cabf00f24eeb5e82b0 /src/math/Vector2D.h
parentMore CCarCtrl (diff)
parentfinished CPathFind (diff)
downloadre3-6a7fdadeaab25e7b17557c30cea4c8be094d9bd9.tar
re3-6a7fdadeaab25e7b17557c30cea4c8be094d9bd9.tar.gz
re3-6a7fdadeaab25e7b17557c30cea4c8be094d9bd9.tar.bz2
re3-6a7fdadeaab25e7b17557c30cea4c8be094d9bd9.tar.lz
re3-6a7fdadeaab25e7b17557c30cea4c8be094d9bd9.tar.xz
re3-6a7fdadeaab25e7b17557c30cea4c8be094d9bd9.tar.zst
re3-6a7fdadeaab25e7b17557c30cea4c8be094d9bd9.zip
Diffstat (limited to '')
-rw-r--r--src/math/Vector2D.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/math/Vector2D.h b/src/math/Vector2D.h
index 76664522..a090155c 100644
--- a/src/math/Vector2D.h
+++ b/src/math/Vector2D.h
@@ -18,7 +18,7 @@ public:
x *= invsqrt;
y *= invsqrt;
}else
- x = 0.0f;
+ x = 1.0f;
}
const CVector2D &operator+=(CVector2D const &right) {
x += right.x;
@@ -52,6 +52,9 @@ public:
CVector2D operator*(float t) const {
return CVector2D(x*t, y*t);
}
+ CVector2D operator/(float t) const {
+ return CVector2D(x/t, y/t);
+ }
};
inline float
@@ -65,3 +68,26 @@ CrossProduct2D(const CVector2D &v1, const CVector2D &v2)
{
return v1.x*v2.y - v1.y*v2.x;
}
+
+inline float
+Distance2D(const CVector2D &v, float x, float y)
+{
+ return Sqrt((v.x-x)*(v.x-x) + (v.y-y)*(v.y-y));
+}
+
+inline float
+DistanceSqr2D(const CVector2D &v, float x, float y)
+{
+ return (v.x-x)*(v.x-x) + (v.y-y)*(v.y-y);
+}
+
+inline void
+NormalizeXY(float &x, float &y)
+{
+ float l = Sqrt(x*x + y*y);
+ if(l != 0.0f){
+ x /= l;
+ y /= l;
+ }else
+ x = 1.0f;
+}