From 830eee78a80bb81ad87775244c7a400b07cd5005 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 18 Dec 2022 14:57:14 +0100 Subject: [PATCH] Math: Rework Box and Rect classes --- examples/GraphicsTest/main.cpp | 2 +- examples/PhysicallyBasedRendering/main.cpp | 2 +- examples/Physics2DDemo/main.cpp | 2 +- include/Nazara/Graphics/Camera.inl | 2 +- .../Nazara/Graphics/LinearSlicedSprite.inl | 4 +- include/Nazara/Graphics/SlicedSprite.inl | 4 +- include/Nazara/Graphics/SpotLight.inl | 2 +- include/Nazara/Graphics/Sprite.inl | 9 +- include/Nazara/Graphics/TextSprite.hpp | 7 - include/Nazara/Math/BoundingVolume.inl | 6 +- include/Nazara/Math/Box.hpp | 28 +- include/Nazara/Math/Box.inl | 368 +++++------------- include/Nazara/Math/OrientedBox.inl | 4 +- include/Nazara/Math/Rect.hpp | 29 +- include/Nazara/Math/Rect.inl | 353 ++++------------- include/Nazara/Utility/AbstractImage.inl | 2 +- include/Nazara/Widgets/Canvas.inl | 2 +- src/Nazara/Graphics/BakedFrameGraph.cpp | 2 +- src/Nazara/Graphics/LinearSlicedSprite.cpp | 2 +- src/Nazara/Graphics/SlicedSprite.cpp | 2 +- src/Nazara/Physics3D/Collider3D.cpp | 2 +- src/Nazara/Utility/AlgorithmUtility.cpp | 30 +- src/Nazara/Utility/Formats/MD5AnimParser.cpp | 2 +- src/Nazara/Utility/GuillotineImageAtlas.cpp | 2 +- src/Nazara/Utility/Mesh.cpp | 4 +- src/Nazara/Utility/RichTextDrawer.cpp | 4 +- src/Nazara/Utility/SimpleTextDrawer.cpp | 4 +- src/Nazara/Utility/Skeleton.cpp | 4 +- 28 files changed, 242 insertions(+), 642 deletions(-) diff --git a/examples/GraphicsTest/main.cpp b/examples/GraphicsTest/main.cpp index d9d8d9691..fbdc7d150 100644 --- a/examples/GraphicsTest/main.cpp +++ b/examples/GraphicsTest/main.cpp @@ -93,7 +93,7 @@ int main() Nz::WorldInstancePtr modelInstance2 = std::make_shared(); modelInstance2->UpdateWorldMatrix(Nz::Matrix4f::Translate(Nz::Vector3f::Forward() * 2 + Nz::Vector3f::Right())); - Nz::Recti scissorBox(Nz::Vector2i(window.GetSize())); + Nz::Recti scissorBox(Nz::Vector2i::Zero(), Nz::Vector2i(window.GetSize())); Nz::ElementRendererRegistry elementRegistry; Nz::ForwardFramePipeline framePipeline(elementRegistry); diff --git a/examples/PhysicallyBasedRendering/main.cpp b/examples/PhysicallyBasedRendering/main.cpp index 8afcdb2f1..41007a4b0 100644 --- a/examples/PhysicallyBasedRendering/main.cpp +++ b/examples/PhysicallyBasedRendering/main.cpp @@ -84,7 +84,7 @@ int main() Nz::WorldInstancePtr modelInstance = std::make_shared(); modelInstance->UpdateWorldMatrix(Nz::Matrix4f::Translate(Nz::Vector3f::Forward() * 2 + Nz::Vector3f::Left())); - Nz::Recti scissorBox(Nz::Vector2i(window.GetSize())); + Nz::Recti scissorBox(Nz::Vector2i::Zero(), Nz::Vector2i(window.GetSize())); Nz::ElementRendererRegistry elementRegistry; Nz::ForwardFramePipeline framePipeline(elementRegistry); diff --git a/examples/Physics2DDemo/main.cpp b/examples/Physics2DDemo/main.cpp index bb274ab1d..4c9c18573 100644 --- a/examples/Physics2DDemo/main.cpp +++ b/examples/Physics2DDemo/main.cpp @@ -49,7 +49,7 @@ int main() std::string windowTitle = "Graphics Test"; Nz::RenderWindow& window = renderSystem.CreateWindow(device, Nz::VideoMode(1920, 1080), windowTitle); - Nz::Vector2ui windowSize = window.GetSize(); + Nz::Vector2f windowSize = Nz::Vector2f(window.GetSize()); physSytem.GetPhysWorld().SetGravity({ 0.f, -98.1f }); diff --git a/include/Nazara/Graphics/Camera.inl b/include/Nazara/Graphics/Camera.inl index e7fd95397..e61032712 100644 --- a/include/Nazara/Graphics/Camera.inl +++ b/include/Nazara/Graphics/Camera.inl @@ -238,7 +238,7 @@ namespace Nz m_aspectRatio = fViewport.width / fViewport.height; // Convert it back to int - m_viewport.Set(fViewport); + m_viewport = Recti(fViewport); m_viewerInstance.UpdateTargetSize(fViewport.GetLengths()); diff --git a/include/Nazara/Graphics/LinearSlicedSprite.inl b/include/Nazara/Graphics/LinearSlicedSprite.inl index 9bff80315..41eca55ef 100644 --- a/include/Nazara/Graphics/LinearSlicedSprite.inl +++ b/include/Nazara/Graphics/LinearSlicedSprite.inl @@ -150,8 +150,8 @@ namespace Nz inline void LinearSlicedSprite::SetTextureRect(const Rectf& textureRect) { - Vector2ui textureSize(GetTextureSize()); - return SetTextureCoords(textureRect / Vector2f(textureSize)); + Vector2f invTextureSize = 1.f / Vector2f(Vector2ui(GetTextureSize())); + return SetTextureCoords(Rectf(textureRect.x * invTextureSize.x, textureRect.y * invTextureSize.y, textureRect.width * invTextureSize.x, textureRect.height * invTextureSize.y)); } } diff --git a/include/Nazara/Graphics/SlicedSprite.inl b/include/Nazara/Graphics/SlicedSprite.inl index e404b2e92..97416a970 100644 --- a/include/Nazara/Graphics/SlicedSprite.inl +++ b/include/Nazara/Graphics/SlicedSprite.inl @@ -105,8 +105,8 @@ namespace Nz inline void SlicedSprite::SetTextureRect(const Rectf& textureRect) { - Vector2ui textureSize(GetTextureSize()); - return SetTextureCoords(textureRect / Vector2f(textureSize)); + Vector2f invTextureSize = 1.f / Vector2f(Vector2ui(GetTextureSize())); + return SetTextureCoords(Rectf(textureRect.x * invTextureSize.x, textureRect.y * invTextureSize.y, textureRect.width * invTextureSize.x, textureRect.height * invTextureSize.y)); } } diff --git a/include/Nazara/Graphics/SpotLight.inl b/include/Nazara/Graphics/SpotLight.inl index 1a996a0bf..b68df4953 100644 --- a/include/Nazara/Graphics/SpotLight.inl +++ b/include/Nazara/Graphics/SpotLight.inl @@ -140,7 +140,7 @@ namespace Nz inline void SpotLight::UpdateBoundingVolume() { // We make a box center in the origin - Boxf box(Vector3f::Zero()); + Boxf box = Boxf::Zero(); // We compute the other points Vector3f base(Vector3f::Forward() * m_radius); diff --git a/include/Nazara/Graphics/Sprite.inl b/include/Nazara/Graphics/Sprite.inl index 269ab3934..3bd825568 100644 --- a/include/Nazara/Graphics/Sprite.inl +++ b/include/Nazara/Graphics/Sprite.inl @@ -89,8 +89,6 @@ namespace Nz inline void Sprite::UpdateVertices() { - Boxf aabb(-1.f, -1.f, -1.f); - VertexStruct_XYZ_Color_UV* vertices = m_vertices.data(); std::array cornerExtent; @@ -107,15 +105,10 @@ namespace Nz vertices->position = Vector3f(m_size * cornerExtent[UnderlyingCast(corner)], 0.f) - originShift; vertices->uv = m_textureCoords.GetCorner(corner); - if (aabb.IsValid()) - aabb.ExtendTo(vertices->position); - else - aabb.Set(vertices->position); - vertices++; } - UpdateAABB(aabb); + UpdateAABB(Rectf(-originShift.x, -originShift.y, m_size.x, m_size.y)); OnElementInvalidated(this); } } diff --git a/include/Nazara/Graphics/TextSprite.hpp b/include/Nazara/Graphics/TextSprite.hpp index a65613271..37fbbef92 100644 --- a/include/Nazara/Graphics/TextSprite.hpp +++ b/include/Nazara/Graphics/TextSprite.hpp @@ -54,11 +54,6 @@ namespace Nz NazaraSlot(AbstractAtlas, OnAtlasRelease, releaseSlot); }; - struct RenderData - { - - }; - struct RenderKey { Texture* texture; @@ -93,9 +88,7 @@ namespace Nz std::unordered_map m_atlases; mutable std::unordered_map m_renderInfos; std::shared_ptr m_material; - std::vector m_data; std::vector m_vertices; - Recti m_scissorBox; }; } diff --git a/include/Nazara/Math/BoundingVolume.inl b/include/Nazara/Math/BoundingVolume.inl index c96bb50dd..a87b366de 100644 --- a/include/Nazara/Math/BoundingVolume.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -15,7 +15,7 @@ namespace Nz { /*! - * \ingroup math + * \ingroup math * \class Nz::BoundingVolume * \brief Math class that represents a bounding volume, a combination of a box and an oriented box * @@ -396,7 +396,7 @@ namespace Nz { obb.Update(transformMatrix); - aabb.Set(obb(0), obb(1)); + aabb = Boxf::FromExtends(obb(0), obb(1)); for (unsigned int i = 2; i < 8; ++i) aabb.ExtendTo(obb(i)); } @@ -412,7 +412,7 @@ namespace Nz { obb.Update(translation); - aabb.Set(obb(0), obb(1)); + aabb = Boxf::FromExtends(obb(0), obb(1)); for (unsigned int i = 2; i < 8; ++i) aabb.ExtendTo(obb(i)); } diff --git a/include/Nazara/Math/Box.hpp b/include/Nazara/Math/Box.hpp index adc378b60..b70ded60d 100644 --- a/include/Nazara/Math/Box.hpp +++ b/include/Nazara/Math/Box.hpp @@ -25,10 +25,8 @@ namespace Nz Box() = default; Box(T Width, T Height, T Depth); Box(T X, T Y, T Z, T Width, T Height, T Depth); - Box(const T box[6]); Box(const Rect& rect); - Box(const Vector3& lengths); - Box(const Vector3& vec1, const Vector3& vec2); + explicit Box(const Vector3& pos, const Vector3& lengths); template explicit Box(const Box& box); Box(const Box& box) = default; ~Box() = default; @@ -56,17 +54,11 @@ namespace Nz bool Intersect(const Box& box, Box* intersection = nullptr) const; + bool IsNull() const; bool IsValid() const; - Box& MakeZero(); - - Box& Set(T Width, T Height, T Depth); - Box& Set(T X, T Y, T Z, T Width, T Height, T Depth); - Box& Set(const T box[6]); - Box& Set(const Rect& rect); - Box& Set(const Vector3& lengths); - Box& Set(const Vector3& vec1, const Vector3& vec2); - template Box& Set(const Box& box); + Box& Scale(T scalar); + Box& Scale(const Vector3& vec); std::string ToString() const; @@ -74,19 +66,17 @@ namespace Nz Box& Translate(const Vector3& translation); T& operator[](std::size_t i); - T operator[](std::size_t i) const; + const T& operator[](std::size_t i) const; - Box operator*(T scalar) const; - Box operator*(const Vector3& vec) const; - Box& operator=(const Box& other) = default; - - Box& operator*=(T scalar); - Box& operator*=(const Vector3& vec); + Box& operator=(const Box&) = default; + Box& operator=(Box&&) = default; bool operator==(const Box& box) const; bool operator!=(const Box& box) const; + static Box FromExtends(const Vector3& vec1, const Vector3& vec2); static Box Lerp(const Box& from, const Box& to, T interpolation); + static Box Invalid(); static Box Zero(); T x, y, z, width, height, depth; diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index 806bba7e8..a47b858a9 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -29,9 +29,14 @@ namespace Nz */ template - Box::Box(T Width, T Height, T Depth) + Box::Box(T Width, T Height, T Depth) : + x(0), + y(0), + z(0), + width(Width), + height(Height), + depth(Depth) { - Set(Width, Height, Depth); } /*! @@ -44,23 +49,15 @@ namespace Nz * \param Height Height of the box (following Y) * \param Depth Depth of the box (following Z) */ - template - Box::Box(T X, T Y, T Z, T Width, T Height, T Depth) + Box::Box(T X, T Y, T Z, T Width, T Height, T Depth) : + x(X), + y(Y), + z(Z), + width(Width), + height(Height), + depth(Depth) { - Set(X, Y, Z, Width, Height, Depth); - } - - /*! - * \brief Constructs a Box object from an array of six elements - * - * \param vec[6] vec[0] is X position, vec[1] is Y position, vec[2] is Z position, vec[3] is width, vec[4] is height and vec[5] is depth - */ - - template - Box::Box(const T vec[6]) - { - Set(vec); } /*! @@ -70,39 +67,32 @@ namespace Nz * * \remark Z position is 0 and depth is 1 */ - template - Box::Box(const Rect& rect) + Box::Box(const Rect& rect) : + x(rect.x), + y(rect.y), + z(0), + width(rect.width), + height(rect.height), + depth(0) { - Set(rect); } /*! - * \brief Constructs a Box object from a vector representing width, height and depth + * \brief Constructs a Box object from two vector representing position and lengths * + * \param pos (X, Y, Z) of the box * \param lengths (Width, Height, Depth) of the box - * - * \remark Positions will be (0, 0, 0) */ - template - Box::Box(const Vector3& lengths) + Box::Box(const Vector3& pos, const Vector3& lengths) : + x(pos.x), + y(pos.y), + z(pos.z), + width(lengths.x), + height(lengths.y), + depth(lengths.z) { - Set(lengths); - } - - /*! - * \brief Constructs a Box object from two vectors representing point of the space - * (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum - * - * \param vec1 First point - * \param vec2 Second point - */ - - template - Box::Box(const Vector3& vec1, const Vector3& vec2) - { - Set(vec1, vec2); } /*! @@ -113,9 +103,14 @@ namespace Nz template template - Box::Box(const Box& box) + Box::Box(const Box& box) : + x(static_cast(box.x)), + y(static_cast(box.y)), + z(static_cast(box.z)), + width(static_cast(box.width)), + height(static_cast(box.height)), + depth(static_cast(box.depth)) { - Set(box); } /*! @@ -482,179 +477,52 @@ namespace Nz /*! * \brief Checks whether this box is valid - * \return true if the box has a strictly positive width, height and depth + * \return true if the box has a negative or zero width, height and depth */ + template + bool Box::IsNull() const + { + return width <= T(0.0) && height <= T(0.0) && depth <= T(0.0); + } + /*! + * \brief Checks whether this box is valid + * \return true if the box has a positive width, height and depth + */ template bool Box::IsValid() const { - return width > T(0.0) && height > T(0.0) && depth > T(0.0); + return width >= T(0.0) && height >= T(0.0) && depth >= T(0.0); } /*! - * \brief Makes the box position (0, 0, 0) and lengths (0, 0, 0) - * \return A reference to this box with position (0, 0, 0) and lengths (0, 0, 0) + * \brief Multiplies the lengths of this box with the scalar + * \return A reference to this box where lengths are the product of these lengths and the scalar * - * \see Zero + * \param scalar The scalar to multiply width, height and depth with */ - template - Box& Box::MakeZero() + Box& Box::Scale(T scalar) { - x = T(0.0); - y = T(0.0); - z = T(0.0); - width = T(0.0); - height = T(0.0); - depth = T(0.0); + width *= scalar; + height *= scalar; + depth *= scalar; return *this; } /*! - * \brief Sets the components of the box with width, height and depth - * \return A reference to this box + * \brief Multiplies the lengths of this box with the vector + * \return A reference to this box where width, height and depth are the product of the old width, height and depth with the vec * - * \param Width Width of the box (following X) - * \param Height Height of the box (following Y) - * \param Depth Depth of the box (following Z) - * - * \remark Position will be (0, 0, 0) + * \param vec The vector where component one multiply width, two height and three depth */ - template - Box& Box::Set(T Width, T Height, T Depth) + Box& Box::Scale(const Vector3& vec) { - x = T(0.0); - y = T(0.0); - z = T(0.0); - width = Width; - height = Height; - depth = Depth; - - return *this; - } - - /*! - * \brief Constructs a Box object from its position and sizes - * - * \param X X component of position - * \param Y Y component of position - * \param Z Z component of position - * \param Width Width of the box (following X) - * \param Height Height of the box (following Y) - * \param Depth Depth of the box (following Z) - */ - - template - Box& Box::Set(T X, T Y, T Z, T Width, T Height, T Depth) - { - x = X; - y = Y; - z = Z; - width = Width; - height = Height; - depth = Depth; - - return *this; - } - - /*! - * \brief Sets the components of the box from an array of six elements - * \return A reference to this box - * - * \param box[6] box[0] is X position, box[1] is Y position, box[2] is Z position, box[3] is width, box[4] is height and box[5] is depth - */ - - template - Box& Box::Set(const T box[6]) - { - x = box[0]; - y = box[1]; - z = box[2]; - width = box[3]; - height = box[4]; - depth = box[5]; - - return *this; - } - - /*! - * \brief Sets the components of the box with components from a Rect - * \return A reference to this box - * - * \param rect Rectangle which describes (X, Y) position and (width, height) lenghts - * - * \remark Z position is 0 and depth is 1 - */ - - template - Box& Box::Set(const Rect& rect) - { - x = rect.x; - y = rect.y; - z = T(0.0); - width = rect.width; - height = rect.height; - depth = T(1.0); - - return *this; - } - - /*! - * \brief Sets the components of the box from a vector representing width, height and depth - * \return A reference to this box - * - * \param lengths (Width, Height, depth) of the box - * - * \remark Position will be (0, 0, 0) - */ - - template - Box& Box::Set(const Vector3& lengths) - { - return Set(lengths.x, lengths.y, lengths.z); - } - - /*! - * \brief Sets the components of the box from two vectors representing point of the space - * (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum - * \return A reference to this box - * - * \param vec1 First point - * \param vec2 Second point - */ - - template - Box& Box::Set(const Vector3& vec1, const Vector3& vec2) - { - x = std::min(vec1.x, vec2.x); - y = std::min(vec1.y, vec2.y); - z = std::min(vec1.z, vec2.z); - width = (vec2.x > vec1.x) ? vec2.x - vec1.x : vec1.x - vec2.x; - height = (vec2.y > vec1.y) ? vec2.y - vec1.y : vec1.y - vec2.y; - depth = (vec2.z > vec1.z) ? vec2.z - vec1.z : vec1.z - vec2.z; - - return *this; - } - - /*! - * \brief Sets the components of the box from another type of Box - * \return A reference to this box - * - * \param box Box of type U to convert its components - */ - - template - template - Box& Box::Set(const Box& box) - { - x = T(box.x); - y = T(box.y); - z = T(box.z); - width = T(box.width); - height = T(box.height); - depth = T(box.depth); + width *= vec.x; + height *= vec.y; + depth *= vec.z; return *this; } @@ -663,7 +531,6 @@ namespace Nz * \brief Gives a string representation * \return A string representation of the object: "Box(x, y, z, width, height, depth)" */ - template std::string Box::ToString() const { @@ -691,7 +558,7 @@ namespace Nz std::abs(matrix(0,1)) * halfSize.x + std::abs(matrix(1,1)) * halfSize.y + std::abs(matrix(2,1)) * halfSize.z, std::abs(matrix(0,2)) * halfSize.x + std::abs(matrix(1,2)) * halfSize.y + std::abs(matrix(2,2)) * halfSize.z); - return Set(center - halfSize, center + halfSize); + return operator=(Boxf::FromExtends(center - halfSize, center + halfSize)); } /*! @@ -738,73 +605,13 @@ namespace Nz */ template - T Box::operator[](std::size_t i) const + const T& Box::operator[](std::size_t i) const { NazaraAssert(i < 6, "Index out of range"); return *(&x+i); } - /*! - * \brief Multiplies the lengths with the scalar - * \return A box where the position is the same and width, height and depth are the product of the old width, height and depth and the scalar - * - * \param scalar The scalar to multiply width, height and depth with - */ - - template - Box Box::operator*(T scalar) const - { - return Box(x, y, z, width * scalar, height * scalar, depth * scalar); - } - - /*! - * \brief Multiplies the lengths with the vector - * \return A box where the position is the same and width, height and depth are the product of the old width, height and depth with the vec - * - * \param vec The vector where component one multiply width, two height and three depth - */ - - template - Box Box::operator*(const Vector3& vec) const - { - return Box(x, y, z, width * vec.x, height * vec.y, depth * vec.z); - } - - /*! - * \brief Multiplies the lengths of this box with the scalar - * \return A reference to this box where lengths are the product of these lengths and the scalar - * - * \param scalar The scalar to multiply width, height and depth with - */ - - template - Box& Box::operator*=(T scalar) - { - width *= scalar; - height *= scalar; - depth *= scalar; - - return *this; - } - - /*! - * \brief Multiplies the lengths of this box with the vector - * \return A reference to this box where width, height and depth are the product of the old width, height and depth with the vec - * - * \param vec The vector where component one multiply width, two height and three depth - */ - - template - Box& Box::operator*=(const Vector3& vec) - { - width *= vec.x; - height *= vec.y; - depth *= vec.z; - - return *this; - } - /*! * \brief Compares the box to other one * \return true if the boxes are the same @@ -845,18 +652,33 @@ namespace Nz * * \see Lerp */ + template + Box Box::FromExtends(const Vector3& vec1, const Vector3& vec2) + { + Box box; + box.x = std::min(vec1.x, vec2.x); + box.y = std::min(vec1.y, vec2.y); + box.z = std::min(vec1.z, vec2.z); + box.width = (vec2.x > vec1.x) ? vec2.x - vec1.x : vec1.x - vec2.x; + box.height = (vec2.y > vec1.y) ? vec2.y - vec1.y : vec1.y - vec2.y; + box.depth = (vec2.z > vec1.z) ? vec2.z - vec1.z : vec1.z - vec2.z; + return box; + } + + /*! + * \brief Interpolates the box to other one with a factor of interpolation + * \return A new box which is the interpolation of two rectangles + * + * \param from Initial box + * \param to Target box + * \param interpolation Factor of interpolation + * + * \see Lerp + */ template Box Box::Lerp(const Box& from, const Box& to, T interpolation) { - #ifdef NAZARA_DEBUG - if (interpolation < T(0.0) || interpolation > T(1.0)) - { - NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); - return Zero(); - } - #endif - Box box; box.x = Nz::Lerp(from.x, to.x, interpolation); box.y = Nz::Lerp(from.y, to.y, interpolation); @@ -874,14 +696,22 @@ namespace Nz * * \see MakeZero */ + template + Box Box::Invalid() + { + return Box(-1, -1, -1, -1, -1, -1); + } + /*! + * \brief Shorthand for the box (0, 0, 0, 0, 0, 0) + * \return A box with position (0, 0, 0) and lengths (0, 0, 0) + * + * \see MakeZero + */ template Box Box::Zero() { - Box box; - box.MakeZero(); - - return box; + return Box(Vector3::Zero(), Vector3::Zero()); } /*! diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index 7e67e0143..22dc13f70 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -14,7 +14,7 @@ namespace Nz { /*! - * \ingroup math + * \ingroup math * \class Nz::OrientedBox * \brief Math class that represents an oriented three dimensional box * @@ -164,7 +164,7 @@ namespace Nz template OrientedBox& OrientedBox::Set(const Box& box) { - localBox.Set(box); + localBox = box; return *this; } diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index d8ce1ab96..39b231a55 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -22,9 +22,7 @@ namespace Nz Rect() = default; Rect(T Width, T Height); Rect(T X, T Y, T Width, T Height); - Rect(const T rect[4]); - Rect(const Vector2& lengths); - Rect(const Vector2& vec1, const Vector2& vec2); + explicit Rect(const Vector2& vec1, const Vector2& vec2); template explicit Rect(const Rect& rect); Rect(const Rect& rect) = default; ~Rect() = default; @@ -48,39 +46,30 @@ namespace Nz bool Intersect(const Rect& rect, Rect* intersection = nullptr) const; + bool IsNull() const; bool IsValid() const; Rect& MakeZero(); - Rect& Set(T Width, T Height); - Rect& Set(T X, T Y, T Width, T Height); - Rect& Set(const T rect[4]); - Rect& Set(const Vector2& lengths); - Rect& Set(const Vector2& vec1, const Vector2& vec2); - template Rect& Set(const Rect& rect); + Rect& Scale(T scalar); + Rect& Scale(const Vector2& vec); std::string ToString() const; Rect& Translate(const Vector2& translation); T& operator[](std::size_t i); - T operator[](std::size_t i) const; + const T& operator[](std::size_t i) const; - Rect operator*(T scalar) const; - Rect operator*(const Vector2& vec) const; - Rect operator/(T scalar) const; - Rect operator/(const Vector2& vec) const; - Rect& operator=(const Rect& other) = default; - - Rect& operator*=(T scalar); - Rect& operator*=(const Vector2& vec); - Rect& operator/=(T scalar); - Rect& operator/=(const Vector2& vec); + Rect& operator=(const Rect&) = default; + Rect& operator=(Rect&&) = default; bool operator==(const Rect& rect) const; bool operator!=(const Rect& rect) const; + static Rect FromExtends(const Vector2& vec1, const Vector2& vec2); static Rect Lerp(const Rect& from, const Rect& to, T interpolation); + static Rect Invalid(); static Rect Zero(); T x, y, width, height; diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 77c70f322..b9b79323a 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -30,9 +30,12 @@ namespace Nz */ template - Rect::Rect(T Width, T Height) + Rect::Rect(T Width, T Height) : + x(0), + y(0), + width(Width), + height(Height) { - Set(Width, Height); } /*! @@ -43,53 +46,29 @@ namespace Nz * \param Width Width of the rectangle (following X) * \param Height Height of the rectangle (following Y) */ - template - Rect::Rect(T X, T Y, T Width, T Height) + Rect::Rect(T X, T Y, T Width, T Height) : + x(X), + y(Y), + width(Width), + height(Height) { - Set(X, Y, Width, Height); } /*! - * \brief Constructs a Rect object from an array of four elements + * \brief Constructs a Rect object from two vector representing position and lengths * - * \param vec[4] vec[0] is X position, vec[1] is Y position, vec[2] is width and vec[3] is height + * \param pos (X, Y) of the rect + * \param lengths (Width, Height) of the rect */ - template - Rect::Rect(const T vec[4]) + Rect::Rect(const Vector2& pos, const Vector2& lengths) : + x(pos.x), + y(pos.y), + width(lengths.x), + height(lengths.y) { - Set(vec); } - - /*! - * \brief Constructs a Rect object from a vector representing width and height - * - * \param lengths (Width, Height) of the rectangle - * - * \remark X and Y will be (0, 0) - */ - - template - Rect::Rect(const Vector2& lengths) - { - Set(lengths); - } - - /*! - * \brief Constructs a Rect object from two vectors representing point of the space - * (X, Y) will be the components minimum of the two vectors and the width and height will be the components maximum - minimum - * - * \param vec1 First point - * \param vec2 Second point - */ - - template - Rect::Rect(const Vector2& vec1, const Vector2& vec2) - { - Set(vec1, vec2); - } - /*! * \brief Constructs a Rect object from another type of Rect * @@ -98,9 +77,12 @@ namespace Nz template template - Rect::Rect(const Rect& rect) + Rect::Rect(const Rect& rect) : + x(static_cast(rect.x)), + y(static_cast(rect.y)), + width(static_cast(rect.width)), + height(static_cast(rect.height)) { - Set(rect); } /*! @@ -128,7 +110,6 @@ namespace Nz * * \see Contains */ - template bool Rect::Contains(const Rect& rect) const { @@ -144,7 +125,6 @@ namespace Nz * * \see Contains */ - template bool Rect::Contains(const Vector2& point) const { @@ -160,7 +140,6 @@ namespace Nz * * \see ExtendTo */ - template Rect& Rect::ExtendTo(T X, T Y) { @@ -184,7 +163,6 @@ namespace Nz * * \see ExtendTo */ - template Rect& Rect::ExtendTo(const Rect& rect) { @@ -385,13 +363,22 @@ namespace Nz /*! * \brief Checks whether this rectangle is valid - * \return true if the rectangle has a strictly positive width and height + * \return true if the rectangle has a positive width and height */ + template + bool Rect::IsNull() const + { + return width <= T(0.0) && height <= T(0.0); + } + /*! + * \brief Checks whether this rectangle is valid + * \return true if the rectangle has a positive width and height + */ template bool Rect::IsValid() const { - return width > T(0.0) && height > T(0.0); + return width >= T(0.0) && height >= T(0.0); } /*! @@ -413,115 +400,33 @@ namespace Nz } /*! - * \brief Sets the components of the rectangle with width and height - * \return A reference to this rectangle + * \brief Multiplies the lengths of this rectangle with the scalar + * \return A reference to this rectangle where lengths are the product of these lengths and the scalar * - * \param Width Width of the rectangle (following X) - * \param Height Height of the rectangle (following Y) - * - * \remark Position will be (0, 0) + * \param scalar The scalar to multiply width and height with */ template - Rect& Rect::Set(T Width, T Height) + Rect& Rect::Scale(T scalar) { - x = T(0.0); - y = T(0.0); - width = Width; - height = Height; + width *= scalar; + height *= scalar; return *this; } /*! - * \brief Sets the components of the rectangle - * \return A reference to this rectangle + * \brief Multiplies the lengths of this rectangle with the vector + * \return A reference to this rectangle where width and height are the product of the old width and height with the vec * - * \param X X position - * \param Y Y position - * \param Width Width of the rectangle (following X) - * \param Height Height of the rectangle (following Y) + * \param vec The vector where component one multiply width and two height */ template - Rect& Rect::Set(T X, T Y, T Width, T Height) + Rect& Rect::Scale(const Vector2& vec) { - x = X; - y = Y; - width = Width; - height = Height; - - return *this; - } - - /*! - * \brief Sets the components of the rectangle from an array of four elements - * \return A reference to this rectangle - * - * \param rect[4] rect[0] is X position, rect[1] is Y position, rect[2] is width and rect[3] is height - */ - - template - Rect& Rect::Set(const T rect[4]) - { - x = rect[0]; - y = rect[1]; - width = rect[2]; - height = rect[3]; - - return *this; - } - - /*! - * \brief Sets the components of the rectange from a vector representing width and height - * \return A reference to this rectangle - * - * \param lengths (Width, Height) of the rectangle - * - * \remark Position will be (0, 0) - */ - - template - Rect& Rect::Set(const Vector2& lengths) - { - return Set(lengths.x, lengths.y); - } - - /*! - * \brief Sets a Rect object from two vectors representing point of the space - * (X, Y) will be the components minimum of the two vectors and the width and height will be the components maximum - minimum - * \return A reference to this rectangle - * - * \param vec1 First point - * \param vec2 Second point - */ - - template - Rect& Rect::Set(const Vector2& vec1, const Vector2& vec2) - { - x = std::min(vec1.x, vec2.x); - y = std::min(vec1.y, vec2.y); - width = (vec2.x > vec1.x) ? vec2.x - vec1.x : vec1.x - vec2.x; - height = (vec2.y > vec1.y) ? vec2.y - vec1.y : vec1.y - vec2.y; - - return *this; - } - - /*! - * \brief Sets the components of the rectangle from another type of Rect - * \return A reference to this rectangle - * - * \param rect Rectangle of type U to convert its components - */ - - template - template - Rect& Rect::Set(const Rect& rect) - { - x = T(rect.x); - y = T(rect.y); - width = T(rect.width); - height = T(rect.height); + width *= vec.x; + height *= vec.y; return *this; } @@ -583,129 +488,13 @@ namespace Nz */ template - T Rect::operator[](std::size_t i) const + const T& Rect::operator[](std::size_t i) const { NazaraAssert(i < 4, "Index out of range"); return *(&x+i); } - /*! - * \brief Multiplies the lengths with the scalar - * \return A rectangle where the position is the same and width and height are the product of the old width and height and the scalar - * - * \param scalar The scalar to multiply width and height with - */ - - template - Rect Rect::operator*(T scalar) const - { - return Rect(x, y, width * scalar, height * scalar); - } - - /*! - * \brief Multiplies the lengths with the vector - * \return A rectangle where the position is the same and width and height are the product of the old width and height with the vec - * - * \param vec The vector where component one multiply width and two height - */ - - template - Rect Rect::operator*(const Vector2& vec) const - { - return Rect(x, y, width*vec.x, height*vec.y); - } - - /*! - * \brief Divides the lengths with the scalar - * \return A rectangle where the position is the same and width and height are the quotient of the old width and height and the scalar - * - * \param scalar The scalar to divide width and height with - */ - - template - Rect Rect::operator/(T scalar) const - { - return Rect(x, y, width / scalar, height / scalar); - } - - /*! - * \brief Divides the lengths with the vector - * \return A rectangle where the position is the same and width and height are the quotient of the old width and height with the vec - * - * \param vec The vector where component one divide width and two height - */ - - template - Rect Rect::operator/(const Vector2& vec) const - { - return Rect(x, y, width/vec.x, height/vec.y); - } - - /*! - * \brief Multiplies the lengths of this rectangle with the scalar - * \return A reference to this rectangle where lengths are the product of these lengths and the scalar - * - * \param scalar The scalar to multiply width and height with - */ - - template - Rect& Rect::operator*=(T scalar) - { - width *= scalar; - height *= scalar; - - return *this; - } - - /*! - * \brief Multiplies the lengths of this rectangle with the vector - * \return A reference to this rectangle where width and height are the product of the old width and height with the vec - * - * \param vec The vector where component one multiply width and two height - */ - - template - Rect& Rect::operator*=(const Vector2& vec) - { - width *= vec.x; - height *= vec.y; - - return *this; - } - - /*! - * \brief Divides the lengths of this rectangle with the scalar - * \return A reference to this rectangle where lengths are the quotient of these lengths and the scalar - * - * \param scalar The scalar to divide width and height with - */ - - template - Rect& Rect::operator/=(T scalar) - { - width /= scalar; - height /= scalar; - - return *this; - } - - /*! - * \brief Divives the lengths of this rectangle with the vector - * \return A reference to this rectangle where width and height are the quotient of the old width and height with the vec - * - * \param vec The vector where component one divide width and two height - */ - - template - Rect& Rect::operator/=(const Vector2& vec) - { - width /= vec.x; - height /= vec.y; - - return *this; - } - /*! * \brief Compares the rectangle to other one * \return true if the rectangles are the same @@ -733,6 +522,26 @@ namespace Nz return !operator==(rect); } + /*! + * \brief Sets a Rect object from two vectors representing point of the space + * (X, Y) will be the components minimum of the two vectors and the width and height will be the components maximum - minimum + * \return A reference to this rectangle + * + * \param vec1 First point + * \param vec2 Second point + */ + template + Rect Rect::FromExtends(const Vector2& vec1, const Vector2& vec2) + { + Rect rect; + rect.x = std::min(vec1.x, vec2.x); + rect.y = std::min(vec1.y, vec2.y); + rect.width = (vec2.x > vec1.x) ? vec2.x - vec1.x : vec1.x - vec2.x; + rect.height = (vec2.y > vec1.y) ? vec2.y - vec1.y : vec1.y - vec2.y; + + return rect; + } + /*! * \brief Interpolates the rectangle to other one with a factor of interpolation * \return A new rectangle which is the interpolation of two rectangles @@ -741,23 +550,11 @@ namespace Nz * \param to Target rectangle * \param interpolation Factor of interpolation * - * \remark interpolation is meant to be between 0 and 1, other values are potentially undefined behavior - * \remark With NAZARA_DEBUG, a NazaraError is thrown and Zero() is returned - * * \see Lerp */ - template Rect Rect::Lerp(const Rect& from, const Rect& to, T interpolation) { - #ifdef NAZARA_DEBUG - if (interpolation < T(0.0) || interpolation > T(1.0)) - { - NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); - return Zero(); - } - #endif - Rect rect; rect.x = Nz::Lerp(from.x, to.x, interpolation); rect.y = Nz::Lerp(from.y, to.y, interpolation); @@ -773,14 +570,22 @@ namespace Nz * * \see MakeZero */ + template + Rect Rect::Invalid() + { + return Rect(-1, -1, -1, -1); + } + /*! + * \brief Shorthand for the rectangle (0, 0, 0, 0) + * \return A rectangle with position (0, 0) and lengths (0, 0) + * + * \see MakeZero + */ template Rect Rect::Zero() { - Rect rect; - rect.MakeZero(); - - return rect; + return Rect(0, 0, 0, 0); } /*! diff --git a/include/Nazara/Utility/AbstractImage.inl b/include/Nazara/Utility/AbstractImage.inl index 090babd12..56aac61ee 100644 --- a/include/Nazara/Utility/AbstractImage.inl +++ b/include/Nazara/Utility/AbstractImage.inl @@ -9,7 +9,7 @@ namespace Nz { inline bool AbstractImage::Update(const void* pixels, unsigned int srcWidth, unsigned int srcHeight, UInt8 level) { - return Update(pixels, GetSize(level), srcWidth, srcHeight, level); + return Update(pixels, Boxui(Vector3ui::Zero(), GetSize(level)), srcWidth, srcHeight, level); } inline bool AbstractImage::Update(const void* pixels, const Rectui& rect, unsigned int z, unsigned int srcWidth, unsigned int srcHeight, UInt8 level) diff --git a/include/Nazara/Widgets/Canvas.inl b/include/Nazara/Widgets/Canvas.inl index 4ec367fd0..7293cfe72 100644 --- a/include/Nazara/Widgets/Canvas.inl +++ b/include/Nazara/Widgets/Canvas.inl @@ -69,7 +69,7 @@ namespace Nz Nz::Vector3f pos = entry.widget->GetPosition(Nz::CoordSys::Global); Nz::Vector2f size = entry.widget->GetSize(); - entry.box.Set(pos.x, pos.y, pos.z, size.x, size.y, 1.f); + entry.box = Boxf(pos.x, pos.y, pos.z, size.x, size.y, 1.f); } inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index) diff --git a/src/Nazara/Graphics/BakedFrameGraph.cpp b/src/Nazara/Graphics/BakedFrameGraph.cpp index 7912a7216..6b57530b9 100644 --- a/src/Nazara/Graphics/BakedFrameGraph.cpp +++ b/src/Nazara/Graphics/BakedFrameGraph.cpp @@ -224,7 +224,7 @@ namespace Nz framebufferHeight = std::min(framebufferHeight, height); } - passData.renderRect.Set(0, 0, int(framebufferWidth), int(framebufferHeight)); + passData.renderRect = Recti(0, 0, int(framebufferWidth), int(framebufferHeight)); passData.framebuffer = renderDevice->InstantiateFramebuffer(framebufferWidth, framebufferHeight, passData.renderPass, textures); if (!passData.name.empty()) diff --git a/src/Nazara/Graphics/LinearSlicedSprite.cpp b/src/Nazara/Graphics/LinearSlicedSprite.cpp index 8c35d54a6..6c364348a 100644 --- a/src/Nazara/Graphics/LinearSlicedSprite.cpp +++ b/src/Nazara/Graphics/LinearSlicedSprite.cpp @@ -142,7 +142,7 @@ namespace Nz for (std::size_t i = 0; i < vertexCount; ++i) m_vertices[i].uv.y = m_textureCoords.height - m_vertices[i].uv.y; - aabb.Set(m_vertices[0].position); + aabb = Boxf(m_vertices[0].position, Vector3f::Zero()); for (std::size_t i = 1; i < vertexCount; ++i) aabb.ExtendTo(m_vertices[i].position); } diff --git a/src/Nazara/Graphics/SlicedSprite.cpp b/src/Nazara/Graphics/SlicedSprite.cpp index 3948afa66..b988d82b3 100644 --- a/src/Nazara/Graphics/SlicedSprite.cpp +++ b/src/Nazara/Graphics/SlicedSprite.cpp @@ -159,7 +159,7 @@ namespace Nz for (std::size_t i = 0; i < vertexCount; ++i) m_vertices[i].uv.y = m_textureCoords.height - m_vertices[i].uv.y; - aabb.Set(m_vertices[0].position); + aabb = Boxf(m_vertices[0].position, Vector2f::Zero()); for (std::size_t i = 1; i < vertexCount; ++i) aabb.ExtendTo(m_vertices[i].position); } diff --git a/src/Nazara/Physics3D/Collider3D.cpp b/src/Nazara/Physics3D/Collider3D.cpp index 8afe475b6..556dd51d7 100644 --- a/src/Nazara/Physics3D/Collider3D.cpp +++ b/src/Nazara/Physics3D/Collider3D.cpp @@ -225,7 +225,7 @@ namespace Nz Boxf aabb(-halfLengths.x, -halfLengths.y, -halfLengths.z, m_lengths.x, m_lengths.y, m_lengths.z); aabb.Transform(offsetMatrix, true); - aabb *= scale; + aabb.Scale(scale); return aabb; } diff --git a/src/Nazara/Utility/AlgorithmUtility.cpp b/src/Nazara/Utility/AlgorithmUtility.cpp index 4a5cde493..6d5ad2819 100644 --- a/src/Nazara/Utility/AlgorithmUtility.cpp +++ b/src/Nazara/Utility/AlgorithmUtility.cpp @@ -47,13 +47,13 @@ namespace Nz { } - void Generate(float size, unsigned int recursionLevel, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb, unsigned int indexOffset) + void Generate(float radius, unsigned int recursionLevel, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb, unsigned int indexOffset) { // Grandement inspiré de http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html const float t = (1.f + 2.236067f)/2.f; m_cache.clear(); - m_size = size; + m_size = radius; m_vertices = vertexPointers; m_vertexIndex = 0; @@ -133,8 +133,8 @@ namespace Nz if (aabb) { - Vector3f totalSize = size * m_matrix.GetScale(); - aabb->Set(-totalSize, totalSize); + Vector3f halfSize = radius * m_matrix.GetScale() * 0.5f; + *aabb = Boxf::FromExtends(-halfSize, halfSize); } } @@ -638,14 +638,14 @@ namespace Nz Boxf aabb; if (vertexCount > 0) { - aabb.Set(positionPtr->x, positionPtr->y, positionPtr->z, 0.f, 0.f, 0.f); + aabb = Boxf(positionPtr->x, positionPtr->y, positionPtr->z, 0.f, 0.f, 0.f); ++positionPtr; for (UInt32 i = 1; i < vertexCount; ++i) aabb.ExtendTo(*positionPtr++); } else - aabb.MakeZero(); + aabb = Boxf::Zero(); return aabb; } @@ -850,7 +850,7 @@ namespace Nz if (aabb) { - aabb->Set(-halfLengths, halfLengths); + *aabb = Boxf::FromExtends(-halfLengths, halfLengths); aabb->Transform(matrix, false); } } @@ -886,7 +886,7 @@ namespace Nz if (aabb) { - aabb->MakeZero(); + *aabb = Boxf::Zero(); // On calcule le reste des points Vector3f base(Vector3f::Down()*length); @@ -914,8 +914,8 @@ namespace Nz if (aabb) { - Vector3f totalSize = size * matrix.GetScale(); - aabb->Set(-totalSize, totalSize); + Vector3f halfSize = size * matrix.GetScale() * 0.5f; + *aabb = Boxf::FromExtends(-halfSize, halfSize); } for (unsigned int i = 0; i < vertexCount; ++i) @@ -995,10 +995,10 @@ namespace Nz } if (aabb) - aabb->Set(matrix.Transform(Vector3f(-halfSizeX, 0.f, -halfSizeY), 0.f), matrix.Transform(Vector3f(halfSizeX, 0.f, halfSizeY), 0.f)); + *aabb = Boxf::FromExtends(matrix.Transform(Vector3f(-halfSizeX, 0.f, -halfSizeY), 0.f), matrix.Transform(Vector3f(halfSizeX, 0.f, halfSizeY), 0.f)); } - void GenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb, UInt32 indexOffset) + void GenerateUvSphere(float radius, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb, UInt32 indexOffset) { // http://stackoverflow.com/questions/14080932/implementing-opengl-sphere-example-code float invSliceCount = 1.f / (sliceCount-1); @@ -1024,7 +1024,7 @@ namespace Nz normal.x = sincos.second * sinStackValPi; normal.z = sincos.first * sinStackValPi; - *vertexPointers.positionPtr++ = matrix.Transform(size * normal); + *vertexPointers.positionPtr++ = matrix.Transform(radius * normal); if (vertexPointers.normalPtr) *vertexPointers.normalPtr++ = matrix.Transform(normal, 0.f); @@ -1047,8 +1047,8 @@ namespace Nz if (aabb) { - Vector3f totalSize = size * matrix.GetScale(); - aabb->Set(-totalSize, totalSize); + Vector3f halfSize = radius * matrix.GetScale(); + *aabb = Boxf::FromExtends(-halfSize, halfSize); } } diff --git a/src/Nazara/Utility/Formats/MD5AnimParser.cpp b/src/Nazara/Utility/Formats/MD5AnimParser.cpp index 06b649e19..b04b20eba 100644 --- a/src/Nazara/Utility/Formats/MD5AnimParser.cpp +++ b/src/Nazara/Utility/Formats/MD5AnimParser.cpp @@ -328,7 +328,7 @@ namespace Nz return false; } - m_frames[i].bounds.Set(min, max); + m_frames[i].bounds = Boxf::FromExtends(min, max); } if (!Advance()) diff --git a/src/Nazara/Utility/GuillotineImageAtlas.cpp b/src/Nazara/Utility/GuillotineImageAtlas.cpp index 4d6f031a6..bec43d6fb 100644 --- a/src/Nazara/Utility/GuillotineImageAtlas.cpp +++ b/src/Nazara/Utility/GuillotineImageAtlas.cpp @@ -175,7 +175,7 @@ namespace Nz { std::shared_ptr newImage = std::make_shared(ImageType::E2D, PixelFormat::A8, size.x, size.y); if (oldImage) - newImage->Copy(static_cast(*oldImage), Rectui(Vector2ui(oldImage->GetSize())), Vector2ui(0, 0)); // Copie des anciennes données + newImage->Copy(static_cast(*oldImage), Rectui(Vector2ui::Zero(), Vector2ui(oldImage->GetSize())), Vector2ui(0, 0)); // Copie des anciennes données return newImage; } diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index a3fe9aa88..3c4eae5d1 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -330,12 +330,12 @@ namespace Nz std::size_t subMeshCount = m_subMeshes.size(); if (subMeshCount > 0) { - m_aabb.Set(m_subMeshes.front().subMesh->GetAABB()); + m_aabb = Boxf(m_subMeshes.front().subMesh->GetAABB()); for (std::size_t i = 1; i < subMeshCount; ++i) m_aabb.ExtendTo(m_subMeshes[i].subMesh->GetAABB()); } else - m_aabb.MakeZero(); + m_aabb = Boxf::Zero(); m_aabbUpdated = true; } diff --git a/src/Nazara/Utility/RichTextDrawer.cpp b/src/Nazara/Utility/RichTextDrawer.cpp index c96fa4e96..6995ae8c9 100644 --- a/src/Nazara/Utility/RichTextDrawer.cpp +++ b/src/Nazara/Utility/RichTextDrawer.cpp @@ -347,7 +347,7 @@ namespace Nz glyph.flipped = fontGlyph.flipped; glyph.renderOrder = renderOrder; - glyph.bounds.Set(fontGlyph.aabb); + glyph.bounds = Rectf(fontGlyph.aabb); if (lineWrap && ShouldLineWrap(glyph.bounds.width)) AppendNewLine(font, characterSize, lineSpacingOffset, m_lastSeparatorGlyph, m_lastSeparatorPosition); @@ -458,7 +458,7 @@ namespace Nz AppendNewLine(font, characterSize, lineSpacingOffset, m_lastSeparatorGlyph, m_lastSeparatorPosition); glyph.atlas = nullptr; - glyph.bounds.Set(m_drawPos.x, m_lines.back().bounds.y, advance, lineHeight); + glyph.bounds = Rectf(m_drawPos.x, m_lines.back().bounds.y, advance, lineHeight); glyph.corners[0].Set(glyph.bounds.GetCorner(RectCorner::LeftTop)); glyph.corners[1].Set(glyph.bounds.GetCorner(RectCorner::RightTop)); diff --git a/src/Nazara/Utility/SimpleTextDrawer.cpp b/src/Nazara/Utility/SimpleTextDrawer.cpp index 1683c4a74..333dba712 100644 --- a/src/Nazara/Utility/SimpleTextDrawer.cpp +++ b/src/Nazara/Utility/SimpleTextDrawer.cpp @@ -153,7 +153,7 @@ namespace Nz glyph.flipped = fontGlyph.flipped; glyph.renderOrder = renderOrder; - glyph.bounds.Set(fontGlyph.aabb); + glyph.bounds = Rectf(fontGlyph.aabb); if (lineWrap && ShouldLineWrap(glyph.bounds.width)) AppendNewLine(m_lastSeparatorGlyph, m_lastSeparatorPosition); @@ -245,7 +245,7 @@ namespace Nz AppendNewLine(m_lastSeparatorGlyph, m_lastSeparatorPosition); glyph.atlas = nullptr; - glyph.bounds.Set(m_drawPos.x, m_lines.back().bounds.y, advance, GetLineHeight(sizeInfo)); + glyph.bounds = Rectf(m_drawPos.x, m_lines.back().bounds.y, advance, GetLineHeight(sizeInfo)); glyph.corners[0].Set(glyph.bounds.GetCorner(RectCorner::LeftTop)); glyph.corners[1].Set(glyph.bounds.GetCorner(RectCorner::RightTop)); diff --git a/src/Nazara/Utility/Skeleton.cpp b/src/Nazara/Utility/Skeleton.cpp index 6cc15136d..2ea8d877e 100644 --- a/src/Nazara/Utility/Skeleton.cpp +++ b/src/Nazara/Utility/Skeleton.cpp @@ -55,12 +55,12 @@ namespace Nz if (jointCount > 0) { Vector3f pos = m_impl->joints[0].GetPosition(); - m_impl->aabb.Set(pos.x, pos.y, pos.z, 0.f, 0.f, 0.f); + m_impl->aabb = Boxf(pos, Vector3f::Zero()); for (std::size_t i = 1; i < jointCount; ++i) m_impl->aabb.ExtendTo(m_impl->joints[i].GetPosition()); } else - m_impl->aabb.MakeZero(); + m_impl->aabb = Boxf::Zero(); m_impl->aabbUpdated = true; }