From cf57dfc51afbb67bc8dd9e5394fd0af6d55fae2e Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 9 Aug 2014 08:31:25 -0700 Subject: [PATCH] I give up on Normalization Compiler was complaining about casting between Vector4 and Matrix<4,1> so I just did the division by hand. I bet operator* and operator/ are broken for Vector4s as well... --- src/basics/vector.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/basics/vector.cc b/src/basics/vector.cc index ded5a3e..3984a3c 100644 --- a/src/basics/vector.cc +++ b/src/basics/vector.cc @@ -64,7 +64,7 @@ Vector4::Z() /* - * charles::basics::Vector4::length2 -- + * charles::basics::Vector4::Length2 -- */ Double Vector4::Length2() @@ -74,6 +74,9 @@ Vector4::Length2() } +/* + * charles::basics::Vector4::Length -- + */ Double Vector4::Length() const @@ -82,6 +85,9 @@ Vector4::Length() } +/* + * charles::basics::Vector4::Dot -- + */ Double Vector4::Dot(const Vector4& rhs) const @@ -90,6 +96,9 @@ Vector4::Dot(const Vector4& rhs) } +/* + * charles::basics::Vector4::Cross -- + */ Vector4 Vector4::Cross(const Vector4& rhs) const @@ -100,10 +109,18 @@ Vector4::Cross(const Vector4& rhs) } +/* + * charles::basics::Vector4::Normalize -- + */ Vector4& Vector4::Normalize() { - return *this /= Length(); + /* XXX: Is there some way to do this with the Matrix<>::operator/? */ + const Double len = Length(); + X() = X() / len; + Y() = Y() / len; + Z() = Z() / len; + return *this; } } /* namespace basics */