Math: Rework Box and Rect classes

This commit is contained in:
SirLynix
2022-12-18 14:57:14 +01:00
parent 811194bb97
commit 830eee78a8
28 changed files with 242 additions and 642 deletions

View File

@@ -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());

View File

@@ -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));
}
}

View File

@@ -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));
}
}

View File

@@ -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);

View File

@@ -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<Vector2f, RectCornerCount> 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);
}
}

View File

@@ -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<const AbstractAtlas*, AtlasSlots> m_atlases;
mutable std::unordered_map<RenderKey, RenderIndices, HashRenderKey> m_renderInfos;
std::shared_ptr<MaterialInstance> m_material;
std::vector<RenderData> m_data;
std::vector<VertexStruct_XYZ_Color_UV> m_vertices;
Recti m_scissorBox;
};
}