Fixed some of the pull request code in order to merge it

Former-commit-id: 76d71f15b335535e7dfcaf986440a00e85e45c1b
This commit is contained in:
Lynix
2014-06-15 01:55:07 +02:00
parent 62daced765
commit eceabcd241
10 changed files with 56 additions and 48 deletions

View File

@@ -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,7 @@ NzBox<T>& NzBox<T>::operator*=(T scalar)
width *= scalar;
height *= scalar;
depth *= scalar;
return *this;
}
@@ -474,6 +475,7 @@ NzBox<T>& NzBox<T>::operator*=(const NzVector3<T>& vec)
width *= vec.x;
height *= vec.y;
depth *= vec.z;
return *this;
}

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);

View File

@@ -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);

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>
@@ -60,8 +62,7 @@ template<typename T>
NzOrientedBox<T>& NzOrientedBox<T>::MakeZero()
{
localBox.MakeZero();
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i].Set(NzVector3<T>::Zero());
return *this;
}
@@ -70,8 +71,6 @@ NzOrientedBox<T>& NzOrientedBox<T>::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<nzCorner>(i)));
return *this;
}
@@ -80,8 +79,6 @@ NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzBox<T>& box)
{
localBox.Set(box);
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i].Set(localBox.GetCorner(static_cast<nzCorner>(i)));
return *this;
}
@@ -98,8 +95,6 @@ NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzVector3<T>& vec1, const NzVector
{
localBox.Set(vec1, vec2);
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i].Set(localBox.GetCorner(static_cast<nzCorner>(i)));
return *this;
}
@@ -134,7 +129,7 @@ template<typename T>
void NzOrientedBox<T>::Update(const NzMatrix4<T>& 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<nzCorner>(i)));
}
template<typename T>
@@ -189,8 +184,6 @@ NzOrientedBox<T> NzOrientedBox<T>::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<nzCorner>(i)));
return box;
}
@@ -199,8 +192,6 @@ NzOrientedBox<T>& NzOrientedBox<T>::operator*=(T scalar)
{
localBox *= scalar;
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i].Set(localBox.GetCorner(static_cast<nzCorner>(i)));
return *this;
}

View File

@@ -68,7 +68,7 @@ class NzRect
NzRect& operator*=(T scalar);
NzRect& operator*=(const NzVector2<T>& vec);
NzRect& operator/=(T scalar);
NzRect& operator/=(T scalar);
NzRect& operator/=(const NzVector2<T>& vec);
bool operator==(const NzRect& rect) const;

View File

@@ -353,6 +353,7 @@ NzRect<T>& NzRect<T>::operator*=(T scalar)
{
width *= scalar;
height *= scalar;
return *this;
}
@@ -361,6 +362,7 @@ NzRect<T>& NzRect<T>::operator*=(const NzVector2<T>& vec)
{
width *= vec.x;
height *= vec.y;
return *this;
}

View File

@@ -8,7 +8,6 @@
#define NAZARA_SPHERE_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>

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>
@@ -81,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);
@@ -120,32 +120,48 @@ NzVector3<T> NzSphere<T>::GetPositiveVertex(const NzVector3<T>& normal) const
template<typename T>
bool NzSphere<T>::Intersect(const NzBox<T>& 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<typename T>
bool NzSphere<T>::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<typename T>