Merge branch 'Gawaboumga-master'

Former-commit-id: 9a0a10f0a44bde3f10b81098f7bf08212107f964
This commit is contained in:
Lynix 2014-06-15 01:59:01 +02:00
commit 46dc4fbd67
13 changed files with 152 additions and 47 deletions

View File

@ -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<char>(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;

View File

@ -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<T>& box);
NzBoundingVolume(const NzOrientedBox<T>& orientedBox);
NzBoundingVolume(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzBoundingVolume(const NzBoundingVolume<U>& 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<T>& volume);
NzBoundingVolume& Set(const NzBox<T>& box);
NzBoundingVolume& Set(const NzOrientedBox<T>& orientedBox);
NzBoundingVolume& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzBoundingVolume& Set(const NzBoundingVolume<U>& volume);

View File

@ -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<T>::NzBoundingVolume(const NzBox<T>& box)
Set(box);
}
template<typename T>
NzBoundingVolume<T>::NzBoundingVolume(const NzOrientedBox<T>& orientedBox)
{
Set(orientedBox);
}
template<typename T>
NzBoundingVolume<T>::NzBoundingVolume(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
@ -103,6 +109,7 @@ template<typename T>
NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzBoundingVolume<T>& volume)
{
obb.Set(volume.obb); // Seul l'OBB est importante pour la suite
extend = volume.extend;
return *this;
}
@ -116,6 +123,15 @@ NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzBox<T>& box)
return *this;
}
template<typename T>
NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzOrientedBox<T>& orientedBox)
{
obb.Set(orientedBox);
extend = nzExtend_Finite;
return *this;
}
template<typename T>
NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
@ -209,17 +225,17 @@ template<typename T>
NzBoundingVolume<T> NzBoundingVolume<T>::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)

View File

@ -122,32 +122,32 @@ NzVector3<T> NzBox<T>::GetCorner(nzCorner corner) const
switch (corner)
{
case nzCorner_FarLeftBottom:
return NzVector3f(x, y, z);
return NzVector3<T>(x, y, z);
case nzCorner_FarLeftTop:
return NzVector3f(x, y + height, z);
return NzVector3<T>(x, y + height, z);
case nzCorner_FarRightBottom:
return NzVector3f(x + width, y, z);
return NzVector3<T>(x + width, y, z);
case nzCorner_FarRightTop:
return NzVector3f(x + width, y + height, z);
return NzVector3<T>(x + width, y + height, z);
case nzCorner_NearLeftBottom:
return NzVector3f(x, y, z + depth);
return NzVector3<T>(x, y, z + depth);
case nzCorner_NearLeftTop:
return NzVector3f(x, y + height, z + depth);
return NzVector3<T>(x, y + height, z + depth);
case nzCorner_NearRightBottom:
return NzVector3f(x + width, y, z + depth);
return NzVector3<T>(x + width, y, z + depth);
case nzCorner_NearRightTop:
return NzVector3f(x + width, y + height, z + depth);
return NzVector3<T>(x + width, y + height, z + depth);
}
NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')');
return NzVector3f();
return NzVector3<T>();
}
template<typename T>
@ -159,7 +159,7 @@ NzSphere<T> NzBox<T>::GetBoundingSphere() const
template<typename T>
NzVector3<T> NzBox<T>::GetCenter() const
{
return GetPosition() + F(0.5)*GetLengths();
return GetPosition() + GetLengths()/F(2.0);
}
template<typename T>
@ -237,7 +237,7 @@ template<typename T>
T NzBox<T>::GetSquaredRadius() const
{
NzVector3<T> 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<typename T>
NzBox<T>& NzBox<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslation)
{
NzVector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation
NzVector3<T> halfSize = GetLengths() * F(0.5);
NzVector3<T> 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<T>& NzBox<T>::operator*=(T scalar)
width *= scalar;
height *= scalar;
depth *= scalar;
return *this;
}
template<typename T>
@ -473,6 +475,8 @@ NzBox<T>& NzBox<T>::operator*=(const NzVector3<T>& vec)
width *= vec.x;
height *= vec.y;
depth *= vec.z;
return *this;
}
template<typename T>

View File

