From 0051b76b9bbba8e9d9e1722be0f64a9370148e11 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 19 Feb 2013 01:19:31 +0100 Subject: [PATCH] Improved Vector4::Normalize Fixed length output Former-commit-id: 2ff9aeca4e125965251187a1b7e2a4c6e0c08e5a --- include/Nazara/Math/Vector4.inl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 4c65d6f60..6d95accfc 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -130,15 +130,16 @@ NzVector4& NzVector4::Minimize(const NzVector4& vec) template NzVector4& NzVector4::Normalize(T* length) { - x /= w; - y /= w; - z /= w; - - w = F(1.0); + T invLength = F(1.0)/w; + x *= invLength; // Attention, briser cette logique casserait Frustum::Extract + y *= invLength; + z *= invLength; if (length) *length = w; + w = F(1.0); + return *this; }