diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-11-22 14:21:18 +0000 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-02 11:24:02 +0100 |
commit | b2539e89f054b066ddbe0741d79553321d54a049 (patch) | |
tree | def32e034fbcb091721d8fccc806b858b031c058 /src/math.hpp | |
parent | d61f45073e36fb655f08dc778413cc54acef558f (diff) |
Vector element-wise multiplication.
Diffstat (limited to 'src/math.hpp')
-rw-r--r-- | src/math.hpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/math.hpp b/src/math.hpp index 2957d00..13eb36a 100644 --- a/src/math.hpp +++ b/src/math.hpp @@ -122,6 +122,24 @@ public: return v; } + friend vec_t<T, N> operator^(const vec_t<T, N> &a, const vec_t<T, N> &b) + { + vec_t<T, N> r; + + for (size_t i = 0; i < N; i++) + r[i] = a[i] * b[i]; + + return r; + } + + friend vec_t<T, N> &operator^=(vec_t<T, N> &v, const vec_t<T, N> &b) + { + for (size_t i = 0; i < N; i++) + v[i] *= b[i]; + + return v; + } + friend T operator*(const vec_t<T, N> &a, const vec_t<T, N> &b) { T r = (T)0; @@ -209,6 +227,11 @@ public: return atan2(v[1], v[0]); } + vec_t<T, N> norm(void) + { + return *this / len(); + } + // Compatibility with SFML template <typename U> |