@ -24,9 +24,9 @@ template<typename T>
NzFrustum<T>& NzFrustum<T>::Build(T angle, T ratio, T zNear, T zFar, const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& 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<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& 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<T> invClipMatrix;
if (clipMatrix.GetInverse(&invClipMatrix))
{
NzVector4f corner;
NzVector4<T> corner;
// FarLeftBottom
corner.Set(F(-1.0), F(-1.0), F(1.0));
@ -332,7 +332,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
template<typename T>
NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& view, const NzMatrix4<T>& projection)
{
NzMatrix4f clipMatrix(view);
NzMatrix4<T> clipMatrix(view);
clipMatrix *= projection;
return Extract(clipMatrix);

View File

@ -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<T>::NzMatrix4(const NzMatrix4<U>& matrix)
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::ApplyRotation(const NzQuaternion<T>& rotation)
{
return Concatenate(NzMatrix4f::Rotate(rotation));
return Concatenate(NzMatrix4<T>::Rotate(rotation));
}
template<typename T>
@ -404,7 +404,7 @@ NzQuaternion<T> NzMatrix4<T>::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<T> NzMatrix4<T>::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<T> NzMatrix4<T>::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<T> NzMatrix4<T>::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<T>& NzMatrix4<T>::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<typename T>
NzMatrix4<T>& NzMatrix4<T>::MakeViewMatrix(const NzVector3<T>& translation, const NzQuaternion<T>& rotation)
{
// Une matrice de vue doit appliquer une transformation opposée à la matrice "monde"
NzQuaternionf invRot = rotation.GetConjugate(); // Inverse de la rotation
NzQuaternion<T> invRot = rotation.GetConjugate(); // Inverse de la rotation
return MakeTransform(-(invRot*translation), invRot);
}

View File

@ -7,6 +7,8 @@
#include <cstring>
#include <Nazara/Core/Debug.hpp>
///DOC: Pour que les coins soient valides, la méthode Update doit être appelée
#define F(a) static_cast<T>(a)
template<typename T>

View File

@ -63,9 +63,13 @@ class NzRect
NzRect operator*(T scalar) const;
NzRect operator*(const NzVector2<T>& vec) const;
NzRect operator/(T scalar) const;
NzRect operator/(const NzVector2<T>& vec) const;
NzRect& operator*=(T scalar);
NzRect& operator*=(const NzVector2<T>& vec);
NzRect& operator/=(T scalar);
NzRect& operator/=(const NzVector2<T>& vec);
bool operator==(const NzRect& rect) const;
bool operator!=(const NzRect& rect) const;

View File

@ -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<T>& NzRect<T>::ExtendTo(const NzRect& rect)
template<typename T>
NzVector2<T> NzRect<T>::GetCenter() const
{
return GetPosition() + F(0.5)*GetLengths();
return GetPosition() + GetLengths() / F(2.0);
}
template<typename T>
@ -336,11 +336,25 @@ NzRect<T> NzRect<T>::operator*(const NzVector2<T>& vec) const
return NzRect(x, y, width*vec.x, height*vec.y);
}
template<typename T>
NzRect<T> NzRect<T>::operator/(T scalar) const
{
return NzRect(x, y, width/scalar, height/scalar);
}
template<typename T>
NzRect<T> NzRect<T>::operator/(const NzVector2<T>& vec) const
{
return NzRect(x, y, width/vec.x, height/vec.y);
}
template<typename T>
NzRect<T>& NzRect<T>::operator*=(T scalar)
{
width *= scalar;
height *= scalar;
return *this;
}
template<typename T>
@ -348,6 +362,26 @@ NzRect<T>& NzRect<T>::operator*=(const NzVector2<T>& vec)
{
width *= vec.x;
height *= vec.y;
return *this;
}
template<typename T>
NzRect<T>& NzRect<T>::operator/=(T scalar)
{
width /= scalar;
height /= scalar;
return *this;
}
template<typename T>
NzRect<T>& NzRect<T>::operator/=(const NzVector2<T>& vec)
{
width /= vec.x;
height /= vec.y;
return *this;
}
template<typename T>

View File

@ -10,6 +10,9 @@
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
class NzBox;
template<typename T>
class NzSphere
{
@ -24,7 +27,7 @@ class NzSphere
~NzSphere() = default;
bool Contains(T X, T Y, T Z) const;
//bool Contains(const NzBox<T>& box) const;
bool Contains(const NzBox<T>& box) const;
bool Contains(const NzVector3<T>& point) const;
T Distance(T X, T Y, T Z) const;
@ -37,7 +40,7 @@ class NzSphere
NzVector3<T> GetPosition() const;
NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const;
//bool Intersect(const NzBox<T>& box) const;
bool Intersect(const NzBox<T>& box) const;
bool Intersect(const NzSphere& sphere) const;
bool IsValid() const;

View File

@ -4,6 +4,7 @@
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/Box.hpp>
#include <algorithm>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
@ -29,7 +30,7 @@ NzSphere<T>::NzSphere(const NzVector3<T>& center, T Radius)
}
template<typename T>
NzSphere<T>::NzSphere(const T sphere[6])
NzSphere<T>::NzSphere(const T sphere[4])
{
Set(sphere);
}
@ -46,12 +47,18 @@ bool NzSphere<T>::Contains(T X, T Y, T Z) const
{
return SquaredDistance(X, Y, Z) <= radius*radius;
}
/*
template<typename T>
bool NzSphere<T>::Contains(const NzBox<T>& box) const
{
if (box.GetMinimum().SquaredDistance(GetPosition()) <= radius * radius)
{
if (box.GetMaximum().SquaredDistance(GetPosition()) <= radius * radius)
return true;
}
return false;
}
*/
template<typename T>
bool NzSphere<T>::Contains(const NzVector3<T>& point) const
{
@ -75,7 +82,6 @@ template<typename T>
NzSphere<T>& NzSphere<T>::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<T>& NzSphere<T>::ExtendTo(T X, T Y, T Z)
template<typename T>
NzSphere<T>& NzSphere<T>::ExtendTo(const NzVector3<T>& point)
{
return ExtendTo(point);
return ExtendTo(point.x, point.y, point.z);
}
template<typename T>
@ -111,13 +117,46 @@ NzVector3<T> NzSphere<T>::GetPositiveVertex(const NzVector3<T>& normal) const
return pos;
}
/*
template<typename T>
bool NzSphere<T>::Intersect(const NzBox<T>& 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<typename T>
bool NzSphere<T>::Intersect(const NzSphere& sphere) const
@ -210,7 +249,7 @@ template<typename T>
T NzSphere<T>::SquaredDistance(T X, T Y, T Z) const
{
NzVector3<T> distance(X-x, Y-y, Z-z);
return distance.SquaredLength();
return distance.GetSquaredLength();
}
template<typename T>

View File

@ -102,7 +102,7 @@ T NzVector2<T>::GetSquaredLength() const
template<typename T>
NzVector2<T>& NzVector2<T>::MakeUnitX()
{
Set(F(1.0), F(0.0));
return Set(F(1.0), F(0.0));
}
template<typename T>

View File

@ -5,6 +5,7 @@
#include <Nazara/Core/Win32/TaskSchedulerImpl.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <cstdlib> // std::ldiv
#include <process.h>
#include <Nazara/Core/Debug.hpp>