From 2bba1be9383ebdb0d4e3f8a9437c009df76217f2 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 26 May 2015 23:39:01 +0200 Subject: [PATCH] Math: Add M_SQRT3 constant, fix sphere radius calculations Former-commit-id: 71ac4d3522f427fda60a0e71d76eca7558539187 --- include/Nazara/Math/Algorithm.hpp | 4 ++++ src/Nazara/Graphics/Light.cpp | 2 +- src/Nazara/Physics/Geom.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Math/Algorithm.hpp b/include/Nazara/Math/Algorithm.hpp index 44b2a3f1b..9cd10ef59 100644 --- a/include/Nazara/Math/Algorithm.hpp +++ b/include/Nazara/Math/Algorithm.hpp @@ -20,6 +20,10 @@ #define M_SQRT2 1.4142135623730950488016887 #endif +#ifndef M_SQRT3 +#define M_SQRT3 1.7320508075688772935274463 +#endif + template T NzApproach(T value, T objective, T increment); template constexpr T NzClamp(T value, T min, T max); template T NzCountBits(T value); diff --git a/src/Nazara/Graphics/Light.cpp b/src/Nazara/Graphics/Light.cpp index 150aa4c5d..ce1b5f2bb 100644 --- a/src/Nazara/Graphics/Light.cpp +++ b/src/Nazara/Graphics/Light.cpp @@ -194,7 +194,7 @@ void NzLight::MakeBoundingVolume() const case nzLightType_Point: { - NzVector3f radius(m_radius); ///FIXME: Incorrect + NzVector3f radius(m_radius * M_SQRT3); m_boundingVolume.Set(-radius, radius); break; } diff --git a/src/Nazara/Physics/Geom.cpp b/src/Nazara/Physics/Geom.cpp index 77952dfef..188df7d25 100644 --- a/src/Nazara/Physics/Geom.cpp +++ b/src/Nazara/Physics/Geom.cpp @@ -400,7 +400,7 @@ m_radius(radius) NzBoxf NzSphereGeom::ComputeAABB(const NzMatrix4f& offsetMatrix, const NzVector3f& scale) const { - NzVector3f size(m_radius * scale); + NzVector3f size(m_radius * M_SQRT3 * scale); NzVector3f position(offsetMatrix.GetTranslation()); return NzBoxf(position - size, position + size);