Remove Nz::String and Nz::StringStream
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
#define NAZARA_ALGORITHM_MATH_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592653589793238462643
|
||||
@@ -59,9 +59,9 @@ namespace Nz
|
||||
template<typename T> constexpr T NormalizeAngle(T angle);
|
||||
template<typename T> constexpr bool NumberEquals(T a, T b);
|
||||
template<typename T> constexpr bool NumberEquals(T a, T b, T maxDifference);
|
||||
String NumberToString(long long number, UInt8 radix = 10);
|
||||
inline std::string NumberToString(long long number, UInt8 radix = 10);
|
||||
template<typename T> constexpr T RadianToDegree(T radians);
|
||||
long long StringToNumber(String str, UInt8 radix = 10, bool* ok = nullptr);
|
||||
inline long long StringToNumber(const std::string_view& str, UInt8 radix = 10, bool* ok = nullptr);
|
||||
template<typename T> constexpr T ToDegrees(T angle);
|
||||
template<typename T> constexpr T ToRadians(T angle);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
@@ -571,20 +570,18 @@ namespace Nz
|
||||
* \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior
|
||||
* \remark With NAZARA_MATH_SAFE, a NazaraError is produced and String() is returned
|
||||
*/
|
||||
inline String NumberToString(long long number, UInt8 radix)
|
||||
inline std::string NumberToString(long long number, UInt8 radix)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (radix < 2 || radix > 36)
|
||||
{
|
||||
NazaraError("Base must be between 2 and 36");
|
||||
return String();
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
|
||||
if (number == 0)
|
||||
return String('0');
|
||||
|
||||
static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
return "0";
|
||||
|
||||
bool negative;
|
||||
if (number < 0)
|
||||
@@ -595,20 +592,23 @@ namespace Nz
|
||||
else
|
||||
negative = false;
|
||||
|
||||
String str;
|
||||
str.Reserve(GetNumberLength(number)); // Prends en compte le signe négatif
|
||||
std::string str;
|
||||
|
||||
const char symbols[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
do
|
||||
{
|
||||
str.Append(symbols[number % radix]);
|
||||
str.push_back(symbols[number % radix]);
|
||||
number /= radix;
|
||||
}
|
||||
while (number > 0);
|
||||
|
||||
if (negative)
|
||||
str.Append('-');
|
||||
str.push_back('-');
|
||||
|
||||
return str.Reverse();
|
||||
std::reverse(str.begin(), str.end());
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -636,7 +636,7 @@ namespace Nz
|
||||
* \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior
|
||||
* \remark With NAZARA_MATH_SAFE, a NazaraError is produced and 0 is returned
|
||||
*/
|
||||
inline long long StringToNumber(String str, UInt8 radix, bool* ok)
|
||||
inline long long StringToNumber(const std::string_view& str, UInt8 radix, bool* ok)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (radix < 2 || radix > 36)
|
||||
@@ -650,15 +650,19 @@ namespace Nz
|
||||
}
|
||||
#endif
|
||||
|
||||
static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
if (str.empty())
|
||||
{
|
||||
if (ok)
|
||||
*ok = false;
|
||||
|
||||
str.Simplify();
|
||||
if (radix > 10)
|
||||
str = str.ToUpper();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool negative = str.StartsWith('-');
|
||||
const char symbols[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
char* digit = &str[(negative) ? 1 : 0];
|
||||
bool negative = (str.front() == '-');
|
||||
|
||||
const char* digit = &str[(negative) ? 1 : 0];
|
||||
unsigned long long total = 0;
|
||||
do
|
||||
{
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
#ifndef NAZARA_ANGLE_HPP
|
||||
#define NAZARA_ANGLE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@@ -50,7 +51,7 @@ namespace Nz
|
||||
Quaternion<T> ToQuaternion() const;
|
||||
T ToRadians() const;
|
||||
Angle<AngleUnit::Radian, T> ToRadianAngle() const;
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Angle& operator=(const Angle&) = default;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef NAZARA_PLATFORM_POSIX
|
||||
#include <math.h> //< sincos
|
||||
@@ -51,11 +52,6 @@ namespace Nz
|
||||
return DegreeToRadian(degrees);
|
||||
}
|
||||
|
||||
template<typename T> static String ToString(T value)
|
||||
{
|
||||
return "Angle(" + String::Number(value) + "deg)";
|
||||
}
|
||||
|
||||
template<typename T> static std::ostream& ToString(std::ostream& out, T value)
|
||||
{
|
||||
return out << "Angle(" << value << "deg)";
|
||||
@@ -95,11 +91,6 @@ namespace Nz
|
||||
return radians;
|
||||
}
|
||||
|
||||
template<typename T> static String ToString(T value)
|
||||
{
|
||||
return "Angle(" + String::Number(value) + "rad)";
|
||||
}
|
||||
|
||||
template<typename T> static std::ostream& ToString(std::ostream& out, T value)
|
||||
{
|
||||
return out << "Angle(" << value << "rad)";
|
||||
@@ -358,9 +349,12 @@ namespace Nz
|
||||
* \return String representation of the angle
|
||||
*/
|
||||
template<AngleUnit Unit, typename T>
|
||||
String Angle<Unit, T>::ToString() const
|
||||
std::string Angle<Unit, T>::ToString() const
|
||||
{
|
||||
return Detail::AngleUtils<Unit>::ToString(value);
|
||||
std::ostringstream oss;
|
||||
Detail::AngleUtils<Unit>::ToString(oss, value);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
#ifndef NAZARA_BOUNDINGVOLUME_HPP
|
||||
#define NAZARA_BOUNDINGVOLUME_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/OrientedBox.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -47,7 +47,7 @@ namespace Nz
|
||||
BoundingVolume& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
|
||||
template<typename U> BoundingVolume& Set(const BoundingVolume<U>& volume);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
void Update(const Matrix4<T>& transformMatrix);
|
||||
void Update(const Vector3<T>& translation);
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -361,23 +359,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String BoundingVolume<T>::ToString() const
|
||||
std::string BoundingVolume<T>::ToString() const
|
||||
{
|
||||
switch (extend)
|
||||
{
|
||||
case Extend_Finite:
|
||||
return "BoundingVolume(localBox=" + obb.localBox.ToString() + ')';
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
case Extend_Infinite:
|
||||
return "BoundingVolume(Infinite)";
|
||||
|
||||
case Extend_Null:
|
||||
return "BoundingVolume(Null)";
|
||||
}
|
||||
|
||||
// Si nous arrivons ici c'est que l'extend est invalide
|
||||
NazaraError("Invalid extend type (0x" + String::Number(extend, 16) + ')');
|
||||
return "BoundingVolume(ERROR)";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -510,17 +497,17 @@ namespace Nz
|
||||
BoundingVolume<T> BoundingVolume<T>::Lerp(const BoundingVolume& from, const BoundingVolume& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Null();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NumberEquals(interpolation, F(0.0)))
|
||||
if (NumberEquals(interpolation, T(0.0)))
|
||||
return from;
|
||||
|
||||
if (NumberEquals(interpolation, F(1.0)))
|
||||
if (NumberEquals(interpolation, T(1.0)))
|
||||
return to;
|
||||
|
||||
switch (to.extend)
|
||||
@@ -545,7 +532,7 @@ namespace Nz
|
||||
}
|
||||
|
||||
// If we arrive here, the extend is invalid
|
||||
NazaraError("Invalid extend type (From) (0x" + String::Number(from.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (From) (0x" + NumberToString(from.extend, 16) + ')');
|
||||
return Null();
|
||||
}
|
||||
|
||||
@@ -557,7 +544,7 @@ namespace Nz
|
||||
switch (from.extend)
|
||||
{
|
||||
case Extend_Finite:
|
||||
return from.obb * (F(1.0) - interpolation);
|
||||
return from.obb * (T(1.0) - interpolation);
|
||||
|
||||
case Extend_Infinite:
|
||||
return Infinite();
|
||||
@@ -567,13 +554,13 @@ namespace Nz
|
||||
}
|
||||
|
||||
// If we arrive here, the extend is invalid
|
||||
NazaraError("Invalid extend type (From) (0x" + String::Number(from.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (From) (0x" + NumberToString(from.extend, 16) + ')');
|
||||
return Null();
|
||||
}
|
||||
}
|
||||
|
||||
// If we arrive here, the extend is invalid
|
||||
NazaraError("Invalid extend type (To) (0x" + String::Number(to.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (To) (0x" + NumberToString(to.extend, 16) + ')');
|
||||
return Null();
|
||||
}
|
||||
|
||||
@@ -659,10 +646,22 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume<T>& volume)
|
||||
{
|
||||
out << volume.ToString();
|
||||
switch (volume.extend)
|
||||
{
|
||||
case Nz::Extend_Finite:
|
||||
out << "BoundingVolume(localBox=" << volume.obb.localBox << ')';
|
||||
break;
|
||||
|
||||
case Nz::Extend_Infinite:
|
||||
out << "BoundingVolume(Infinite)";
|
||||
break;
|
||||
|
||||
case Nz::Extend_Null:
|
||||
out << "BoundingVolume(Null)";
|
||||
break;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#ifndef NAZARA_BOX_HPP
|
||||
#define NAZARA_BOX_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -68,7 +68,7 @@ namespace Nz
|
||||
Box& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
|
||||
template<typename U> Box& Set(const Box<U>& box);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Box& Transform(const Matrix4<T>& matrix, bool applyTranslation = true);
|
||||
Box& Translate(const Vector3<T>& translation);
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -261,7 +259,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T> Box<T>::GetCenter() const
|
||||
{
|
||||
return GetPosition() + GetLengths() / F(2.0);
|
||||
return GetPosition() + GetLengths() / T(2.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -303,7 +301,7 @@ namespace Nz
|
||||
return Vector3<T>(x + width, y + height, z + depth);
|
||||
}
|
||||
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
return Vector3<T>();
|
||||
}
|
||||
|
||||
@@ -358,13 +356,13 @@ namespace Nz
|
||||
{
|
||||
Vector3<T> neg(GetPosition());
|
||||
|
||||
if (normal.x < F(0.0))
|
||||
if (normal.x < T(0.0))
|
||||
neg.x += width;
|
||||
|
||||
if (normal.y < F(0.0))
|
||||
if (normal.y < T(0.0))
|
||||
neg.y += height;
|
||||
|
||||
if (normal.z < F(0.0))
|
||||
if (normal.z < T(0.0))
|
||||
neg.z += depth;
|
||||
|
||||
return neg;
|
||||
@@ -397,13 +395,13 @@ namespace Nz
|
||||
{
|
||||
Vector3<T> pos(GetPosition());
|
||||
|
||||
if (normal.x > F(0.0))
|
||||
if (normal.x > T(0.0))
|
||||
pos.x += width;
|
||||
|
||||
if (normal.y > F(0.0))
|
||||
if (normal.y > T(0.0))
|
||||
pos.y += height;
|
||||
|
||||
if (normal.z > F(0.0))
|
||||
if (normal.z > T(0.0))
|
||||
pos.z += depth;
|
||||
|
||||
return pos;
|
||||
@@ -442,7 +440,7 @@ namespace Nz
|
||||
T Box<T>::GetSquaredRadius() const
|
||||
{
|
||||
Vector3<T> size(GetLengths());
|
||||
size /= F(2.0); // The size only depends on the lengths and not the center
|
||||
size /= T(2.0); // The size only depends on the lengths and not the center
|
||||
|
||||
return size.GetSquaredLength();
|
||||
}
|
||||
@@ -494,7 +492,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
bool Box<T>::IsValid() const
|
||||
{
|
||||
return width > F(0.0) && height > F(0.0) && depth > F(0.0);
|
||||
return width > T(0.0) && height > T(0.0) && depth > T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -507,12 +505,12 @@ namespace Nz
|
||||
template<typename T>
|
||||
Box<T>& Box<T>::MakeZero()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
width = F(0.0);
|
||||
height = F(0.0);
|
||||
depth = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
width = T(0.0);
|
||||
height = T(0.0);
|
||||
depth = T(0.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -531,9 +529,9 @@ namespace Nz
|
||||
template<typename T>
|
||||
Box<T>& Box<T>::Set(T Width, T Height, T Depth)
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
width = Width;
|
||||
height = Height;
|
||||
depth = Depth;
|
||||
@@ -599,10 +597,10 @@ namespace Nz
|
||||
{
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
z = F(0.0);
|
||||
z = T(0.0);
|
||||
width = rect.width;
|
||||
height = rect.height;
|
||||
depth = F(1.0);
|
||||
depth = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -655,12 +653,12 @@ namespace Nz
|
||||
template<typename U>
|
||||
Box<T>& Box<T>::Set(const Box<U>& box)
|
||||
{
|
||||
x = F(box.x);
|
||||
y = F(box.y);
|
||||
z = F(box.z);
|
||||
width = F(box.width);
|
||||
height = F(box.height);
|
||||
depth = F(box.depth);
|
||||
x = T(box.x);
|
||||
y = T(box.y);
|
||||
z = T(box.z);
|
||||
width = T(box.width);
|
||||
height = T(box.height);
|
||||
depth = T(box.depth);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -671,11 +669,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Box<T>::ToString() const
|
||||
std::string Box<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Box(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -689,8 +688,8 @@ namespace Nz
|
||||
template<typename T>
|
||||
Box<T>& Box<T>::Transform(const Matrix4<T>& matrix, bool applyTranslation)
|
||||
{
|
||||
Vector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Value multiplying the translation
|
||||
Vector3<T> halfSize = GetLengths() / F(2.0);
|
||||
Vector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? T(1.0) : T(0.0)); // Value multiplying the translation
|
||||
Vector3<T> halfSize = GetLengths() / T(2.0);
|
||||
|
||||
halfSize.Set(std::abs(matrix(0,0)) * halfSize.x + std::abs(matrix(1,0)) * halfSize.y + std::abs(matrix(2,0)) * halfSize.z,
|
||||
std::abs(matrix(0,1)) * halfSize.x + std::abs(matrix(1,1)) * halfSize.y + std::abs(matrix(2,1)) * halfSize.z,
|
||||
@@ -855,9 +854,9 @@ namespace Nz
|
||||
Box<T> Box<T>::Lerp(const Box& from, const Box& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
@@ -963,9 +962,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Box<T>& box)
|
||||
{
|
||||
return out << box.ToString();
|
||||
return out << "Box(" << box.x << ", " << box.y << ", " << box.z << ", " << box.width << ", " << box.height << ", " << box.depth << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#ifndef NAZARA_EULERANGLES_HPP
|
||||
#define NAZARA_EULERANGLES_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -43,7 +43,7 @@ namespace Nz
|
||||
|
||||
//Matrix3<T> ToRotationMatrix() const;
|
||||
Quaternion<T> ToQuaternion() const;
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
EulerAngles operator+(const EulerAngles& angles) const;
|
||||
EulerAngles operator-(const EulerAngles& angles) const;
|
||||
|
||||
@@ -4,16 +4,14 @@
|
||||
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -96,7 +94,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
void EulerAngles<T>::MakeZero()
|
||||
{
|
||||
Set(F(0.0), F(0.0), F(0.0));
|
||||
Set(T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -194,9 +192,9 @@ namespace Nz
|
||||
template<typename U>
|
||||
EulerAngles<T>& EulerAngles<T>::Set(const EulerAngles<U>& angles)
|
||||
{
|
||||
pitch = F(angles.pitch);
|
||||
yaw = F(angles.yaw);
|
||||
roll = F(angles.roll);
|
||||
pitch = T(angles.pitch);
|
||||
yaw = T(angles.yaw);
|
||||
roll = T(angles.roll);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -210,13 +208,13 @@ namespace Nz
|
||||
Quaternion<T> EulerAngles<T>::ToQuaternion() const
|
||||
{
|
||||
// XYZ
|
||||
T c1 = std::cos(ToRadians(yaw) / F(2.0));
|
||||
T c2 = std::cos(ToRadians(roll) / F(2.0));
|
||||
T c3 = std::cos(ToRadians(pitch) / F(2.0));
|
||||
T c1 = std::cos(ToRadians(yaw) / T(2.0));
|
||||
T c2 = std::cos(ToRadians(roll) / T(2.0));
|
||||
T c3 = std::cos(ToRadians(pitch) / T(2.0));
|
||||
|
||||
T s1 = std::sin(ToRadians(yaw) / F(2.0));
|
||||
T s2 = std::sin(ToRadians(roll) / F(2.0));
|
||||
T s3 = std::sin(ToRadians(pitch) / F(2.0));
|
||||
T s1 = std::sin(ToRadians(yaw) / T(2.0));
|
||||
T s2 = std::sin(ToRadians(roll) / T(2.0));
|
||||
T s3 = std::sin(ToRadians(pitch) / T(2.0));
|
||||
|
||||
return Quaternion<T>(c1 * c2 * c3 - s1 * s2 * s3,
|
||||
s1 * s2 * c3 + c1 * c2 * s3,
|
||||
@@ -230,11 +228,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String EulerAngles<T>::ToString() const
|
||||
std::string EulerAngles<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -401,9 +400,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles<T>& angles)
|
||||
{
|
||||
return out << angles.ToString();
|
||||
return out << "EulerAngles(" << angles.pitch << ", " << angles.yaw << ", " << angles.roll << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#ifndef NAZARA_FRUSTUM_HPP
|
||||
#define NAZARA_FRUSTUM_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
@@ -15,6 +14,7 @@
|
||||
#include <Nazara/Math/Plane.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -54,7 +54,7 @@ namespace Nz
|
||||
|
||||
template<typename U> Frustum& Set(const Frustum<U>& frustum);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
template<typename U>
|
||||
friend bool Serialize(SerializationContext& context, const Frustum<U>& frustum, TypeTag<Frustum<U>>);
|
||||
|
||||
@@ -7,13 +7,11 @@
|
||||
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -55,9 +53,9 @@ namespace Nz
|
||||
Frustum<T>& Frustum<T>::Build(T angle, T ratio, T zNear, T zFar, const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up)
|
||||
{
|
||||
#if NAZARA_MATH_ANGLE_RADIAN
|
||||
angle /= F(2.0);
|
||||
angle /= T(2.0);
|
||||
#else
|
||||
angle = DegreeToRadian(angle/F(2.0));
|
||||
angle = DegreeToRadian(angle / T(2.0));
|
||||
#endif
|
||||
|
||||
T tangent = std::tan(angle);
|
||||
@@ -128,7 +126,7 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Invalid intersection side (0x" + String::Number(side, 16) + ')');
|
||||
NazaraError("Invalid intersection side (0x" + NumberToString(side, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -139,7 +137,7 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -156,7 +154,7 @@ namespace Nz
|
||||
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/
|
||||
for (unsigned int i = 0; i <= FrustumPlane_Max; i++)
|
||||
{
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0))
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -173,7 +171,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
bool Frustum<T>::Contains(const OrientedBox<T>& orientedbox) const
|
||||
{
|
||||
return Contains(&orientedbox[0], 8);
|
||||
return Contains(orientedbox.GetCorners(), 8);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -207,7 +205,7 @@ namespace Nz
|
||||
{
|
||||
for (unsigned int i = 0; i <= FrustumPlane_Max; ++i)
|
||||
{
|
||||
if (m_planes[i].Distance(point) < F(0.0))
|
||||
if (m_planes[i].Distance(point) < T(0.0))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -230,7 +228,7 @@ namespace Nz
|
||||
unsigned int j;
|
||||
for (j = 0; j < pointCount; j++ )
|
||||
{
|
||||
if (m_planes[i].Distance(points[j]) > F(0.0))
|
||||
if (m_planes[i].Distance(points[j]) > T(0.0))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -264,7 +262,7 @@ namespace Nz
|
||||
plane[3] = clipMatrix[15] - clipMatrix[12];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
@@ -279,7 +277,7 @@ namespace Nz
|
||||
plane[3] = clipMatrix[15] + clipMatrix[12];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
@@ -294,7 +292,7 @@ namespace Nz
|
||||
plane[3] = clipMatrix[15] + clipMatrix[13];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
@@ -309,7 +307,7 @@ namespace Nz
|
||||
plane[3] = clipMatrix[15] - clipMatrix[13];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
@@ -324,7 +322,7 @@ namespace Nz
|
||||
plane[3] = clipMatrix[15] - clipMatrix[14];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
@@ -339,7 +337,7 @@ namespace Nz
|
||||
plane[3] = clipMatrix[15] + clipMatrix[14];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
@@ -356,56 +354,56 @@ namespace Nz
|
||||
Vector4<T> corner;
|
||||
|
||||
// FarLeftBottom
|
||||
corner.Set(F(-1.0), F(-1.0), F(1.0));
|
||||
corner.Set(T(-1.0), T(-1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarLeftBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// FarLeftTop
|
||||
corner.Set(F(-1.0), F(1.0), F(1.0));
|
||||
corner.Set(T(-1.0), T(1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarLeftTop] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// FarRightBottom
|
||||
corner.Set(F(1.0), F(-1.0), F(1.0));
|
||||
corner.Set(T(1.0), T(-1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarRightBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// FarRightTop
|
||||
corner.Set(F(1.0), F(1.0), F(1.0));
|
||||
corner.Set(T(1.0), T(1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarRightTop] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearLeftBottom
|
||||
corner.Set(F(-1.0), F(-1.0), F(0.0));
|
||||
corner.Set(T(-1.0), T(-1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_NearLeftBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearLeftTop
|
||||
corner.Set(F(-1.0), F(1.0), F(0.0));
|
||||
corner.Set(T(-1.0), T(1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_NearLeftTop] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearRightBottom
|
||||
corner.Set(F(1.0), F(-1.0), F(0.0));
|
||||
corner.Set(T(1.0), T(-1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_NearRightBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearRightTop
|
||||
corner.Set(F(1.0), F(1.0), F(0.0));
|
||||
corner.Set(T(1.0), T(1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
@@ -448,7 +446,7 @@ namespace Nz
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (corner > BoxCorner_Max)
|
||||
{
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
|
||||
static Vector3<T> dummy;
|
||||
return dummy;
|
||||
@@ -473,7 +471,7 @@ namespace Nz
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (plane > FrustumPlane_Max)
|
||||
{
|
||||
NazaraError("Frustum plane not handled (0x" + String::Number(plane, 16) + ')');
|
||||
NazaraError("Frustum plane not handled (0x" + NumberToString(plane, 16) + ')');
|
||||
|
||||
static Plane<T> dummy;
|
||||
return dummy;
|
||||
@@ -515,7 +513,7 @@ namespace Nz
|
||||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
NazaraError("Invalid intersection side (0x" + String::Number(side, 16) + ')');
|
||||
NazaraError("Invalid intersection side (0x" + NumberToString(side, 16) + ')');
|
||||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
@@ -526,7 +524,7 @@ namespace Nz
|
||||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')');
|
||||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
@@ -545,9 +543,9 @@ namespace Nz
|
||||
|
||||
for (unsigned int i = 0; i <= FrustumPlane_Max; i++)
|
||||
{
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0))
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0))
|
||||
return IntersectionSide_Outside;
|
||||
else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < F(0.0))
|
||||
else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < T(0.0))
|
||||
side = IntersectionSide_Intersecting;
|
||||
}
|
||||
|
||||
@@ -564,7 +562,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
IntersectionSide Frustum<T>::Intersect(const OrientedBox<T>& orientedbox) const
|
||||
{
|
||||
return Intersect(&orientedbox[0], 8);
|
||||
return Intersect(orientedbox.GetCorners(), 8);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -610,7 +608,7 @@ namespace Nz
|
||||
unsigned int j;
|
||||
for (j = 0; j < pointCount; j++ )
|
||||
{
|
||||
if (m_planes[i].Distance(points[j]) > F(0.0))
|
||||
if (m_planes[i].Distance(points[j]) > T(0.0))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -649,16 +647,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Frustum<T>::ToString() const
|
||||
std::string Frustum<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Frustum(Bottom: " << m_planes[FrustumPlane_Bottom].ToString() << "\n"
|
||||
<< " Far: " << m_planes[FrustumPlane_Far].ToString() << "\n"
|
||||
<< " Left: " << m_planes[FrustumPlane_Left].ToString() << "\n"
|
||||
<< " Near: " << m_planes[FrustumPlane_Near].ToString() << "\n"
|
||||
<< " Right: " << m_planes[FrustumPlane_Right].ToString() << "\n"
|
||||
<< " Top: " << m_planes[FrustumPlane_Top].ToString() << ")\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -723,9 +717,12 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Frustum<T>& frustum)
|
||||
{
|
||||
return out << frustum.ToString();
|
||||
return out << "Frustum(Bottom: " << frustum.GetPlane(Nz::FrustumPlane_Bottom) << ",\n"
|
||||
<< " Far: " << frustum.GetPlane(Nz::FrustumPlane_Far) << ",\n"
|
||||
<< " Left: " << frustum.GetPlane(Nz::FrustumPlane_Left) << ",\n"
|
||||
<< " Near: " << frustum.GetPlane(Nz::FrustumPlane_Near) << ",\n"
|
||||
<< " Right: " << frustum.GetPlane(Nz::FrustumPlane_Right) << ",\n"
|
||||
<< " Top: " << frustum.GetPlane(Nz::FrustumPlane_Top) << ")\n";
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
|
||||
///FIXME: Matrices column-major, difficile de bosser avec (Tout passer en row-major et transposer dans les shaders ?)
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -90,7 +91,7 @@ namespace Nz
|
||||
Matrix4& SetScale(const Vector3<T>& scale);
|
||||
Matrix4& SetTranslation(const Vector3<T>& translation);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Vector2<T> Transform(const Vector2<T>& vector, T z = 0.0, T w = 1.0) const;
|
||||
Vector3<T> Transform(const Vector3<T>& vector, T w = 1.0) const;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
@@ -14,11 +13,10 @@
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -202,22 +200,22 @@ namespace Nz
|
||||
return Set(m11*matrix.m11 + m12*matrix.m21 + m13*matrix.m31,
|
||||
m11*matrix.m12 + m12*matrix.m22 + m13*matrix.m32,
|
||||
m11*matrix.m13 + m12*matrix.m23 + m13*matrix.m33,
|
||||
F(0.0),
|
||||
T(0.0),
|
||||
|
||||
m21*matrix.m11 + m22*matrix.m21 + m23*matrix.m31,
|
||||
m21*matrix.m12 + m22*matrix.m22 + m23*matrix.m32,
|
||||
m21*matrix.m13 + m22*matrix.m23 + m23*matrix.m33,
|
||||
F(0.0),
|
||||
T(0.0),
|
||||
|
||||
m31*matrix.m11 + m32*matrix.m21 + m33*matrix.m31,
|
||||
m31*matrix.m12 + m32*matrix.m22 + m33*matrix.m32,
|
||||
m31*matrix.m13 + m32*matrix.m23 + m33*matrix.m33,
|
||||
F(0.0),
|
||||
T(0.0),
|
||||
|
||||
m41*matrix.m11 + m42*matrix.m21 + m43*matrix.m31 + matrix.m41,
|
||||
m41*matrix.m12 + m42*matrix.m22 + m43*matrix.m32 + matrix.m42,
|
||||
m41*matrix.m13 + m42*matrix.m23 + m43*matrix.m33 + matrix.m43,
|
||||
F(1.0));
|
||||
T(1.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -257,10 +255,10 @@ namespace Nz
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (column > 3)
|
||||
{
|
||||
String error("Column out of range: (" + String::Number(column) + ") > 3");
|
||||
std::string error("Column out of range: (" + std::to_string(column) + ") > 3");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -466,7 +464,7 @@ namespace Nz
|
||||
m31 * m12 * m23 -
|
||||
m31 * m13 * m22;
|
||||
|
||||
T invDet = F(1.0) / det;
|
||||
T invDet = T(1.0) / det;
|
||||
for (unsigned int i = 0; i < 16; ++i)
|
||||
inv[i] *= invDet;
|
||||
|
||||
@@ -508,7 +506,7 @@ namespace Nz
|
||||
#endif
|
||||
|
||||
T det = GetDeterminantAffine();
|
||||
if (det != F(0.0))
|
||||
if (det != T(0.0))
|
||||
{
|
||||
// http://stackoverflow.com/questions/1148309/inverting-a-4x4-matrix
|
||||
T inv[16];
|
||||
@@ -521,7 +519,7 @@ namespace Nz
|
||||
inv[2] = m12 * m23 -
|
||||
m22 * m13;
|
||||
|
||||
inv[3] = F(0.0);
|
||||
inv[3] = T(0.0);
|
||||
|
||||
inv[4] = -m21 * m33 +
|
||||
m31 * m23;
|
||||
@@ -532,7 +530,7 @@ namespace Nz
|
||||
inv[6] = -m11 * m23 +
|
||||
m21 * m13;
|
||||
|
||||
inv[7] = F(0.0);
|
||||
inv[7] = T(0.0);
|
||||
|
||||
inv[8] = m21 * m32 -
|
||||
m31 * m22;
|
||||
@@ -543,7 +541,7 @@ namespace Nz
|
||||
inv[10] = m11 * m22 -
|
||||
m21 * m12;
|
||||
|
||||
inv[11] = F(0.0);
|
||||
inv[11] = T(0.0);
|
||||
|
||||
inv[12] = -m21 * m32 * m43 +
|
||||
m21 * m33 * m42 +
|
||||
@@ -566,11 +564,11 @@ namespace Nz
|
||||
m41 * m12 * m23 +
|
||||
m41 * m13 * m22;
|
||||
|
||||
T invDet = F(1.0) / det;
|
||||
T invDet = T(1.0) / det;
|
||||
for (unsigned int i = 0; i < 16; ++i)
|
||||
inv[i] *= invDet;
|
||||
|
||||
inv[15] = F(1.0);
|
||||
inv[15] = T(1.0);
|
||||
|
||||
*dest = inv;
|
||||
return true;
|
||||
@@ -591,10 +589,10 @@ namespace Nz
|
||||
Quaternion<T> quat;
|
||||
|
||||
T trace = m11 + m22 + m33;
|
||||
if (trace > F(0.0))
|
||||
if (trace > T(0.0))
|
||||
{
|
||||
T s = F(0.5) / std::sqrt(trace + F(1.0));
|
||||
quat.w = F(0.25) / s;
|
||||
T s = T(0.5) / std::sqrt(trace + T(1.0));
|
||||
quat.w = T(0.25) / s;
|
||||
quat.x = (m23 - m32) * s;
|
||||
quat.y = (m31 - m13) * s;
|
||||
quat.z = (m12 - m21) * s;
|
||||
@@ -603,30 +601,30 @@ namespace Nz
|
||||
{
|
||||
if (m11 > m22 && m11 > m33)
|
||||
{
|
||||
T s = F(2.0) * std::sqrt(F(1.0) + m11 - m22 - m33);
|
||||
T s = T(2.0) * std::sqrt(T(1.0) + m11 - m22 - m33);
|
||||
|
||||
quat.w = (m23 - m32) / s;
|
||||
quat.x = F(0.25) * s;
|
||||
quat.x = T(0.25) * s;
|
||||
quat.y = (m21 + m12) / s;
|
||||
quat.z = (m31 + m13) / s;
|
||||
}
|
||||
else if (m22 > m33)
|
||||
{
|
||||
T s = F(2.0) * std::sqrt(F(1.0) + m22 - m11 - m33);
|
||||
T s = T(2.0) * std::sqrt(T(1.0) + m22 - m11 - m33);
|
||||
|
||||
quat.w = (m31 - m13) / s;
|
||||
quat.x = (m21 + m12) / s;
|
||||
quat.y = F(0.25) * s;
|
||||
quat.y = T(0.25) * s;
|
||||
quat.z = (m32 + m23) / s;
|
||||
}
|
||||
else
|
||||
{
|
||||
T s = F(2.0) * std::sqrt(F(1.0) + m33 - m11 - m22);
|
||||
T s = T(2.0) * std::sqrt(T(1.0) + m33 - m11 - m22);
|
||||
|
||||
quat.w = (m12 - m21) / s;
|
||||
quat.x = (m31 + m13) / s;
|
||||
quat.y = (m32 + m23) / s;
|
||||
quat.z = F(0.25) * s;
|
||||
quat.z = T(0.25) * s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,10 +649,10 @@ namespace Nz
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (row > 3)
|
||||
{
|
||||
String error("Row out of range: (" + String::Number(row) + ") > 3");
|
||||
std::string error("Row out of range: (" + NumberToString(row) + ") > 3");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -740,7 +738,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
bool Matrix4<T>::HasNegativeScale() const
|
||||
{
|
||||
return GetDeterminant() < F(0.0);
|
||||
return GetDeterminant() < T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -754,15 +752,15 @@ namespace Nz
|
||||
bool Matrix4<T>::HasScale() const
|
||||
{
|
||||
T t = m11*m11 + m21*m21 + m31*m31;
|
||||
if (!NumberEquals(t, F(1.0)))
|
||||
if (!NumberEquals(t, T(1.0)))
|
||||
return true;
|
||||
|
||||
t = m12*m12 + m22*m22 + m32*m32;
|
||||
if (!NumberEquals(t, F(1.0)))
|
||||
if (!NumberEquals(t, T(1.0)))
|
||||
return true;
|
||||
|
||||
t = m13*m13 + m23*m23 + m33*m33;
|
||||
if (!NumberEquals(t, F(1.0)))
|
||||
if (!NumberEquals(t, T(1.0)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -814,7 +812,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
bool Matrix4<T>::IsAffine() const
|
||||
{
|
||||
return NumberEquals(m14, F(0.0)) && NumberEquals(m24, F(0.0)) && NumberEquals(m34, F(0.0)) && NumberEquals(m44, F(1.0));
|
||||
return NumberEquals(m14, T(0.0)) && NumberEquals(m24, T(0.0)) && NumberEquals(m34, T(0.0)) && NumberEquals(m44, T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -825,10 +823,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
bool Matrix4<T>::IsIdentity() const
|
||||
{
|
||||
return (NumberEquals(m11, F(1.0)) && NumberEquals(m12, F(0.0)) && NumberEquals(m13, F(0.0)) && NumberEquals(m14, F(0.0)) &&
|
||||
NumberEquals(m21, F(0.0)) && NumberEquals(m22, F(1.0)) && NumberEquals(m23, F(0.0)) && NumberEquals(m24, F(0.0)) &&
|
||||
NumberEquals(m31, F(0.0)) && NumberEquals(m32, F(0.0)) && NumberEquals(m33, F(1.0)) && NumberEquals(m34, F(0.0)) &&
|
||||
NumberEquals(m41, F(0.0)) && NumberEquals(m42, F(0.0)) && NumberEquals(m43, F(0.0)) && NumberEquals(m44, F(1.0)));
|
||||
return (NumberEquals(m11, T(1.0)) && NumberEquals(m12, T(0.0)) && NumberEquals(m13, T(0.0)) && NumberEquals(m14, T(0.0)) &&
|
||||
NumberEquals(m21, T(0.0)) && NumberEquals(m22, T(1.0)) && NumberEquals(m23, T(0.0)) && NumberEquals(m24, T(0.0)) &&
|
||||
NumberEquals(m31, T(0.0)) && NumberEquals(m32, T(0.0)) && NumberEquals(m33, T(1.0)) && NumberEquals(m34, T(0.0)) &&
|
||||
NumberEquals(m41, T(0.0)) && NumberEquals(m42, T(0.0)) && NumberEquals(m43, T(0.0)) && NumberEquals(m44, T(1.0)));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -841,10 +839,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeIdentity()
|
||||
{
|
||||
Set(F(1.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(1.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(1.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
Set(T(1.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(1.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(1.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -893,10 +891,10 @@ namespace Nz
|
||||
Matrix4<T>& Matrix4<T>::MakeOrtho(T left, T right, T top, T bottom, T zNear, T zFar)
|
||||
{
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb204942(v=vs.85).aspx
|
||||
Set(F(2.0) / (right - left), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(2.0) / (top - bottom), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(1.0) / (zNear - zFar), F(0.0),
|
||||
(left + right) / (left - right), (top + bottom) / (bottom - top), zNear/(zNear - zFar), F(1.0));
|
||||
Set(T(2.0) / (right - left), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(2.0) / (top - bottom), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(1.0) / (zNear - zFar), T(0.0),
|
||||
(left + right) / (left - right), (top + bottom) / (bottom - top), zNear/(zNear - zFar), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -918,17 +916,17 @@ namespace Nz
|
||||
{
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb204945(v=vs.85).aspx
|
||||
#if NAZARA_MATH_ANGLE_RADIAN
|
||||
angle /= F(2.0);
|
||||
angle /= T(2.0);
|
||||
#else
|
||||
angle = DegreeToRadian(angle/F(2.0));
|
||||
angle = DegreeToRadian(angle / T(2.0));
|
||||
#endif
|
||||
|
||||
T yScale = std::tan(static_cast<T>(M_PI_2) - angle);
|
||||
|
||||
Set(yScale / ratio, F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), yScale, F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), - (zFar + zNear) / (zFar - zNear), F(-1.0),
|
||||
F(0.0), F(0.0), F(-2.0) * (zNear * zFar) / (zFar - zNear), F(0.0));
|
||||
Set(yScale / ratio, T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), yScale, T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), - (zFar + zNear) / (zFar - zNear), T(-1.0),
|
||||
T(0.0), T(0.0), T(-2.0) * (zNear * zFar) / (zFar - zNear), T(0.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -948,13 +946,13 @@ namespace Nz
|
||||
SetRotation(rotation);
|
||||
|
||||
// We complete the matrix
|
||||
m14 = F(0.0);
|
||||
m24 = F(0.0);
|
||||
m34 = F(0.0);
|
||||
m41 = F(0.0);
|
||||
m42 = F(0.0);
|
||||
m43 = F(0.0);
|
||||
m44 = F(1.0);
|
||||
m14 = T(0.0);
|
||||
m24 = T(0.0);
|
||||
m34 = T(0.0);
|
||||
m41 = T(0.0);
|
||||
m42 = T(0.0);
|
||||
m43 = T(0.0);
|
||||
m44 = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -971,10 +969,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeScale(const Vector3<T>& scale)
|
||||
{
|
||||
Set(scale.x, F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), scale.y, F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), scale.z, F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
Set(scale.x, T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), scale.y, T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), scale.z, T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -991,10 +989,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeTranslation(const Vector3<T>& translation)
|
||||
{
|
||||
Set(F(1.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(1.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(1.0), F(0.0),
|
||||
translation.x, translation.y, translation.z, F(1.0));
|
||||
Set(T(1.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(1.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(1.0), T(0.0),
|
||||
translation.x, translation.y, translation.z, T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -1019,10 +1017,10 @@ namespace Nz
|
||||
SetTranslation(translation);
|
||||
|
||||
// We complete the matrix (the transformations are affine)
|
||||
m14 = F(0.0);
|
||||
m24 = F(0.0);
|
||||
m34 = F(0.0);
|
||||
m44 = F(1.0);
|
||||
m14 = T(0.0);
|
||||
m24 = T(0.0);
|
||||
m34 = T(0.0);
|
||||
m44 = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -1078,10 +1076,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeZero()
|
||||
{
|
||||
Set(F(0.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(0.0));
|
||||
Set(T(0.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(0.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -1130,10 +1128,10 @@ namespace Nz
|
||||
template<typename U>
|
||||
Matrix4<T>& Matrix4<T>::Set(const Matrix4<U>& matrix)
|
||||
{
|
||||
Set(F(matrix[ 0]), F(matrix[ 1]), F(matrix[ 2]), F(matrix[ 3]),
|
||||
F(matrix[ 4]), F(matrix[ 5]), F(matrix[ 6]), F(matrix[ 7]),
|
||||
F(matrix[ 8]), F(matrix[ 9]), F(matrix[10]), F(matrix[11]),
|
||||
F(matrix[12]), F(matrix[13]), F(matrix[14]), F(matrix[15]));
|
||||
Set(T(matrix[ 0]), T(matrix[ 1]), T(matrix[ 2]), T(matrix[ 3]),
|
||||
T(matrix[ 4]), T(matrix[ 5]), T(matrix[ 6]), T(matrix[ 7]),
|
||||
T(matrix[ 8]), T(matrix[ 9]), T(matrix[10]), T(matrix[11]),
|
||||
T(matrix[12]), T(matrix[13]), T(matrix[14]), T(matrix[15]));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -1159,17 +1157,17 @@ namespace Nz
|
||||
T qy2 = qy * qy;
|
||||
T qz2 = qz * qz;
|
||||
|
||||
m11 = F(1.0) - F(2.0) * qy2 - F(2.0) * qz2;
|
||||
m21 = F(2.0) * qx * qy - F(2.0) * qz * qw;
|
||||
m31 = F(2.0) * qx * qz + F(2.0) * qy * qw;
|
||||
m11 = T(1.0) - T(2.0) * qy2 - T(2.0) * qz2;
|
||||
m21 = T(2.0) * qx * qy - T(2.0) * qz * qw;
|
||||
m31 = T(2.0) * qx * qz + T(2.0) * qy * qw;
|
||||
|
||||
m12 = F(2.0) * qx * qy + F(2.0) * qz * qw;
|
||||
m22 = F(1.0) - F(2.0) * qx2 - F(2.0) * qz2;
|
||||
m32 = F(2.0) * qy * qz - F(2.0) * qx * qw;
|
||||
m12 = T(2.0) * qx * qy + T(2.0) * qz * qw;
|
||||
m22 = T(1.0) - T(2.0) * qx2 - T(2.0) * qz2;
|
||||
m32 = T(2.0) * qy * qz - T(2.0) * qx * qw;
|
||||
|
||||
m13 = F(2.0) * qx * qz - F(2.0) * qy * qw;
|
||||
m23 = F(2.0) * qy * qz + F(2.0) * qx * qw;
|
||||
m33 = F(1.0) - F(2.0) * qx2 - F(2.0) * qy2;
|
||||
m13 = T(2.0) * qx * qz - T(2.0) * qy * qw;
|
||||
m23 = T(2.0) * qy * qz + T(2.0) * qx * qw;
|
||||
m33 = T(1.0) - T(2.0) * qx2 - T(2.0) * qy2;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -1218,13 +1216,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Matrix4<T>::ToString() const
|
||||
std::string Matrix4<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
return ss << "Matrix4(" << m11 << ", " << m12 << ", " << m13 << ", " << m14 << ",\n"
|
||||
<< " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n"
|
||||
<< " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n"
|
||||
<< " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')';
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1335,10 +1332,10 @@ namespace Nz
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (x > 3 || y > 3)
|
||||
{
|
||||
String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)");
|
||||
std::string error("Index out of range: (" + NumberToString(x) + ", " + NumberToString(y) +") > (3, 3)");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1359,10 +1356,10 @@ namespace Nz
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (x > 3 || y > 3)
|
||||
{
|
||||
String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)");
|
||||
std::string error("Index out of range: (" + NumberToString(x) + ", " + NumberToString(y) +") > (3, 3)");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1801,7 +1798,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Matrix4<T>& matrix)
|
||||
{
|
||||
return out << matrix.ToString();
|
||||
return out << "Matrix4(" << matrix.m11 << ", " << matrix.m12 << ", " << matrix.m13 << ", " << matrix.m14 << ",\n"
|
||||
<< " " << matrix.m21 << ", " << matrix.m22 << ", " << matrix.m23 << ", " << matrix.m24 << ",\n"
|
||||
<< " " << matrix.m31 << ", " << matrix.m32 << ", " << matrix.m33 << ", " << matrix.m34 << ",\n"
|
||||
<< " " << matrix.m41 << ", " << matrix.m42 << ", " << matrix.m43 << ", " << matrix.m44 << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1818,6 +1818,4 @@ Nz::Matrix4<T> operator*(T scale, const Nz::Matrix4<T>& matrix)
|
||||
return matrix * scale;
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
#ifndef NAZARA_ORIENTEDBOX_HPP
|
||||
#define NAZARA_ORIENTEDBOX_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -29,6 +30,7 @@ namespace Nz
|
||||
~OrientedBox() = default;
|
||||
|
||||
const Vector3<T>& GetCorner(BoxCorner corner) const;
|
||||
const Vector3<T>* GetCorners() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
@@ -39,14 +41,11 @@ namespace Nz
|
||||
OrientedBox& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
|
||||
template<typename U> OrientedBox& Set(const OrientedBox<U>& orientedBox);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
void Update(const Matrix4<T>& transformMatrix);
|
||||
void Update(const Vector3<T>& transformMatrix);
|
||||
|
||||
operator Vector3<T>* ();
|
||||
operator const Vector3<T>* () const;
|
||||
|
||||
Vector3<T>& operator()(unsigned int i);
|
||||
Vector3<T> operator()(unsigned int i) const;
|
||||
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#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)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -93,7 +91,7 @@ namespace Nz
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (corner > BoxCorner_Max)
|
||||
{
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
|
||||
static Vector3<T> dummy;
|
||||
return dummy;
|
||||
@@ -103,6 +101,12 @@ namespace Nz
|
||||
return m_corners[corner];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const Vector3<T>* OrientedBox<T>::GetCorners() const
|
||||
{
|
||||
return &m_corners[0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether this oriented box is valid
|
||||
* \return true if the oriented box has a strictly positive width, height and depth
|
||||
@@ -205,18 +209,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String OrientedBox<T>::ToString() const
|
||||
std::string OrientedBox<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "OrientedBox(FLB: " << m_corners[BoxCorner_FarLeftBottom].ToString() << "\n"
|
||||
<< " FLT: " << m_corners[BoxCorner_FarLeftTop].ToString() << "\n"
|
||||
<< " FRB: " << m_corners[BoxCorner_FarRightBottom].ToString() << "\n"
|
||||
<< " FRT: " << m_corners[BoxCorner_FarRightTop].ToString() << "\n"
|
||||
<< " NLB: " << m_corners[BoxCorner_NearLeftBottom].ToString() << "\n"
|
||||
<< " NLT: " << m_corners[BoxCorner_NearLeftTop].ToString() << "\n"
|
||||
<< " NRB: " << m_corners[BoxCorner_NearRightBottom].ToString() << "\n"
|
||||
<< " NRT: " << m_corners[BoxCorner_NearRightTop].ToString() << ")\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -245,32 +243,6 @@ namespace Nz
|
||||
m_corners[i] = localBox.GetCorner(static_cast<BoxCorner>(i)) + translation;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts oriented box to pointer of Vector3 to its own corners
|
||||
* \return A pointer to the own corners
|
||||
*
|
||||
* \remark Access to index greather than BoxCorner_Max is undefined behavior
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
OrientedBox<T>::operator Vector3<T>* ()
|
||||
{
|
||||
return &m_corners[0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts oriented box to pointer of Vector3 to its own corners
|
||||
* \return A const pointer to the own corners
|
||||
*
|
||||
* \remark Access to index greather than BoxCorner_Max is undefined behavior
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
OrientedBox<T>::operator const Vector3<T>* () const
|
||||
{
|
||||
return &m_corners[0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith corner of the oriented box
|
||||
* \return A reference to this corner
|
||||
@@ -285,11 +257,11 @@ namespace Nz
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (i > BoxCorner_Max)
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")";
|
||||
|
||||
NazaraError(ss);
|
||||
throw std::out_of_range(ss.ToString().ToStdString());
|
||||
NazaraError(ss.str());
|
||||
throw std::out_of_range(ss.str());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -307,16 +279,16 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T> OrientedBox<T>::operator()(unsigned int i) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (i > BoxCorner_Max)
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")";
|
||||
|
||||
NazaraError(ss);
|
||||
throw std::out_of_range(ss.ToString().ToStdString());
|
||||
NazaraError(ss.str());
|
||||
throw std::out_of_range(ss.str());
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return m_corners[i];
|
||||
}
|
||||
@@ -465,9 +437,15 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox<T>& orientedBox)
|
||||
{
|
||||
return out << orientedBox.ToString();
|
||||
return out << "OrientedBox(FLB: " << orientedBox.GetCorner(Nz::BoxCorner_FarLeftBottom) << ",\n"
|
||||
<< " FLT: " << orientedBox.GetCorner(Nz::BoxCorner_FarLeftTop) << ",\n"
|
||||
<< " FRB: " << orientedBox.GetCorner(Nz::BoxCorner_FarRightBottom) << ",\n"
|
||||
<< " FRT: " << orientedBox.GetCorner(Nz::BoxCorner_FarRightTop) << ",\n"
|
||||
<< " NLB: " << orientedBox.GetCorner(Nz::BoxCorner_NearLeftBottom) << ",\n"
|
||||
<< " NLT: " << orientedBox.GetCorner(Nz::BoxCorner_NearLeftTop) << ",\n"
|
||||
<< " NRB: " << orientedBox.GetCorner(Nz::BoxCorner_NearRightBottom) << ",\n"
|
||||
<< " NRT: " << orientedBox.GetCorner(Nz::BoxCorner_NearRightTop) << ")\n";
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
#include "OrientedBox.hpp"
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#ifndef NAZARA_PLANE_HPP
|
||||
#define NAZARA_PLANE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -42,7 +42,7 @@ namespace Nz
|
||||
Plane& Set(const Vector3<T>& point1, const Vector3<T>& point2, const Vector3<T>& point3);
|
||||
template<typename U> Plane& Set(const Plane<U>& plane);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Plane& operator=(const Plane& other) = default;
|
||||
|
||||
|
||||
@@ -3,13 +3,11 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -148,7 +146,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Plane<T>& Plane<T>::MakeXY()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -161,7 +159,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Plane<T>& Plane<T>::MakeXZ()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -174,7 +172,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Plane<T>& Plane<T>::MakeYZ()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -282,7 +280,7 @@ namespace Nz
|
||||
Plane<T>& Plane<T>::Set(const Plane<U>& plane)
|
||||
{
|
||||
normal.Set(plane.normal);
|
||||
distance = F(plane.distance);
|
||||
distance = T(plane.distance);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -293,11 +291,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Plane<T>::ToString() const
|
||||
std::string Plane<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Plane(Normal: " << normal.ToString() << "; Distance: " << distance << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -348,9 +347,9 @@ namespace Nz
|
||||
Plane<T> Plane<T>::Lerp(const Plane& from, const Plane& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Plane();
|
||||
}
|
||||
#endif
|
||||
@@ -461,9 +460,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Plane<T>& plane)
|
||||
{
|
||||
return out << plane.ToString();
|
||||
return out << "Plane(Normal: " << plane.normal << "; Distance: " << plane.distance << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#ifndef NAZARA_QUATERNION_HPP
|
||||
#define NAZARA_QUATERNION_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -63,7 +63,7 @@ namespace Nz
|
||||
RadianAngle<T> To2DAngle() const;
|
||||
EulerAngles<T> ToEulerAngles() const;
|
||||
//Matrix3<T> ToRotationMatrix() const;
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Quaternion& operator=(const Quaternion& quat) = default;
|
||||
|
||||
|
||||
@@ -4,17 +4,15 @@
|
||||
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -119,10 +117,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Quaternion<T>& Quaternion<T>::ComputeW()
|
||||
{
|
||||
T t = F(1.0) - SquaredMagnitude();
|
||||
T t = T(1.0) - SquaredMagnitude();
|
||||
|
||||
if (t < F(0.0))
|
||||
w = F(0.0);
|
||||
if (t < T(0.0))
|
||||
w = T(0.0);
|
||||
else
|
||||
w = -std::sqrt(t);
|
||||
|
||||
@@ -230,9 +228,9 @@ namespace Nz
|
||||
Quaternion<T>& Quaternion<T>::Inverse()
|
||||
{
|
||||
T norm = SquaredMagnitude();
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / std::sqrt(norm);
|
||||
T invNorm = T(1.0) / std::sqrt(norm);
|
||||
|
||||
w *= invNorm;
|
||||
x *= -invNorm;
|
||||
@@ -253,7 +251,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Quaternion<T>& Quaternion<T>::MakeIdentity()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -288,7 +286,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Quaternion<T>& Quaternion<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -319,9 +317,9 @@ namespace Nz
|
||||
Quaternion<T>& Quaternion<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = std::sqrt(SquaredMagnitude());
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
T invNorm = T(1.0) / norm;
|
||||
w *= invNorm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
@@ -399,7 +397,7 @@ namespace Nz
|
||||
angle = DegreeToRadian(angle);
|
||||
#endif
|
||||
|
||||
angle /= F(2.0);
|
||||
angle /= T(2.0);
|
||||
|
||||
Vector3<T> normalizedAxis = axis.GetNormal();
|
||||
|
||||
@@ -442,10 +440,10 @@ namespace Nz
|
||||
template<typename U>
|
||||
Quaternion<T>& Quaternion<T>::Set(const Quaternion<U>& quat)
|
||||
{
|
||||
w = F(quat.w);
|
||||
x = F(quat.x);
|
||||
y = F(quat.y);
|
||||
z = F(quat.z);
|
||||
w = T(quat.w);
|
||||
x = T(quat.x);
|
||||
y = T(quat.y);
|
||||
z = T(quat.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -488,17 +486,17 @@ namespace Nz
|
||||
EulerAngles<T> Quaternion<T>::ToEulerAngles() const
|
||||
{
|
||||
T test = x * y + z * w;
|
||||
if (test > F(0.499))
|
||||
if (test > T(0.499))
|
||||
// singularity at north pole
|
||||
return EulerAngles<T>(F(0.0), FromRadians(F(2.0) * std::atan2(x, w)), FromDegrees(F(90.0)));
|
||||
return EulerAngles<T>(T(0.0), FromRadians(T(2.0) * std::atan2(x, w)), FromDegrees(T(90.0)));
|
||||
|
||||
if (test < F(-0.499))
|
||||
if (test < T(-0.499))
|
||||
// singularity at south pole
|
||||
return EulerAngles<T>(F(0.0), FromRadians(F(-2.0) * std::atan2(x, w)), FromDegrees(F(-90.0)));
|
||||
return EulerAngles<T>(T(0.0), FromRadians(T(-2.0) * std::atan2(x, w)), FromDegrees(T(-90.0)));
|
||||
|
||||
return EulerAngles<T>(FromRadians(std::atan2(F(2.0) * x * w - F(2.0) * y * z, F(1.0) - F(2.0) * x * x - F(2.0) * z * z)),
|
||||
FromRadians(std::atan2(F(2.0) * y * w - F(2.0) * x * z, F(1.0) - F(2.0) * y * y - F(2.0) * z * z)),
|
||||
FromRadians(std::asin(F(2.0) * test)));
|
||||
return EulerAngles<T>(FromRadians(std::atan2(T(2.0) * x * w - T(2.0) * y * z, T(1.0) - T(2.0) * x * x - T(2.0) * z * z)),
|
||||
FromRadians(std::atan2(T(2.0) * y * w - T(2.0) * x * z, T(1.0) - T(2.0) * y * y - T(2.0) * z * z)),
|
||||
FromRadians(std::asin(T(2.0) * test)));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -507,11 +505,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Quaternion<T>::ToString() const
|
||||
std::string Quaternion<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -565,8 +564,8 @@ namespace Nz
|
||||
Vector3<T> quatVec(x, y, z);
|
||||
Vector3<T> uv = quatVec.CrossProduct(vec);
|
||||
Vector3<T> uuv = quatVec.CrossProduct(uv);
|
||||
uv *= F(2.0) * w;
|
||||
uuv *= F(2.0);
|
||||
uv *= T(2.0) * w;
|
||||
uuv *= T(2.0);
|
||||
|
||||
return vec + uv + uuv;
|
||||
}
|
||||
@@ -715,9 +714,9 @@ namespace Nz
|
||||
Quaternion<T> Quaternion<T>::Lerp(const Quaternion& from, const Quaternion& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
@@ -784,9 +783,9 @@ namespace Nz
|
||||
Quaternion<T> Quaternion<T>::Slerp(const Quaternion& from, const Quaternion& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
@@ -794,7 +793,7 @@ namespace Nz
|
||||
Quaternion q;
|
||||
|
||||
T cosOmega = from.DotProduct(to);
|
||||
if (cosOmega < F(0.0))
|
||||
if (cosOmega < T(0.0))
|
||||
{
|
||||
// We invert everything
|
||||
q.Set(-to.w, -to.x, -to.y, -to.z);
|
||||
@@ -804,21 +803,21 @@ namespace Nz
|
||||
q.Set(to);
|
||||
|
||||
T k0, k1;
|
||||
if (cosOmega > F(0.9999))
|
||||
if (cosOmega > T(0.9999))
|
||||
{
|
||||
// Linear interpolation to avoid division by zero
|
||||
k0 = F(1.0) - interpolation;
|
||||
k0 = T(1.0) - interpolation;
|
||||
k1 = interpolation;
|
||||
}
|
||||
else
|
||||
{
|
||||
T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega);
|
||||
T sinOmega = std::sqrt(T(1.0) - cosOmega*cosOmega);
|
||||
T omega = std::atan2(sinOmega, cosOmega);
|
||||
|
||||
// To avoid two divisions
|
||||
sinOmega = F(1.0)/sinOmega;
|
||||
sinOmega = T(1.0)/sinOmega;
|
||||
|
||||
k0 = std::sin((F(1.0) - interpolation) * omega) * sinOmega;
|
||||
k0 = std::sin((T(1.0) - interpolation) * omega) * sinOmega;
|
||||
k1 = std::sin(interpolation*omega) * sinOmega;
|
||||
}
|
||||
|
||||
@@ -905,9 +904,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Quaternion<T>& quat)
|
||||
{
|
||||
return out << quat.ToString();
|
||||
return out << "Quaternion(" << quat.w << " | " << quat.x << ", " << quat.y << ", " << quat.z << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#ifndef NAZARA_RAY_HPP
|
||||
#define NAZARA_RAY_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
@@ -15,6 +14,7 @@
|
||||
#include <Nazara/Math/Plane.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace Nz
|
||||
template<typename U> Ray& Set(const Ray<U>& ray);
|
||||
template<typename U> Ray& Set(const Vector3<U>& origin, const Vector3<U>& direction);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Vector3<T> operator*(T lambda) const;
|
||||
Ray& operator=(const Ray& other) = default;
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -166,7 +164,7 @@ namespace Nz
|
||||
case Extend_Infinite:
|
||||
{
|
||||
if (closestHit)
|
||||
*closestHit = F(0.0);
|
||||
*closestHit = T(0.0);
|
||||
|
||||
if (furthestHit)
|
||||
*furthestHit = std::numeric_limits<T>::infinity();
|
||||
@@ -178,7 +176,7 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -197,7 +195,7 @@ namespace Nz
|
||||
bool Ray<T>::Intersect(const Box<T>& box, T* closestHit, T* furthestHit) const
|
||||
{
|
||||
// http://www.gamedev.net/topic/429443-obb-ray-and-obb-plane-intersection/
|
||||
T tfirst = F(0.0);
|
||||
T tfirst = T(0.0);
|
||||
T tlast = std::numeric_limits<T>::infinity();
|
||||
|
||||
Vector3<T> boxMin = box.GetMinimum();
|
||||
@@ -210,7 +208,7 @@ namespace Nz
|
||||
T max = boxMax[i];
|
||||
T min = boxMin[i];
|
||||
|
||||
if (NumberEquals(dir, F(0.0)))
|
||||
if (NumberEquals(dir, T(0.0)))
|
||||
{
|
||||
if (ori < max && ori > min)
|
||||
continue;
|
||||
@@ -256,7 +254,7 @@ namespace Nz
|
||||
{
|
||||
// http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-custom-ray-obb-function/
|
||||
// Intersection method from Real-Time Rendering and Essential Mathematics for Games
|
||||
T tMin = F(0.0);
|
||||
T tMin = T(0.0);
|
||||
T tMax = std::numeric_limits<T>::infinity();
|
||||
|
||||
Vector3<T> boxMin = box.GetMinimum();
|
||||
@@ -270,7 +268,7 @@ namespace Nz
|
||||
T e = axis.DotProduct(delta);
|
||||
T f = direction.DotProduct(axis);
|
||||
|
||||
if (!NumberEquals(f, F(0.0)))
|
||||
if (!NumberEquals(f, T(0.0)))
|
||||
{
|
||||
T t1 = (e + boxMin[i]) / f; // Intersection with the "left" plane
|
||||
T t2 = (e + boxMax[i]) / f; // Intersection with the "right" plane
|
||||
@@ -296,7 +294,7 @@ namespace Nz
|
||||
}
|
||||
else
|
||||
// Rare case : the ray is almost parallel to the planes, so they don't have any "intersection"
|
||||
if (-e + boxMin[i] > F(0.0) || -e + boxMax[i] < F(0.0))
|
||||
if (-e + boxMin[i] > T(0.0) || -e + boxMax[i] < T(0.0))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -334,7 +332,7 @@ namespace Nz
|
||||
Matrix4<T> matrix(width.x, height.x, depth.x, corner.x,
|
||||
width.y, height.y, depth.y, corner.y,
|
||||
width.z, height.z, depth.z, corner.z,
|
||||
F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
|
||||
matrix.InverseAffine();
|
||||
|
||||
@@ -361,11 +359,11 @@ namespace Nz
|
||||
bool Ray<T>::Intersect(const Plane<T>& plane, T* hit) const
|
||||
{
|
||||
T divisor = plane.normal.DotProduct(direction);
|
||||
if (NumberEquals(divisor, F(0.0)))
|
||||
if (NumberEquals(divisor, T(0.0)))
|
||||
return false; // Perpendicular
|
||||
|
||||
T lambda = -(plane.normal.DotProduct(origin) - plane.distance) / divisor; // The plane is ax + by + cz = d
|
||||
if (lambda < F(0.0))
|
||||
if (lambda < T(0.0))
|
||||
return false; // The plane is 'behind' the ray.
|
||||
|
||||
if (hit)
|
||||
@@ -391,7 +389,7 @@ namespace Nz
|
||||
Vector3<T> sphereRay = sphere.GetPosition() - origin;
|
||||
T length = sphereRay.DotProduct(direction);
|
||||
|
||||
if (length < F(0.0))
|
||||
if (length < T(0.0))
|
||||
return false; // ray is perpendicular to the vector origin - center
|
||||
|
||||
T squaredDistance = sphereRay.GetSquaredLength() - length * length;
|
||||
@@ -436,21 +434,21 @@ namespace Nz
|
||||
|
||||
Vector3<T> P = Vector3<T>::CrossProduct(direction, secondEdge);
|
||||
const T divisor = firstEdge.DotProduct(P);
|
||||
if (NumberEquals(divisor, F(0.0)))
|
||||
if (NumberEquals(divisor, T(0.0)))
|
||||
return false; // Ray lies in plane of triangle
|
||||
|
||||
Vector3<T> directionToPoint = origin - firstPoint;
|
||||
T u = directionToPoint.DotProduct(P) / divisor;
|
||||
if (u < F(0.0) || u > F(1.0))
|
||||
if (u < T(0.0) || u > T(1.0))
|
||||
return 0; // The intersection lies outside of the triangle
|
||||
|
||||
Vector3<T> Q = Vector3<T>::CrossProduct(directionToPoint, firstEdge);
|
||||
T v = directionToPoint.DotProduct(Q) / divisor;
|
||||
if (v < F(0.0) || u + v > F(1.0))
|
||||
if (v < T(0.0) || u + v > T(1.0))
|
||||
return 0; // The intersection lies outside of the triangle
|
||||
|
||||
T t = secondEdge.DotProduct(Q) / divisor;
|
||||
if (t > F(0.0))
|
||||
if (t > T(0.0))
|
||||
{
|
||||
if (hit)
|
||||
*hit = t;
|
||||
@@ -574,16 +572,16 @@ namespace Nz
|
||||
T det = termOne * termFour - termTwo * termTwo;
|
||||
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(det, F(0.0)))
|
||||
if (NumberEquals(det, T(0.0)))
|
||||
{
|
||||
String error("Planes are parallel");
|
||||
std::string error("Planes are parallel");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
throw std::domain_error(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
T invdet = F(1.0) / det;
|
||||
T invdet = T(1.0) / det;
|
||||
T fc0 = (termFour * -planeOne.distance + termTwo * planeTwo.distance) * invdet;
|
||||
T fc1 = (termOne * -planeTwo.distance + termTwo * planeOne.distance) * invdet;
|
||||
|
||||
@@ -634,11 +632,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Ray<T>::ToString() const
|
||||
std::string Ray<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Ray(origin: " << origin.ToString() << ", direction: " << direction.ToString() << ")";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -799,9 +798,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Ray<T>& ray)
|
||||
{
|
||||
return out << ray.ToString();
|
||||
return out << "Ray(origin: " << ray.origin << ", direction: " << ray.direction << ")";
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#ifndef NAZARA_RECT_HPP
|
||||
#define NAZARA_RECT_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace Nz
|
||||
Rect& Set(const Vector2<T>& vec1, const Vector2<T>& vec2);
|
||||
template<typename U> Rect& Set(const Rect<U>& rect);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Rect& Translate(const Vector2<T>& translation);
|
||||
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -224,7 +222,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector2<T> Rect<T>::GetCenter() const
|
||||
{
|
||||
return GetPosition() + GetLengths() / F(2.0);
|
||||
return GetPosition() + GetLengths() / T(2.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -254,7 +252,7 @@ namespace Nz
|
||||
return Vector2<T>(x + width, y);
|
||||
}
|
||||
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
return Vector2<T>();
|
||||
}
|
||||
|
||||
@@ -309,10 +307,10 @@ namespace Nz
|
||||
{
|
||||
Vector2<T> neg(GetPosition());
|
||||
|
||||
if (normal.x < F(0.0))
|
||||
if (normal.x < T(0.0))
|
||||
neg.x += width;
|
||||
|
||||
if (normal.y < F(0.0))
|
||||
if (normal.y < T(0.0))
|
||||
neg.y += height;
|
||||
|
||||
return neg;
|
||||
@@ -345,10 +343,10 @@ namespace Nz
|
||||
{
|
||||
Vector2<T> pos(GetPosition());
|
||||
|
||||
if (normal.x > F(0.0))
|
||||
if (normal.x > T(0.0))
|
||||
pos.x += width;
|
||||
|
||||
if (normal.y > F(0.0))
|
||||
if (normal.y > T(0.0))
|
||||
pos.y += height;
|
||||
|
||||
return pos;
|
||||
@@ -394,7 +392,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
bool Rect<T>::IsValid() const
|
||||
{
|
||||
return width > F(0.0) && height > F(0.0);
|
||||
return width > T(0.0) && height > T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -407,10 +405,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Rect<T>& Rect<T>::MakeZero()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
width = F(0.0);
|
||||
height = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
width = T(0.0);
|
||||
height = T(0.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -428,8 +426,8 @@ namespace Nz
|
||||
template<typename T>
|
||||
Rect<T>& Rect<T>::Set(T Width, T Height)
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
width = Width;
|
||||
height = Height;
|
||||
|
||||
@@ -521,10 +519,10 @@ namespace Nz
|
||||
template<typename U>
|
||||
Rect<T>& Rect<T>::Set(const Rect<U>& rect)
|
||||
{
|
||||
x = F(rect.x);
|
||||
y = F(rect.y);
|
||||
width = F(rect.width);
|
||||
height = F(rect.height);
|
||||
x = T(rect.x);
|
||||
y = T(rect.y);
|
||||
width = T(rect.width);
|
||||
height = T(rect.height);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -535,11 +533,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Rect<T>::ToString() const
|
||||
std::string Rect<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Rect(" << x << ", " << y << ", " << width << ", " << height << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -753,9 +752,9 @@ namespace Nz
|
||||
Rect<T> Rect<T>::Lerp(const Rect& from, const Rect& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
@@ -847,9 +846,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Rect<T>& rect)
|
||||
{
|
||||
return out << rect.ToString();
|
||||
return out << "Rect(" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#ifndef NAZARA_SPHERE_HPP
|
||||
#define NAZARA_SPHERE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace Nz
|
||||
Sphere& Set(const T sphere[4]);
|
||||
template<typename U> Sphere& Set(const Sphere<U>& sphere);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -306,7 +304,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
bool Sphere<T>::IsValid() const
|
||||
{
|
||||
return radius > F(0.0);
|
||||
return radius > T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -319,10 +317,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Sphere<T>& Sphere<T>::MakeUnit()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
radius = F(1.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
radius = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -337,10 +335,10 @@ namespace Nz
|
||||
template<typename T>
|
||||
Sphere<T>& Sphere<T>::MakeZero()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
radius = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
radius = T(0.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -390,7 +388,7 @@ namespace Nz
|
||||
{
|
||||
x = circle.x;
|
||||
y = circle.y;
|
||||
z = F(0.0);
|
||||
z = T(0.0);
|
||||
radius = circle.radius;
|
||||
|
||||
return *this;
|
||||
@@ -426,10 +424,10 @@ namespace Nz
|
||||
template<typename U>
|
||||
Sphere<T>& Sphere<T>::Set(const Sphere<U>& sphere)
|
||||
{
|
||||
x = F(sphere.x);
|
||||
y = F(sphere.y);
|
||||
z = F(sphere.z);
|
||||
radius = F(sphere.radius);
|
||||
x = T(sphere.x);
|
||||
y = T(sphere.y);
|
||||
z = T(sphere.z);
|
||||
radius = T(sphere.radius);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -440,11 +438,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Sphere<T>::ToString() const
|
||||
std::string Sphere<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Sphere(" << x << ", " << y << ", " << z << "; " << radius << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -568,9 +567,9 @@ namespace Nz
|
||||
Sphere<T> Sphere<T>::Lerp(const Sphere& from, const Sphere& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
@@ -662,9 +661,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Sphere<T>& sphere)
|
||||
{
|
||||
return out << sphere.ToString();
|
||||
return out << "Sphere(" << sphere.x << ", " << sphere.y << ", " << sphere.z << "; " << sphere.radius << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#ifndef NAZARA_VECTOR2_HPP
|
||||
#define NAZARA_VECTOR2_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -61,7 +63,7 @@ namespace Nz
|
||||
|
||||
T SquaredDistance(const Vector2& vec) const;
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -212,7 +210,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeUnit()
|
||||
{
|
||||
return Set(F(1.0), F(1.0));
|
||||
return Set(T(1.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -225,7 +223,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeUnitX()
|
||||
{
|
||||
return Set(F(1.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -238,7 +236,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeUnitY()
|
||||
{
|
||||
return Set(F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -251,7 +249,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -311,9 +309,9 @@ namespace Nz
|
||||
Vector2<T>& Vector2<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = GetLength();
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
T invNorm = T(1.0) / norm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
}
|
||||
@@ -383,8 +381,8 @@ namespace Nz
|
||||
template<typename U>
|
||||
Vector2<T>& Vector2<T>::Set(const Vector2<U>& vec)
|
||||
{
|
||||
x = F(vec.x);
|
||||
y = F(vec.y);
|
||||
x = T(vec.x);
|
||||
y = T(vec.y);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -442,11 +440,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Vector2<T>::ToString() const
|
||||
std::string Vector2<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Vector2(" << x << ", " << y << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -550,24 +549,11 @@ namespace Nz
|
||||
* \return A vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T> Vector2<T>::operator/(const Vector2& vec) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector2(x / vec.x, y / vec.y);
|
||||
}
|
||||
|
||||
@@ -576,24 +562,11 @@ namespace Nz
|
||||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T> Vector2<T>::operator/(T scale) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector2(x / scale, y / scale);
|
||||
}
|
||||
|
||||
@@ -666,24 +639,11 @@ namespace Nz
|
||||
* \return A reference to this vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to multiply components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::operator/=(const Vector2& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
|
||||
@@ -695,24 +655,11 @@ namespace Nz
|
||||
* \return A reference to this vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::operator/=(T scale)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= scale;
|
||||
y /= scale;
|
||||
|
||||
@@ -990,7 +937,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Vector2<T>& vec)
|
||||
{
|
||||
return out << vec.ToString();
|
||||
return out << "Vector2(" << vec.x << ", " << vec.y << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1011,24 +958,11 @@ Nz::Vector2<T> operator*(T scale, const Nz::Vector2<T>& vec)
|
||||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (Nz::NumberEquals(vec.x, F(0.0)) || Nz::NumberEquals(vec.y, F(0.0)))
|
||||
{
|
||||
Nz::String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Nz::Vector2<T>(scale / vec.x, scale / vec.y);
|
||||
}
|
||||
|
||||
@@ -1054,7 +988,5 @@ namespace std
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#ifndef NAZARA_VECTOR3_HPP
|
||||
#define NAZARA_VECTOR3_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -72,7 +74,7 @@ namespace Nz
|
||||
|
||||
T SquaredDistance(const Vector3& vec) const;
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
@@ -126,17 +124,17 @@ namespace Nz
|
||||
T divisor = std::sqrt(GetSquaredLength() * vec.GetSquaredLength());
|
||||
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(divisor, F(0.0)))
|
||||
if (NumberEquals(divisor, T(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
std::string error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
throw std::domain_error(std::move(error));
|
||||
}
|
||||
#endif
|
||||
|
||||
T alpha = DotProduct(vec) / divisor;
|
||||
return FromRadians(std::acos(Clamp(alpha, F(-1.0), F(1.0))));
|
||||
return FromRadians(std::acos(Clamp(alpha, T(-1.0), T(1.0))));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -244,7 +242,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeBackward()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -256,7 +254,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeDown()
|
||||
{
|
||||
return Set(F(0.0), F(-1.0), F(0.0));
|
||||
return Set(T(0.0), T(-1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -268,7 +266,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeForward()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(-1.0));
|
||||
return Set(T(0.0), T(0.0), T(-1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -280,7 +278,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeLeft()
|
||||
{
|
||||
return Set(F(-1.0), F(0.0), F(0.0));
|
||||
return Set(T(-1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -292,7 +290,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeRight()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -304,7 +302,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnit()
|
||||
{
|
||||
return Set(F(1.0), F(1.0), F(1.0));
|
||||
return Set(T(1.0), T(1.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -316,7 +314,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnitX()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -328,7 +326,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnitY()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -340,7 +338,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnitZ()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -352,7 +350,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUp()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -364,7 +362,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -427,9 +425,9 @@ namespace Nz
|
||||
Vector3<T>& Vector3<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = GetLength();
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
T invNorm = T(1.0) / norm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
z *= invNorm;
|
||||
@@ -533,9 +531,9 @@ namespace Nz
|
||||
template<typename U>
|
||||
Vector3<T>& Vector3<T>::Set(const Vector3<U>& vec)
|
||||
{
|
||||
x = F(vec.x);
|
||||
y = F(vec.y);
|
||||
z = F(vec.z);
|
||||
x = T(vec.x);
|
||||
y = T(vec.y);
|
||||
z = T(vec.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -575,11 +573,12 @@ namespace Nz
|
||||
* \return A string representation of the object: "Vector3(x, y, z)"
|
||||
*/
|
||||
template<typename T>
|
||||
String Vector3<T>::ToString() const
|
||||
std::string Vector3<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Vector3(" << x << ", " << y << ", " << z <<')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -677,23 +676,10 @@ namespace Nz
|
||||
* \return A vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T> Vector3<T>::operator/(const Vector3& vec) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector3(x / vec.x, y / vec.y, z / vec.z);
|
||||
}
|
||||
|
||||
@@ -702,23 +688,10 @@ namespace Nz
|
||||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T> Vector3<T>::operator/(T scale) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector3(x / scale, y / scale, z / scale);
|
||||
}
|
||||
|
||||
@@ -791,21 +764,10 @@ namespace Nz
|
||||
* \return A reference to this vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to multiply components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::operator/=(const Vector3& vec)
|
||||
{
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
z /= vec.z;
|
||||
@@ -818,21 +780,10 @@ namespace Nz
|
||||
* \return A reference to this vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::operator/=(T scale)
|
||||
{
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
|
||||
x /= scale;
|
||||
y /= scale;
|
||||
z /= scale;
|
||||
@@ -1253,7 +1204,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Vector3<T>& vec)
|
||||
{
|
||||
return out << vec.ToString();
|
||||
return out << "Vector3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1274,24 +1225,11 @@ Nz::Vector3<T> operator*(T scale, const Nz::Vector3<T>& vec)
|
||||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Nz::Vector3<T> operator/(T scale, const Nz::Vector3<T>& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (Nz::NumberEquals(vec.x, F(0.0)) || Nz::NumberEquals(vec.y, F(0.0)) || Nz::NumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
Nz::String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Nz::Vector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
|
||||
}
|
||||
|
||||
@@ -1320,6 +1258,4 @@ namespace std
|
||||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#ifndef NAZARA_VECTOR4_HPP
|
||||
#define NAZARA_VECTOR4_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -59,7 +61,7 @@ namespace Nz
|
||||
Vector4& Set(const Vector3<T>& vec, T W = 1.0);
|
||||
template<typename U> Vector4& Set(const Vector4<U>& vec);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
||||
@@ -3,16 +3,14 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -188,7 +186,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeUnitX()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -201,7 +199,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeUnitY()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -214,7 +212,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeUnitZ()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -227,7 +225,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -296,7 +294,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::Normalize(T* length)
|
||||
{
|
||||
T invLength = F(1.0)/w;
|
||||
T invLength = T(1.0)/w;
|
||||
x *= invLength; // Warning, change this logic will break Frustum::Extract
|
||||
y *= invLength;
|
||||
z *= invLength;
|
||||
@@ -304,7 +302,7 @@ namespace Nz
|
||||
if (length)
|
||||
*length = w;
|
||||
|
||||
w = F(1.0);
|
||||
w = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -472,10 +470,10 @@ namespace Nz
|
||||
template<typename U>
|
||||
Vector4<T>& Vector4<T>::Set(const Vector4<U>& vec)
|
||||
{
|
||||
x = F(vec.x);
|
||||
y = F(vec.y);
|
||||
z = F(vec.z);
|
||||
w = F(vec.w);
|
||||
x = T(vec.x);
|
||||
y = T(vec.y);
|
||||
z = T(vec.z);
|
||||
w = T(vec.w);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -486,11 +484,12 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
String Vector4<T>::ToString() const
|
||||
std::string Vector4<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -594,24 +593,11 @@ namespace Nz
|
||||
* \return A vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T> Vector4<T>::operator/(const Vector4& vec) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w);
|
||||
}
|
||||
|
||||
@@ -620,24 +606,11 @@ namespace Nz
|
||||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T> Vector4<T>::operator/(T scale) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector4(x / scale, y / scale, z / scale, w / scale);
|
||||
}
|
||||
|
||||
@@ -718,24 +691,11 @@ namespace Nz
|
||||
* \return A reference to this vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to multiply components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::operator/=(const Vector4& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
z /= vec.z;
|
||||
@@ -749,24 +709,11 @@ namespace Nz
|
||||
* \return A reference to this vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::operator/=(T scale)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= scale;
|
||||
y /= scale;
|
||||
z /= scale;
|
||||
@@ -1062,7 +1009,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Vector4<T>& vec)
|
||||
{
|
||||
return out << vec.ToString();
|
||||
return out << "Vector4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1084,24 +1031,11 @@ Nz::Vector4<T> operator*(T scale, const Nz::Vector4<T>& vec)
|
||||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Nz::Vector4<T> operator/(T scale, const Nz::Vector4<T>& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0)))
|
||||
{
|
||||
Nz::String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Nz::Vector4<T>(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w);
|
||||
}
|
||||
|
||||
@@ -1130,6 +1064,4 @@ namespace std
|
||||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user