From 676ed6c9d818d3bdc68d9f18d92afe3a84f53081 Mon Sep 17 00:00:00 2001 From: Gawaboumga Date: Sat, 14 Jun 2014 22:10:37 +0200 Subject: [PATCH 1/2] Correction of mathematical functions. BoundingVolume: Add of constructor and setter OrientedBox. Extend is now up to date. Box: Use of . Return this Frustrum: Use of Matrix: Use of OrientedBox: m_corners is up to date Rect: Add of operators /= and /. Return this Sphere: Add of Intersect and Contains with box. Little corrections. Vector2: Return TaskSchedulerImpl: Add of include header cstdlib to compile because of std::div HardwareInfo/main: use of accentAigu Former-commit-id: a5a7f8e8c45448e5683eb13bff453d6f67478d03 --- examples/HardwareInfo/main.cpp | 10 +++--- include/Nazara/Math/BoundingVolume.hpp | 2 ++ include/Nazara/Math/BoundingVolume.inl | 24 ++++++++++--- include/Nazara/Math/Box.inl | 20 ++++++----- include/Nazara/Math/Frustum.inl | 6 ++-- include/Nazara/Math/Matrix4.inl | 14 ++++---- include/Nazara/Math/OrientedBox.inl | 15 ++++++-- include/Nazara/Math/Rect.hpp | 4 +++ include/Nazara/Math/Rect.inl | 36 +++++++++++++++++-- include/Nazara/Math/Sphere.hpp | 8 +++-- include/Nazara/Math/Sphere.inl | 39 ++++++++++++++++----- include/Nazara/Math/Vector2.inl | 2 +- src/Nazara/Core/Win32/TaskSchedulerImpl.cpp | 5 +-- 13 files changed, 141 insertions(+), 44 deletions(-) diff --git a/examples/HardwareInfo/main.cpp b/examples/HardwareInfo/main.cpp index f929501cb..07beced54 100644 --- a/examples/HardwareInfo/main.cpp +++ b/examples/HardwareInfo/main.cpp @@ -24,6 +24,9 @@ int main() // On va afficher le tout via un ostringstream, pour écrire dans la console et aussi dans un fichier std::ostringstream oss; + + char accentAigu = static_cast(130); // C'est crade, mais ça marche chez 95% des Windowsiens + oss << "--Processeur--" << std::endl; // Plutôt que d'initialiser le Renderer de Nazara, nous initialisons les deux classes utilisées ici // Elles sont compatibles avec NzInitialiser et seront donc libérées automatiquement @@ -41,7 +44,7 @@ int main() oss << std::endl; // Ensuite, Nazara récupère les capacités du processeur, dont des jeux d'extensions supplémentaires - oss << "Report des capacites: " << std::endl; + oss << "Report des capacit" << accentAigu << "s: " << std::endl; printCap(oss, "-64bits", NzHardwareInfo::HasCapability(nzProcessorCap_x64)); printCap(oss, "-AVX", NzHardwareInfo::HasCapability(nzProcessorCap_AVX)); printCap(oss, "-FMA3", NzHardwareInfo::HasCapability(nzProcessorCap_FMA3)); @@ -78,7 +81,7 @@ int main() oss << std::endl; // Ainsi qu'un report des capacités de la carte graphique (avec le driver actuel) - oss << "Report des capacites: " << std::endl; + oss << "Report des capacit" << accentAigu << "s: " << std::endl; printCap(oss, "-Calculs 64bits", NzOpenGL::IsSupported(nzOpenGLExtension_FP64)); printCap(oss, "-Compression de textures (s3tc)", NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc)); printCap(oss, "-Filtrage anisotrope", NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)); @@ -105,8 +108,7 @@ int main() reportFile.Write(oss.str()); // Conversion implicite en NzString reportFile.Close(); - char accent = (char) 130; // C'est crade, mais ça marche chez 95% des Windowsiens - std::cout << "Un fichier (RapportHardwareInfo.txt) contenant le rapport a " << accent << 't' << accent << " cr" << accent << accent << std::endl; + std::cout << "Un fichier (RapportHardwareInfo.txt) contenant le rapport a " << accentAigu << 't' << accentAigu << " cr" << accentAigu << accentAigu << std::endl; } else std::cout << "Impossible de sauvegarder le rapport" << std::endl; diff --git a/include/Nazara/Math/BoundingVolume.hpp b/include/Nazara/Math/BoundingVolume.hpp index 40d32f873..999bfdd6a 100644 --- a/include/Nazara/Math/BoundingVolume.hpp +++ b/include/Nazara/Math/BoundingVolume.hpp @@ -20,6 +20,7 @@ class NzBoundingVolume NzBoundingVolume(nzExtend Extend); NzBoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth); NzBoundingVolume(const NzBox& box); + NzBoundingVolume(const NzOrientedBox& orientedBox); NzBoundingVolume(const NzVector3& vec1, const NzVector3& vec2); template explicit NzBoundingVolume(const NzBoundingVolume& volume); NzBoundingVolume(const NzBoundingVolume& volume) = default; @@ -36,6 +37,7 @@ class NzBoundingVolume NzBoundingVolume& Set(T X, T Y, T Z, T Width, T Height, T Depth); NzBoundingVolume& Set(const NzBoundingVolume& volume); NzBoundingVolume& Set(const NzBox& box); + NzBoundingVolume& Set(const NzOrientedBox& orientedBox); NzBoundingVolume& Set(const NzVector3& vec1, const NzVector3& vec2); template NzBoundingVolume& Set(const NzBoundingVolume& volume); diff --git a/include/Nazara/Math/BoundingVolume.inl b/include/Nazara/Math/BoundingVolume.inl index a6a58c381..ed84258a1 100644 --- a/include/Nazara/Math/BoundingVolume.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -1,4 +1,4 @@ -// Copyright (C) 2014 Jérôme Leclercq +// Copyright (C) 2014 Jérôme Leclercq // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -35,6 +35,12 @@ NzBoundingVolume::NzBoundingVolume(const NzBox& box) Set(box); } +template +NzBoundingVolume::NzBoundingVolume(const NzOrientedBox& orientedBox) +{ + Set(orientedBox); +} + template NzBoundingVolume::NzBoundingVolume(const NzVector3& vec1, const NzVector3& vec2) { @@ -103,6 +109,7 @@ template NzBoundingVolume& NzBoundingVolume::Set(const NzBoundingVolume& volume) { obb.Set(volume.obb); // Seul l'OBB est importante pour la suite + extend = volume.extend; return *this; } @@ -116,6 +123,15 @@ NzBoundingVolume& NzBoundingVolume::Set(const NzBox& box) return *this; } +template +NzBoundingVolume& NzBoundingVolume::Set(const NzOrientedBox& orientedBox) +{ + obb.Set(orientedBox); + extend = nzExtend_Finite; + + return *this; +} + template NzBoundingVolume& NzBoundingVolume::Set(const NzVector3& vec1, const NzVector3& vec2) { @@ -209,17 +225,17 @@ template NzBoundingVolume NzBoundingVolume::Lerp(const NzBoundingVolume& from, const NzBoundingVolume& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < 0.f || interpolation > 1.f) + if (interpolation < F(0.0) || interpolation > F(1.0)) { NazaraError("Interpolation must be in range [0..1] (Got " + NzString::Number(interpolation) + ')'); return Null(); } #endif - if (NzNumberEquals(interpolation, 0.f)) + if (NzNumberEquals(interpolation, F(0.0))) return from; - if (NzNumberEquals(interpolation, 1.f)) + if (NzNumberEquals(interpolation, F(1.0))) return to; switch (to.extend) diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index 098e34e6d..989e7108e 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -122,32 +122,32 @@ NzVector3 NzBox::GetCorner(nzCorner corner) const switch (corner) { case nzCorner_FarLeftBottom: - return NzVector3f(x, y, z); + return NzVector3(x, y, z); case nzCorner_FarLeftTop: - return NzVector3f(x, y + height, z); + return NzVector3(x, y + height, z); case nzCorner_FarRightBottom: - return NzVector3f(x + width, y, z); + return NzVector3(x + width, y, z); case nzCorner_FarRightTop: - return NzVector3f(x + width, y + height, z); + return NzVector3(x + width, y + height, z); case nzCorner_NearLeftBottom: - return NzVector3f(x, y, z + depth); + return NzVector3(x, y, z + depth); case nzCorner_NearLeftTop: - return NzVector3f(x, y + height, z + depth); + return NzVector3(x, y + height, z + depth); case nzCorner_NearRightBottom: - return NzVector3f(x + width, y, z + depth); + return NzVector3(x + width, y, z + depth); case nzCorner_NearRightTop: - return NzVector3f(x + width, y + height, z + depth); + return NzVector3(x + width, y + height, z + depth); } NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')'); - return NzVector3f(); + return NzVector3(); } template @@ -465,6 +465,7 @@ NzBox& NzBox::operator*=(T scalar) width *= scalar; height *= scalar; depth *= scalar; + return *this; } template @@ -473,6 +474,7 @@ NzBox& NzBox::operator*=(const NzVector3& vec) width *= vec.x; height *= vec.y; depth *= vec.z; + return *this; } template diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index a1424a33f..300031d88 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -262,10 +262,10 @@ NzFrustum& NzFrustum::Extract(const NzMatrix4& clipMatrix) // Une fois les plans extraits, il faut extraire les points du frustum // Je me base sur cette page: http://www.gamedev.net/topic/393309-calculating-the-view-frustums-vertices/ - NzMatrix4f invClipMatrix; + NzMatrix4 invClipMatrix; if (clipMatrix.GetInverse(&invClipMatrix)) { - NzVector4f corner; + NzVector4 corner; // FarLeftBottom corner.Set(F(-1.0), F(-1.0), F(1.0)); @@ -332,7 +332,7 @@ NzFrustum& NzFrustum::Extract(const NzMatrix4& clipMatrix) template NzFrustum& NzFrustum::Extract(const NzMatrix4& view, const NzMatrix4& projection) { - NzMatrix4f clipMatrix(view); + NzMatrix4 clipMatrix(view); clipMatrix *= projection; return Extract(clipMatrix); diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index f577114ad..173653ebb 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -1,4 +1,4 @@ -// Copyright (C) 2014 Jérôme Leclercq +// Copyright (C) 2014 Jérôme Leclercq // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -46,7 +46,7 @@ NzMatrix4::NzMatrix4(const NzMatrix4& matrix) template NzMatrix4& NzMatrix4::ApplyRotation(const NzQuaternion& rotation) { - return Concatenate(NzMatrix4f::Rotate(rotation)); + return Concatenate(NzMatrix4::Rotate(rotation)); } template @@ -404,7 +404,7 @@ NzQuaternion NzMatrix4::GetRotation() const T trace = m11 + m22 + m33; if (trace > F(0.0)) { - float s = F(0.5)/std::sqrt(trace + F(1.0)); + T s = F(0.5)/std::sqrt(trace + F(1.0)); quat.w = F(0.25) / s; quat.x = (m23 - m32) * s; quat.y = (m31 - m13) * s; @@ -414,7 +414,7 @@ NzQuaternion NzMatrix4::GetRotation() const { if (m11 > m22 && m11 > m33) { - float s = F(2.0) * std::sqrt(F(1.0) + m11 - m22 - m33); + T s = F(2.0) * std::sqrt(F(1.0) + m11 - m22 - m33); quat.w = (m23 - m32) / s; quat.x = F(0.25) * s; @@ -423,7 +423,7 @@ NzQuaternion NzMatrix4::GetRotation() const } else if (m22 > m33) { - float s = F(2.0) * std::sqrt(F(1.0) + m22 - m11 - m33); + T s = F(2.0) * std::sqrt(F(1.0) + m22 - m11 - m33); quat.w = (m31 - m13) / s; quat.x = (m21 + m12) / s; @@ -432,7 +432,7 @@ NzQuaternion NzMatrix4::GetRotation() const } else { - float s = F(2.0) * std::sqrt(F(1.0) + m33 - m11 - m22); + T s = F(2.0) * std::sqrt(F(1.0) + m33 - m11 - m22); quat.w = (m12 - m21) / s; quat.x = (m31 + m13) / s; @@ -658,7 +658,7 @@ template NzMatrix4& NzMatrix4::MakeViewMatrix(const NzVector3& translation, const NzQuaternion& rotation) { // Une matrice de vue doit appliquer une transformation opposée à la matrice "monde" - NzQuaternionf invRot = rotation.GetConjugate(); // Inverse de la rotation + NzQuaternion invRot = rotation.GetConjugate(); // Inverse de la rotation return MakeTransform(-(invRot*translation), invRot); } diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index fad8abbf9..fcc91e4d1 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -60,7 +60,8 @@ template NzOrientedBox& NzOrientedBox::MakeZero() { localBox.MakeZero(); - + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + m_corners[i].Set(NzVector3::Zero()); return *this; } @@ -69,6 +70,8 @@ NzOrientedBox& NzOrientedBox::Set(T X, T Y, T Z, T Width, T Height, T Dept { localBox.Set(X, Y, Z, Width, Height, Depth); + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } @@ -77,6 +80,8 @@ NzOrientedBox& NzOrientedBox::Set(const NzBox& box) { localBox.Set(box); + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } @@ -93,6 +98,8 @@ NzOrientedBox& NzOrientedBox::Set(const NzVector3& vec1, const NzVector { localBox.Set(vec1, vec2); + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } @@ -127,7 +134,7 @@ template void NzOrientedBox::Update(const NzMatrix4& transformMatrix) { for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast(i))); + m_corners[i] = transformMatrix.Transform(m_corners[i]); } template @@ -182,6 +189,8 @@ NzOrientedBox NzOrientedBox::operator*(T scalar) const NzOrientedBox box(*this); box *= scalar; + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + box.m_corners[i].Set(box.GetCorner(static_cast(i))); return box; } @@ -190,6 +199,8 @@ NzOrientedBox& NzOrientedBox::operator*=(T scalar) { localBox *= scalar; + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index fdaf7a826..df7611b13 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -63,9 +63,13 @@ class NzRect NzRect operator*(T scalar) const; NzRect operator*(const NzVector2& vec) const; + NzRect operator/(T scalar) const; + NzRect operator/(const NzVector2& vec) const; NzRect& operator*=(T scalar); NzRect& operator*=(const NzVector2& vec); + NzRect& operator/=(T scalar); + NzRect& operator/=(const NzVector2& vec); bool operator==(const NzRect& rect) const; bool operator!=(const NzRect& rect) const; diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 7048666da..b2fd3a3e4 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -1,4 +1,4 @@ -// Copyright (C) 2014 Jérôme Leclercq +// Copyright (C) 2014 Jérôme Leclercq // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -106,7 +106,7 @@ NzRect& NzRect::ExtendTo(const NzRect& rect) template NzVector2 NzRect::GetCenter() const { - return GetPosition() + F(0.5)*GetLengths(); + return GetPosition() + GetLengths() / F(2.0); } template @@ -336,11 +336,24 @@ NzRect NzRect::operator*(const NzVector2& vec) const return NzRect(x, y, width*vec.x, height*vec.y); } +template +NzRect NzRect::operator/(T scalar) const +{ + return NzRect(x, y, width/scalar, height/scalar); +} + +template +NzRect NzRect::operator/(const NzVector2& vec) const +{ + return NzRect(x, y, width/vec.x, height/vec.y); +} + template NzRect& NzRect::operator*=(T scalar) { width *= scalar; height *= scalar; + return *this; } template @@ -348,6 +361,25 @@ NzRect& NzRect::operator*=(const NzVector2& vec) { width *= vec.x; height *= vec.y; + return *this; +} + +template +NzRect& NzRect::operator/=(T scalar) +{ + width /= scalar; + height /= scalar; + + return *this; +} + +template +NzRect& NzRect::operator/=(const NzVector2& vec) +{ + width /= vec.x; + height /= vec.y; + + return *this; } template diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index 611dc25c2..975893076 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -8,8 +8,12 @@ #define NAZARA_SPHERE_HPP #include +#include #include +template +class NzBox; + template class NzSphere { @@ -24,7 +28,7 @@ class NzSphere ~NzSphere() = default; bool Contains(T X, T Y, T Z) const; - //bool Contains(const NzBox& box) const; + bool Contains(const NzBox& box) const; bool Contains(const NzVector3& point) const; T Distance(T X, T Y, T Z) const; @@ -37,7 +41,7 @@ class NzSphere NzVector3 GetPosition() const; NzVector3 GetPositiveVertex(const NzVector3& normal) const; - //bool Intersect(const NzBox& box) const; + bool Intersect(const NzBox& box) const; bool Intersect(const NzSphere& sphere) const; bool IsValid() const; diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 2e360fef2..2f74945dc 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -29,7 +29,7 @@ NzSphere::NzSphere(const NzVector3& center, T Radius) } template -NzSphere::NzSphere(const T sphere[6]) +NzSphere::NzSphere(const T sphere[4]) { Set(sphere); } @@ -46,12 +46,18 @@ bool NzSphere::Contains(T X, T Y, T Z) const { return SquaredDistance(X, Y, Z) <= radius*radius; } -/* + template bool NzSphere::Contains(const NzBox& box) const { + if (box.GetMinimum().SquaredDistance(GetPosition()) <= radius * radius) + { + if (box.GetMaximum().SquaredDistance(GetPosition()) <= radius * radius) + return true; + } + + return false; } -*/ template bool NzSphere::Contains(const NzVector3& point) const { @@ -85,7 +91,7 @@ NzSphere& NzSphere::ExtendTo(T X, T Y, T Z) template NzSphere& NzSphere::ExtendTo(const NzVector3& point) { - return ExtendTo(point); + return ExtendTo(point.x, point.y, point.z); } template @@ -111,18 +117,35 @@ NzVector3 NzSphere::GetPositiveVertex(const NzVector3& normal) const return pos; } -/* template bool NzSphere::Intersect(const NzBox& box) const { + // Arvo's algorithm. + T dmin = T(0); + if (x < box.x) + dmin += (x - box.x) * (x - box.x); + else if (x > box.x + box.width) + dmin += (x - (box.x + box.width)) * (x - (box.x + box.width)); + if (y < box.y) + dmin += (y - box.y) * (y - box.y); + else if (x > box.x + box.width) + dmin += (y - (box.y + box.height)) * (y - (box.y + box.height)); + + if (z < box.z) + dmin += (z - box.z) * (z - box.z); + else if (x > box.x + box.width) + dmin += (z - (box.z + box.depth)) * (z - (box.z + box.depth)); + + if (dmin <= radius * radius) + return true; + return false; } -*/ template bool NzSphere::Intersect(const NzSphere& sphere) const { - return SquaredDistance(sphere.x, sphere.y, sphere.z) - radius*radius <= sphere.radius*sphere.radius; + return std::abs(SquaredDistance(sphere.x, sphere.y, sphere.z) - radius*radius) <= sphere.radius*sphere.radius; } template @@ -210,7 +233,7 @@ template T NzSphere::SquaredDistance(T X, T Y, T Z) const { NzVector3 distance(X-x, Y-y, Z-z); - return distance.SquaredLength(); + return distance.GetSquaredLength(); } template diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index e415125b8..5da704243 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -102,7 +102,7 @@ T NzVector2::GetSquaredLength() const template NzVector2& NzVector2::MakeUnitX() { - Set(F(1.0), F(0.0)); + return Set(F(1.0), F(0.0)); } template diff --git a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp index fc35f833c..0dccbff11 100644 --- a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp +++ b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp @@ -4,9 +4,10 @@ #include #include -#include -#include #include +#include +#include +#include bool NzTaskSchedulerImpl::Initialize(unsigned int workerCount) { From eceabcd241500d4bb35f68ea7be8a4c9631f1024 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 15 Jun 2014 01:55:07 +0200 Subject: [PATCH 2/2] Fixed some of the pull request code in order to merge it Former-commit-id: 76d71f15b335535e7dfcaf986440a00e85e45c1b --- examples/HardwareInfo/main.cpp | 8 ++- include/Nazara/Math/Box.inl | 8 +-- include/Nazara/Math/Frustum.inl | 4 +- include/Nazara/Math/Matrix4.inl | 4 +- include/Nazara/Math/OrientedBox.inl | 17 ++----- include/Nazara/Math/Rect.hpp | 2 +- include/Nazara/Math/Rect.inl | 2 + include/Nazara/Math/Sphere.hpp | 1 - include/Nazara/Math/Sphere.inl | 54 +++++++++++++-------- src/Nazara/Core/Win32/TaskSchedulerImpl.cpp | 4 +- 10 files changed, 56 insertions(+), 48 deletions(-) diff --git a/examples/HardwareInfo/main.cpp b/examples/HardwareInfo/main.cpp index 07beced54..d1a12dade 100644 --- a/examples/HardwareInfo/main.cpp +++ b/examples/HardwareInfo/main.cpp @@ -24,9 +24,6 @@ int main() // On va afficher le tout via un ostringstream, pour écrire dans la console et aussi dans un fichier std::ostringstream oss; - - char accentAigu = static_cast(130); // C'est crade, mais ça marche chez 95% des Windowsiens - oss << "--Processeur--" << std::endl; // Plutôt que d'initialiser le Renderer de Nazara, nous initialisons les deux classes utilisées ici // Elles sont compatibles avec NzInitialiser et seront donc libérées automatiquement @@ -44,7 +41,7 @@ int main() oss << std::endl; // Ensuite, Nazara récupère les capacités du processeur, dont des jeux d'extensions supplémentaires - oss << "Report des capacit" << accentAigu << "s: " << std::endl; + oss << "Rapport des capacites: " << std::endl;// Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça) printCap(oss, "-64bits", NzHardwareInfo::HasCapability(nzProcessorCap_x64)); printCap(oss, "-AVX", NzHardwareInfo::HasCapability(nzProcessorCap_AVX)); printCap(oss, "-FMA3", NzHardwareInfo::HasCapability(nzProcessorCap_FMA3)); @@ -81,7 +78,7 @@ int main() oss << std::endl; // Ainsi qu'un report des capacités de la carte graphique (avec le driver actuel) - oss << "Report des capacit" << accentAigu << "s: " << std::endl; + oss << "Rapport des capacites: " << std::endl; // Pas d'accent car écriture dans un fichier (et on ne va pas s'embêter avec ça) printCap(oss, "-Calculs 64bits", NzOpenGL::IsSupported(nzOpenGLExtension_FP64)); printCap(oss, "-Compression de textures (s3tc)", NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc)); printCap(oss, "-Filtrage anisotrope", NzOpenGL::IsSupported(nzOpenGLExtension_AnisotropicFilter)); @@ -108,6 +105,7 @@ int main() reportFile.Write(oss.str()); // Conversion implicite en NzString reportFile.Close(); + char accentAigu = static_cast(130); // C'est crade, mais ça marche chez 95% des Windowsiens std::cout << "Un fichier (RapportHardwareInfo.txt) contenant le rapport a " << accentAigu << 't' << accentAigu << " cr" << accentAigu << accentAigu << std::endl; } else diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index 989e7108e..e8f9b8fed 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -159,7 +159,7 @@ NzSphere NzBox::GetBoundingSphere() const template NzVector3 NzBox::GetCenter() const { - return GetPosition() + F(0.5)*GetLengths(); + return GetPosition() + GetLengths()/F(2.0); } template @@ -237,7 +237,7 @@ template T NzBox::GetSquaredRadius() const { NzVector3 size(GetLengths()); - size *= F(0.5); // La taille étant relative à la position (minimum) de la boite et non pas à son centre + size /= F(2.0); // La taille étant relative à la position (minimum) de la boite et non pas à son centre return size.GetSquaredLength(); } @@ -394,7 +394,7 @@ template NzBox& NzBox::Transform(const NzMatrix4& matrix, bool applyTranslation) { NzVector3 center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation - NzVector3 halfSize = GetLengths() * F(0.5); + NzVector3 halfSize = GetLengths()/F(2.0); halfSize.Set(std::fabs(matrix(0,0))*halfSize.x + std::fabs(matrix(1,0))*halfSize.y + std::fabs(matrix(2,0))*halfSize.z, std::fabs(matrix(0,1))*halfSize.x + std::fabs(matrix(1,1))*halfSize.y + std::fabs(matrix(2,1))*halfSize.z, @@ -465,6 +465,7 @@ NzBox& NzBox::operator*=(T scalar) width *= scalar; height *= scalar; depth *= scalar; + return *this; } @@ -474,6 +475,7 @@ NzBox& NzBox::operator*=(const NzVector3& vec) width *= vec.x; height *= vec.y; depth *= vec.z; + return *this; } diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index 300031d88..8541a34f1 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -24,9 +24,9 @@ template NzFrustum& NzFrustum::Build(T angle, T ratio, T zNear, T zFar, const NzVector3& eye, const NzVector3& target, const NzVector3& up) { #if NAZARA_MATH_ANGLE_RADIAN - angle *= F(0.5); + angle /= F(2.0); #else - angle = NzDegreeToRadian(angle * F(0.5)); + angle = NzDegreeToRadian(angle/F(2.0)); #endif T tangent = std::tan(angle); diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 173653ebb..2531b51dd 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -573,9 +573,9 @@ NzMatrix4& NzMatrix4::MakePerspective(T angle, T ratio, T zNear, T zFar) { // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204945(v=vs.85).aspx #if NAZARA_MATH_ANGLE_RADIAN - angle *= F(0.5); + angle /= F(2.0); #else - angle = NzDegreeToRadian(angle * F(0.5)); + angle = NzDegreeToRadian(angle/F(2.0)); #endif T yScale = F(1.0) / std::tan(angle); diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index fcc91e4d1..33a131c72 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -7,6 +7,8 @@ #include #include +///DOC: Pour que les coins soient valides, la méthode Update doit être appelée + #define F(a) static_cast(a) template @@ -60,8 +62,7 @@ template NzOrientedBox& NzOrientedBox::MakeZero() { localBox.MakeZero(); - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i].Set(NzVector3::Zero()); + return *this; } @@ -70,8 +71,6 @@ NzOrientedBox& NzOrientedBox::Set(T X, T Y, T Z, T Width, T Height, T Dept { localBox.Set(X, Y, Z, Width, Height, Depth); - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } @@ -80,8 +79,6 @@ NzOrientedBox& NzOrientedBox::Set(const NzBox& box) { localBox.Set(box); - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } @@ -98,8 +95,6 @@ NzOrientedBox& NzOrientedBox::Set(const NzVector3& vec1, const NzVector { localBox.Set(vec1, vec2); - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } @@ -134,7 +129,7 @@ template void NzOrientedBox::Update(const NzMatrix4& transformMatrix) { for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i] = transformMatrix.Transform(m_corners[i]); + m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast(i))); } template @@ -189,8 +184,6 @@ NzOrientedBox NzOrientedBox::operator*(T scalar) const NzOrientedBox box(*this); box *= scalar; - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - box.m_corners[i].Set(box.GetCorner(static_cast(i))); return box; } @@ -199,8 +192,6 @@ NzOrientedBox& NzOrientedBox::operator*=(T scalar) { localBox *= scalar; - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i].Set(localBox.GetCorner(static_cast(i))); return *this; } diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index df7611b13..a133b7ed6 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -68,7 +68,7 @@ class NzRect NzRect& operator*=(T scalar); NzRect& operator*=(const NzVector2& vec); - NzRect& operator/=(T scalar); + NzRect& operator/=(T scalar); NzRect& operator/=(const NzVector2& vec); bool operator==(const NzRect& rect) const; diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index b2fd3a3e4..ab35b30c5 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -353,6 +353,7 @@ NzRect& NzRect::operator*=(T scalar) { width *= scalar; height *= scalar; + return *this; } @@ -361,6 +362,7 @@ NzRect& NzRect::operator*=(const NzVector2& vec) { width *= vec.x; height *= vec.y; + return *this; } diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index 975893076..64378a949 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -8,7 +8,6 @@ #define NAZARA_SPHERE_HPP #include -#include #include template diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 2f74945dc..9c56fac16 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -81,7 +82,6 @@ template NzSphere& NzSphere::ExtendTo(T X, T Y, T Z) { T distance = SquaredDistance(X, Y, Z); - if (distance > radius*radius) radius = std::sqrt(distance); @@ -120,32 +120,48 @@ NzVector3 NzSphere::GetPositiveVertex(const NzVector3& normal) const template bool NzSphere::Intersect(const NzBox& box) const { - // Arvo's algorithm. - T dmin = T(0); - if (x < box.x) - dmin += (x - box.x) * (x - box.x); - else if (x > box.x + box.width) - dmin += (x - (box.x + box.width)) * (x - (box.x + box.width)); + // Arvo's algorithm. + T squaredDistance = T(0.0); + if (x < box.x) + { + T diff = x - box.x; + squaredDistance += diff*diff; + } + else if (x > box.x + box.width) + { + T diff = x - (box.x + box.width); + squaredDistance += diff*diff; + } - if (y < box.y) - dmin += (y - box.y) * (y - box.y); - else if (x > box.x + box.width) - dmin += (y - (box.y + box.height)) * (y - (box.y + box.height)); + if (y < box.y) + { + T diff = y - box.y; + squaredDistance += diff*diff; + } + else if (y > box.y + box.height) + { + T diff = y - (box.y + box.height); + squaredDistance += diff*diff; + } - if (z < box.z) - dmin += (z - box.z) * (z - box.z); - else if (x > box.x + box.width) - dmin += (z - (box.z + box.depth)) * (z - (box.z + box.depth)); + if (z < box.z) + { + T diff = z - box.z; + squaredDistance += diff*diff; + } + else if (z > box.z + box.depth) + { + T diff = z - (box.z + box.depth); + squaredDistance += diff*diff; + } - if (dmin <= radius * radius) - return true; - return false; + return squaredDistance <= radius * radius; } template bool NzSphere::Intersect(const NzSphere& sphere) const { - return std::abs(SquaredDistance(sphere.x, sphere.y, sphere.z) - radius*radius) <= sphere.radius*sphere.radius; + return SquaredDistance(sphere.x, sphere.y, sphere.z) - radius*radius <= sphere.radius*sphere.radius; } template diff --git a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp index 0dccbff11..c55d84202 100644 --- a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp +++ b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp @@ -4,10 +4,10 @@ #include #include -#include #include -#include +#include // std::ldiv #include +#include bool NzTaskSchedulerImpl::Initialize(unsigned int workerCount) {