Refactored mathematics module
Added AABBs Added code examples Added experimental support for texture arrays (1D/2D) Added initialisers (new way of initialising modules) Added global headers (Plus a global header generator script) Added pattern support for directory Added support for spinlocks critical section on Windows Added NzRenderWindow::SetFramerateLimit Core project now includes Mathematics files Fixed color implementation using double Fixed declaration needing renderer include Fixed MLT not clearing nextFree(File/Line) after Free Fixed move operators not being noexcept Fixed thread-safety (Now working correctly - If I'm lucky) Moved Resource to core New interface for modules New interface for the renderer Put some global functions to anonymous namespace Removed empty modules Renamed ThreadCondition to ConditionVariable Replaced redirect to cerr log option by duplicate to cout Setting mouse position relative to a window will make this window ignore the event Shaders sending methods no longer takes the uniform variable name (it's using ID instead) Using new OpenGL 4.3 header
This commit is contained in:
@@ -6,53 +6,46 @@
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::NzVector3()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::NzVector3(T X, T Y, T Z) :
|
||||
x(X),
|
||||
y(Y),
|
||||
z(Z)
|
||||
NzVector3<T>::NzVector3(T X, T Y, T Z)
|
||||
{
|
||||
Set(X, Y, Z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::NzVector3(T scale) :
|
||||
x(scale),
|
||||
y(scale),
|
||||
z(scale)
|
||||
NzVector3<T>::NzVector3(T scale)
|
||||
{
|
||||
Set(scale);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::NzVector3(T vec[3]) :
|
||||
x(vec[0]),
|
||||
y(vec[1]),
|
||||
z(vec[2])
|
||||
NzVector3<T>::NzVector3(T vec[3])
|
||||
{
|
||||
Set(vec);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::NzVector3(const NzVector2<T>& vec, T Z) :
|
||||
x(vec.x),
|
||||
y(vec.y),
|
||||
z(Z)
|
||||
NzVector3<T>::NzVector3(const NzVector2<T>& vec, T Z)
|
||||
{
|
||||
Set(vec, Z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
NzVector3<T>::NzVector3(const NzVector3<U>& vec) :
|
||||
x(static_cast<T>(vec.x)),
|
||||
y(static_cast<T>(vec.y)),
|
||||
z(static_cast<T>(vec.z))
|
||||
NzVector3<T>::NzVector3(const NzVector3<U>& vec)
|
||||
{
|
||||
Set(vec);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -94,7 +87,7 @@ float NzVector3<T>::Distancef(const NzVector3& vec) const
|
||||
template<typename T>
|
||||
T NzVector3<T>::DotProduct(const NzVector3& vec) const
|
||||
{
|
||||
return x * vec.x + y * vec.y + z * vec.z;
|
||||
return x*vec.x + y*vec.y + z*vec.z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -132,6 +125,30 @@ void NzVector3<T>::MakeFloor(const NzVector3& vec)
|
||||
z = vec.z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::MakeUnitX()
|
||||
{
|
||||
Set(F(1.0), F(0.0), F(0.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::MakeUnitY()
|
||||
{
|
||||
Set(F(0.0), F(1.0), F(0.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::MakeUnitZ()
|
||||
{
|
||||
Set(F(0.0), F(0.0), F(1.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::MakeZero()
|
||||
{
|
||||
Set(F(0.0), F(0.0), F(0.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzVector3<T>::Length() const
|
||||
{
|
||||
@@ -147,16 +164,57 @@ float NzVector3<T>::Lengthf() const
|
||||
template<typename T>
|
||||
void NzVector3<T>::Normalize()
|
||||
{
|
||||
T length = Length();
|
||||
T squaredLength = SquaredLength();
|
||||
|
||||
if (!NzNumberEquals(length, static_cast<T>(0.0)))
|
||||
if (squaredLength-F(1.0) > std::numeric_limits<T>::epsilon())
|
||||
{
|
||||
T length = std::sqrt(squaredLength);
|
||||
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::Set(T X, T Y, T Z)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
z = Z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::Set(T scale)
|
||||
{
|
||||
x = scale;
|
||||
y = scale;
|
||||
z = scale;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::Set(T vec[3])
|
||||
{
|
||||
std::memcpy(&x, vec, 3*sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzVector3<T>::Set(const NzVector2<T>& vec, T Z)
|
||||
{
|
||||
x = vec.x;
|
||||
y = vec.y;
|
||||
z = Z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
void NzVector3<T>::Set(const NzVector3<U>& vec)
|
||||
{
|
||||
x = F(vec.x);
|
||||
y = F(vec.y);
|
||||
z = F(vec.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
|
||||
{
|
||||
@@ -166,7 +224,7 @@ T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
|
||||
template<typename T>
|
||||
T NzVector3<T>::SquaredLength() const
|
||||
{
|
||||
return x * x + y * y + z * z;
|
||||
return x*x + y*y + z*z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -177,6 +235,12 @@ NzString NzVector3<T>::ToString() const
|
||||
return ss << "Vector3(" << x << ", " << y << ", " << z <<')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::operator NzString() const
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::operator T*()
|
||||
{
|
||||
@@ -192,13 +256,15 @@ NzVector3<T>::operator const T*() const
|
||||
template<typename T>
|
||||
T& NzVector3<T>::operator[](unsigned int i)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (i >= 3)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
throw std::out_of_range(ss.ToString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
@@ -206,13 +272,15 @@ T& NzVector3<T>::operator[](unsigned int i)
|
||||
template<typename T>
|
||||
T NzVector3<T>::operator[](unsigned int i) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (i >= 3)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
throw std::out_of_range(ss.ToString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
@@ -256,13 +324,15 @@ NzVector3<T> NzVector3<T>::operator*(T scale) const
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
|
||||
{
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return NzVector3(x / vec.x, y / vec.y, z / vec.z);
|
||||
}
|
||||
@@ -270,13 +340,15 @@ NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::operator/(T scale) const
|
||||
{
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NzNumberEquals(scale, F(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return NzVector3(x / scale, y / scale, z / scale);
|
||||
}
|
||||
@@ -324,7 +396,7 @@ NzVector3<T>& NzVector3<T>::operator*=(T scale)
|
||||
template<typename T>
|
||||
NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
|
||||
{
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -342,7 +414,7 @@ NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
|
||||
template<typename T>
|
||||
NzVector3<T>& NzVector3<T>::operator/=(T scale)
|
||||
{
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
if (NzNumberEquals(scale, F(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -395,6 +467,42 @@ bool NzVector3<T>::operator>=(const NzVector3& vec) const
|
||||
return !operator<(vec);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::UnitX()
|
||||
{
|
||||
NzVector3 vector;
|
||||
vector.MakeUnitX();
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::UnitY()
|
||||
{
|
||||
NzVector3 vector;
|
||||
vector.MakeUnitY();
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::UnitZ()
|
||||
{
|
||||
NzVector3 vector;
|
||||
vector.MakeUnitZ();
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::Zero()
|
||||
{
|
||||
NzVector3 vector;
|
||||
vector.MakeZero();
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const NzVector3<T>& vec)
|
||||
{
|
||||
@@ -410,15 +518,19 @@ NzVector3<T> operator*(T scale, const NzVector3<T>& vec)
|
||||
template<typename T>
|
||||
NzVector3<T> operator/(T scale, const NzVector3<T>& vec)
|
||||
{
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return NzVector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user