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,37 +6,36 @@
|
||||
#include <algorithm>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::NzRect()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::NzRect(T X, T Y, T Width, T Height) :
|
||||
x(X),
|
||||
y(Y),
|
||||
width(Width),
|
||||
height(Height)
|
||||
NzRect<T>::NzRect(T X, T Y, T Width, T Height)
|
||||
{
|
||||
Set(X, Y, Width, Height);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::NzRect(T vec[4]) :
|
||||
x(vec[0]),
|
||||
y(vec[1]),
|
||||
width(vec[2]),
|
||||
height(vec[3])
|
||||
NzRect<T>::NzRect(const T vec[4])
|
||||
{
|
||||
Set(vec);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::NzRect(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
|
||||
{
|
||||
Set(vec1, vec2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
NzRect<T>::NzRect(const NzRect<U>& rect) :
|
||||
x(static_cast<T>(rect.x)),
|
||||
y(static_cast<T>(rect.y)),
|
||||
width(static_cast<T>(rect.width)),
|
||||
height(static_cast<T>(rect.height))
|
||||
NzRect<T>::NzRect(const NzRect<U>& rect)
|
||||
{
|
||||
Set(rect);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -80,18 +79,11 @@ void NzRect<T>::ExtendTo(const NzRect& rect)
|
||||
template<typename T>
|
||||
NzVector2<T> NzRect<T>::GetCenter() const
|
||||
{
|
||||
return NzVector2<T>((x+width)/2, (y+height)/2);
|
||||
return NzVector2<T>((x+width)/F(2.0), (y+height)/F(2.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::Intersect(const NzRect& rect) const
|
||||
{
|
||||
NzRect intersection; // Optimisé par le compilateur
|
||||
return Intersect(rect, intersection);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
|
||||
bool NzRect<T>::Intersect(const NzRect& rect, NzRect* intersection) const
|
||||
{
|
||||
T left = std::max(x, rect.x);
|
||||
T right = std::min(x+width, rect.x+rect.width);
|
||||
@@ -100,10 +92,13 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
|
||||
|
||||
if (left < right && top < bottom)
|
||||
{
|
||||
intersection.x = left;
|
||||
intersection.y = top;
|
||||
intersection.width = right-left;
|
||||
intersection.height = bottom-top;
|
||||
if (intersection)
|
||||
{
|
||||
intersection->x = left;
|
||||
intersection->y = top;
|
||||
intersection->width = right-left;
|
||||
intersection->height = bottom-top;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -114,7 +109,44 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
|
||||
template<typename T>
|
||||
bool NzRect<T>::IsValid() const
|
||||
{
|
||||
return width > 0 && height > 0;
|
||||
return width > F(0.0) && height > F(0.0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzRect<T>::Set(T X, T Y, T Width, T Height)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
width = Width;
|
||||
height = Height;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzRect<T>::Set(const T rect[4])
|
||||
{
|
||||
x = rect[0];
|
||||
y = rect[1];
|
||||
width = rect[2];
|
||||
height = rect[3];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzRect<T>::Set(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
|
||||
{
|
||||
x = std::min(vec1.x, vec2.x);
|
||||
y = std::min(vec1.y, vec2.y);
|
||||
width = (vec2.x > vec1.x) ? vec2.x-vec1.x : vec1.x-vec2.x;
|
||||
height = (vec2.y > vec1.y) ? vec2.y-vec1.y : vec1.y-vec2.y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
void NzRect<T>::Set(const NzRect<U>& rect)
|
||||
{
|
||||
x = F(rect.x);
|
||||
y = F(rect.y);
|
||||
width = F(rect.width);
|
||||
height = F(rect.height);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -134,6 +166,7 @@ NzRect<T>::operator NzString() const
|
||||
template<typename T>
|
||||
T& NzRect<T>::operator[](unsigned int i)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (i >= 4)
|
||||
{
|
||||
NzStringStream ss;
|
||||
@@ -141,6 +174,7 @@ T& NzRect<T>::operator[](unsigned int i)
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
@@ -148,6 +182,7 @@ T& NzRect<T>::operator[](unsigned int i)
|
||||
template<typename T>
|
||||
T NzRect<T>::operator[](unsigned int i) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (i >= 4)
|
||||
{
|
||||
NzStringStream ss;
|
||||
@@ -155,6 +190,7 @@ T NzRect<T>::operator[](unsigned int i) const
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
@@ -165,4 +201,6 @@ std::ostream& operator<<(std::ostream& out, const NzRect<T>& rect)
|
||||
return out << rect.ToString();
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user