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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -175,7 +175,7 @@ namespace Nz
{
std::shared_ptr<Image> newImage = std::make_shared<Image>(ImageType::E2D, PixelFormat::A8, size.x, size.y);
if (oldImage)
newImage->Copy(static_cast<Image&>(*oldImage), Rectui(Vector2ui(oldImage->GetSize())), Vector2ui(0, 0)); // Copie des anciennes données
newImage->Copy(static_cast<Image&>(*oldImage), Rectui(Vector2ui::Zero(), Vector2ui(oldImage->GetSize())), Vector2ui(0, 0)); // Copie des anciennes données
return newImage;
}

View File

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

View File

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

View File

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

View File

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