calculate AABB for geometry

This commit is contained in:
ohyzha
2024-10-29 12:40:52 +02:00
parent 839efa5509
commit 5ece0acc77
2 changed files with 41 additions and 0 deletions

View File

@@ -83,6 +83,46 @@ namespace OpenVulkano::Scene
Geometry::Close();
}
void Geometry::CalculateAABB()
{
if (vertexCount == 0 || !vertices)
{
return;
}
for (int i = 0; i < vertexCount; i++)
{
float x = vertices[i].position.x;
float y = vertices[i].position.y;
float z = vertices[i].position.z;
if (x < aabb.min.x)
{
aabb.min.x = x;
}
if (y < aabb.min.y)
{
aabb.min.y = y;
}
if (z < aabb.min.z)
{
aabb.min.z = z;
}
if (x > aabb.max.x)
{
aabb.max.x = x;
}
if (y > aabb.max.y)
{
aabb.max.y = y;
}
if (z > aabb.max.z)
{
aabb.max.z = z;
}
}
}
void Geometry::Swap(Geometry& other) noexcept
{
RenderResourceHolder<Geometry>::Swap(other);

View File

@@ -63,6 +63,7 @@ namespace OpenVulkano
void SetOwnsMemory(bool val) { ownsMemory = val; }
bool FreeAfterUpload() const { return freeAfterUpload; }
void SetFreeAfterUpload(bool val) { freeAfterUpload = val; }
void CalculateAABB();
private:
void Swap(Geometry& other) noexcept;
};