From fee209b6769ee6b207e9101c4f15e16c0a67ad09 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 24 Dec 2012 21:33:18 +0000 Subject: Improved off-screen HUD target indicators. --- src/math/matrix4f.cc | 3 +-- src/math/matrix4f.h | 2 -- src/math/vector2f.cc | 24 ++++++++++++++++++++++++ src/math/vector2f.h | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) (limited to 'src/math') diff --git a/src/math/matrix4f.cc b/src/math/matrix4f.cc index b7953e9..caccae6 100644 --- a/src/math/matrix4f.cc +++ b/src/math/matrix4f.cc @@ -4,8 +4,7 @@ the terms of the GNU General Public License version 2 */ -#include - +#include #include #include "math/matrix4f.h" diff --git a/src/math/matrix4f.h b/src/math/matrix4f.h index 4148870..5442cb9 100644 --- a/src/math/matrix4f.h +++ b/src/math/matrix4f.h @@ -7,8 +7,6 @@ #ifndef __INCLUDED_MATH_MATRIX4F_H__ #define __INCLUDED_MATH_MATRIX4F_H__ -#include - #include "math/axis.h" namespace math diff --git a/src/math/vector2f.cc b/src/math/vector2f.cc index 878304f..bff60c9 100644 --- a/src/math/vector2f.cc +++ b/src/math/vector2f.cc @@ -63,6 +63,25 @@ Vector2f &Vector2f::operator-=(const Vector2f &other) return (*this); } +Vector2f & Vector2f::operator*=(const float scalar) +{ + coord[0] *= scalar; + coord[1] *= scalar; + return (*this); +} + +Vector2f & Vector2f::operator/=(const float scalar) +{ + coord[0] /= scalar; + coord[1] /= scalar; + return (*this); +} + +float Vector2f::length() const +{ + return (sqrtf((coord[0] * coord[0]) + (coord[1] * coord[1]))); +} + float distance(const Vector2f& first, const Vector2f& second) { float r = 0; @@ -80,4 +99,9 @@ float distancesquared(const Vector2f& first, const Vector2f& second) return (r); } +Vector2f operator*(float scalar, const Vector2f &vector) +{ + return vector * scalar; +} + } diff --git a/src/math/vector2f.h b/src/math/vector2f.h index 1a5f4de..7641cbc 100644 --- a/src/math/vector2f.h +++ b/src/math/vector2f.h @@ -43,6 +43,18 @@ public: /// vector sum Vector2f & operator+=(const Vector2f &other); + + /** + * @brief scalar multiplication assignment + * @param scalar multiplication factor + * */ + Vector2f& operator*=(const float scalar); + + /** + * @brief scalar division assignment + * @param scalar divider + * */ + Vector2f& operator/=(const float scalar); /// vector subtraction inline Vector2f operator+(const Vector2f &other) const { @@ -97,6 +109,10 @@ public: inline float y() const { return coord[1]; } + + /// cartesian length + float length() const; + /// mutable reference to the x coordinate inline float & get_x() { @@ -131,6 +147,9 @@ float distance(const Vector2f& first, const Vector2f& second); /// distance between two vectors squared float distancesquared(const Vector2f& first, const Vector2f& second); +/// scalar * Vector2f operators +Vector2f operator*(float scalar, const Vector2f & vector); + } #endif // __INCLUDED_MATH_VECTOR2F_H__ -- cgit v1.2.3