General bug fixes (#142)

* Core/Bitset: Fix TestAll method

* Fix documentation

* Fix color and their conversions

* Core/ByteStream: Fix return of Write

* Fix compiler warnings

* Math/Algorithm: Fix angle normalization

* Math/BoundingVolume: Fix lerp

* Math: Fix relation between Matrix4 and Quaternion

* More tests

* X11/Window: Fix mouse moved event generated when doing Mouse::SetPosition

* Update ChangeLog

* Should fix compilation on Windows

* Should fix compilation on Windows

Forgot to include array for Windows
This commit is contained in:
Gawaboumga
2017-11-21 12:16:46 +01:00
committed by Jérôme Leclercq
parent f2506ee918
commit f991a9529e
52 changed files with 1287 additions and 272 deletions

View File

@@ -552,11 +552,11 @@ namespace Nz
#endif
const T twoLimit = limit * T(2);
angle = std::fmod(angle + limit, twoLimit);
angle = std::fmod(angle, twoLimit);
if (angle < T(0))
angle += twoLimit;
return angle - limit;
return angle;
}
/*!

View File

@@ -541,7 +541,7 @@ namespace Nz
return Infinite();
case Extend_Null:
return from.obb * interpolation;
return to.obb * interpolation;
}
// If we arrive here, the extend is invalid

View File

@@ -77,7 +77,6 @@ namespace Nz
/*!
* \brief Makes the euler angle (0, 0, 0)
* \return A reference to this euler angle with components (0, 0, 0)
*
* \see Zero
*/
@@ -276,7 +275,7 @@ namespace Nz
* \brief Substracts the components of other euler angle to this euler angle
* \return A reference to this euler angle where components are the difference of this euler angle and the other one
*
* \param angle The other euler angle to substract components with
* \param angles The other euler angle to substract components with
*/
template<typename T>

View File

@@ -664,9 +664,9 @@ namespace Nz
template<typename T>
Vector3<T> Matrix4<T>::GetSquaredScale() const
{
return Vector3<T>(m11*m11 + m21*m21 + m31*m31,
m12*m12 + m22*m22 + m32*m32,
m13*m13 + m23*m23 + m33*m33);
return Vector3<T>(m11 * m11 + m12 * m12 + m13 * m13,
m21 * m21 + m22 * m22 + m23 * m23,
m31 * m31 + m32 * m32 + m33 * m33);
}
/*!
@@ -1153,36 +1153,32 @@ namespace Nz
*
* \param rotation Quaternion representing a rotation of space
*
* \remark 3rd column and row are unchanged
* \remark 3rd column and row are unchanged. Scale is removed.
*/
template<typename T>
Matrix4<T>& Matrix4<T>::SetRotation(const Quaternion<T>& rotation)
{
T tx = rotation.x + rotation.x;
T ty = rotation.y + rotation.y;
T tz = rotation.z + rotation.z;
T twx = tx * rotation.w;
T twy = ty * rotation.w;
T twz = tz * rotation.w;
T txx = tx * rotation.x;
T txy = ty * rotation.x;
T txz = tz * rotation.x;
T tyy = ty * rotation.y;
T tyz = tz * rotation.y;
T tzz = tz * rotation.z;
T qw = rotation.w;
T qx = rotation.x;
T qy = rotation.y;
T qz = rotation.z;
m11 = F(1.0) - (tyy + tzz);
m12 = txy + twz;
m13 = txz - twy;
T qx2 = qx * qx;
T qy2 = qy * qy;
T qz2 = qz * qz;
m21 = txy - twz;
m22 = F(1.0) - (txx + tzz);
m23 = tyz + twx;
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;
m31 = txz + twy;
m32 = tyz - twx;
m33 = F(1.0) - (txx + tyy);
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;
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;
return *this;
}

View File

@@ -106,9 +106,9 @@ namespace Nz
* \brief Returns the distance from the plane to the point
* \return Distance to the point
*
* \param X X position of the point
* \param Y Y position of the point
* \param Z Z position of the point
* \param x X position of the point
* \param y Y position of the point
* \param z Z position of the point
*
* \remark If T is negative, it means that the point is in the opposite direction of the normal
*
@@ -319,7 +319,7 @@ namespace Nz
* \brief Compares the plane to other one
* \return true if the planes are the same
*
* \param vec Other vector to compare with
* \param plane Other vector to compare with
*
* \remark Plane with normal N and distance D is the same than with normal -N et distance -D
*/

