diff --git a/examples/HardwareInfo/main.cpp b/examples/HardwareInfo/main.cpp index f929501cb..d1a12dade 100644 --- a/examples/HardwareInfo/main.cpp +++ b/examples/HardwareInfo/main.cpp @@ -41,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 capacites: " << 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)); @@ -78,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 capacites: " << 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)); @@ -105,8 +105,8 @@ 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; + 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 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..e8f9b8fed 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 @@ -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,8 @@ NzBox& NzBox::operator*=(T scalar) width *= scalar; height *= scalar; depth *= scalar; + + return *this; } template @@ -473,6 +475,8 @@ 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..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); @@ -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..2531b51dd 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; @@ -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); @@ -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..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 diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index fdaf7a826..a133b7ed6 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..ab35b30c5 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,25 @@ 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 +362,26 @@ 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..64378a949 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -10,6 +10,9 @@ #include #include +template +class NzBox; + template class NzSphere { @@ -24,7 +27,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 +40,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..9c56fac16 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -29,7 +30,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 +47,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 { @@ -75,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); @@ -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,13 +117,46 @@ NzVector3 NzSphere::GetPositiveVertex(const NzVector3& normal) const return pos; } -/* template bool NzSphere::Intersect(const NzBox& box) const { + // 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) + { + 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) + { + 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; + } + + return squaredDistance <= radius * radius; } -*/ template bool NzSphere::Intersect(const NzSphere& sphere) const @@ -210,7 +249,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..c55d84202 100644 --- a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp +++ b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include // std::ldiv #include #include