From 2e6d8e1321c81e29a85f46c0ff3c0280e3f95b9f Mon Sep 17 00:00:00 2001 From: wwylele Date: Sun, 11 Dec 2016 23:28:55 +0200 Subject: [PATCH] vector math: add implementation of Length and Normalize --- src/common/vector_math.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/common/vector_math.h b/src/common/vector_math.h index a57d86d880..7ca8e15f56 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -186,6 +186,18 @@ Vec2 operator*(const V& f, const Vec2& vec) { typedef Vec2 Vec2f; +template <> +inline float Vec2::Length() const { + return std::sqrt(x * x + y * y); +} + +template <> +inline float Vec2::Normalize() { + float length = Length(); + *this /= length; + return length; +} + template class Vec3 { public: @@ -388,6 +400,13 @@ inline Vec3 Vec3::Normalized() const { return *this / Length(); } +template <> +inline float Vec3::Normalize() { + float length = Length(); + *this /= length; + return length; +} + typedef Vec3 Vec3f; template