View File

@@ -251,35 +251,19 @@ namespace Nz
* \param from Initial vector
* \param to Target vector
*
* \remark Vectors are not required to be normalized
*
* \see RotationBetween
*/
template<typename T>
Quaternion<T>& Quaternion<T>::MakeRotationBetween(const Vector3<T>& from, const Vector3<T>& to)
{
// TODO (Gawaboumga): Replace by http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors ?
T dot = from.DotProduct(to);
if (NumberEquals(dot, F(-1.0)))
{
Vector3<T> cross = Vector3<T>::CrossProduct(Vector3<T>::UnitX(), from);
if (NumberEquals(cross.GetLength(), F(0.0)))
cross = Vector3<T>::CrossProduct(Vector3<T>::UnitY(), from);
return Set(F(180.0), cross);
}
else if (NumberEquals(dot, F(1.0)))
return MakeIdentity();
else
{
Vector3<T> a = from.CrossProduct(to);
x = a.x;
y = a.y;
z = a.z;
w = T(1.0) + dot;
return Normalize();
}
// Based on: http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
T norm = std::sqrt(from.GetSquaredLength() * to.GetSquaredLength());
Vector3<T> crossProduct = from.CrossProduct(to);
Set(norm + from.DotProduct(to), crossProduct.x, crossProduct.y, crossProduct.z);
return Normalize();
}
/*!
@@ -425,7 +409,7 @@ namespace Nz
* \brief Sets the components of the quaternion from another quaternion
* \return A reference to this quaternion
*
* \param vec The other quaternion
* \param quat The other quaternion
*/
template<typename T>
@@ -647,7 +631,7 @@ namespace Nz
* \brief Compares the quaternion to other one
* \return true if the quaternions are the same
*
* \param vec Other quaternion to compare with
* \param quat Other quaternion to compare with
*/
template<typename T>
@@ -663,7 +647,7 @@ namespace Nz
* \brief Compares the quaternion to other one
* \return false if the quaternions are the same
*
* \param vec Other quaternion to compare with
* \param quat Other quaternion to compare with
*/
template<typename T>

View File

@@ -500,7 +500,7 @@ namespace Nz
* \brief Multiplies the radius of the sphere with a scalar
* \return A sphere where the center is the same and radius is the product of this radius and the scalar
*
* \param scale The scalar to multiply radius with
* \param scalar The scalar to multiply radius with
*/
template<typename T>
@@ -513,7 +513,7 @@ namespace Nz
* \brief Multiplies the radius of other sphere with a scalar
* \return A reference to this sphere where the center is the same and radius is the product of this radius and the scalar
*
* \param scale The scalar to multiply radius with
* \param scalar The scalar to multiply radius with
*/
template<typename T>

View File

@@ -692,7 +692,7 @@ namespace Nz
* \brief Multiplies the components of other vector with a scalar
* \return A reference to this vector where components are the product of this vector and the scalar
*
* \param vec The other vector to multiply components with
* \param scale The scalar to multiply components with
*/
template<typename T>
@@ -737,7 +737,7 @@ namespace Nz
* \brief Divides the components of other vector with a scalar
* \return A reference to this vector where components are the quotient of this vector and the scalar
*
* \param vec The other vector to divide components with
* \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

View File

@@ -810,7 +810,7 @@ namespace Nz
* \brief Multiplies the components of other vector with a scalar
* \return A reference to this vector where components are the product of this vector and the scalar
*
* \param vec The other vector to multiply components with
* \param scale The scalar to multiply components with
*/
template<typename T>
Vector3<T>& Vector3<T>::operator*=(T scale)
@@ -853,7 +853,7 @@ namespace Nz
* \brief Divides the components of other vector with a scalar
* \return A reference to this vector where components are the quotient of this vector and the scalar
*
* \param vec The other vector to divide components with
* \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

View File

@@ -728,7 +728,7 @@ namespace Nz
* \brief Multiplies the components of other vector with a scalar
* \return A reference to this vector where components are the product of this vector and the scalar
*
* \param vec The other vector to multiply components with
* \param scale The scalar to multiply components with
*/
template<typename T>
@@ -777,7 +777,7 @@ namespace Nz
* \brief Divides the components of other vector with a scalar
* \return A reference to this vector where components are the quotient of this vector and the scalar
*
* \param vec The other vector to divide components with
* \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