Sdk/DebugSystem: Fix AABB/OBB debug draw

This commit is contained in:
Lynix 2018-08-31 21:45:57 +02:00
parent b739965b1d
commit 8ce8eafb88
3 changed files with 36 additions and 10 deletions

View File

@ -57,6 +57,8 @@ namespace Ndk
inline std::size_t GetAttachedRenderableCount() const; inline std::size_t GetAttachedRenderableCount() const;
inline const Nz::BoundingVolumef& GetBoundingVolume(std::size_t renderableIndex) const; inline const Nz::BoundingVolumef& GetBoundingVolume(std::size_t renderableIndex) const;
inline const Nz::Matrix4f& GetLocalMatrix(std::size_t renderableIndex) const;
inline const Nz::Matrix4f& GetTransformMatrix(std::size_t renderableIndex) const;
inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const; inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const;

View File

@ -176,6 +176,20 @@ namespace Ndk
return m_renderables[renderableIndex].boundingVolume; return m_renderables[renderableIndex].boundingVolume;
} }
inline const Nz::Matrix4f& GraphicsComponent::GetLocalMatrix(std::size_t renderableIndex) const
{
assert(renderableIndex < m_renderables.size());
return m_renderables[renderableIndex].data.localMatrix;
}
inline const Nz::Matrix4f& GraphicsComponent::GetTransformMatrix(std::size_t renderableIndex) const
{
EnsureBoundingVolumesUpdate();
assert(renderableIndex < m_renderables.size());
return m_renderables[renderableIndex].data.transformMatrix;
}
/*! /*!
* \brief Calls a function for every renderable attached to this component * \brief Calls a function for every renderable attached to this component
* *

View File

@ -39,7 +39,9 @@ namespace Ndk
void MakeBoundingVolume() const override void MakeBoundingVolume() const override
{ {
m_boundingVolume.MakeNull(); // We generate an infinite bounding volume so that we're always considered for rendering when culling does occurs
// (bounding volume culling happens only if GraphicsComponent AABB partially fail)
m_boundingVolume.MakeInfinite();
} }
protected: protected:
@ -71,7 +73,9 @@ namespace Ndk
renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect); renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect);
}; };
// Maybe we should draw the global AABB (using another color)
//DrawBox(entityGfx.GetAABB()); //DrawBox(entityGfx.GetAABB());
for (std::size_t i = 0; i < entityGfx.GetAttachedRenderableCount(); ++i) for (std::size_t i = 0; i < entityGfx.GetAttachedRenderableCount(); ++i)
{ {
const Nz::BoundingVolumef& boundingVolume = entityGfx.GetBoundingVolume(i); const Nz::BoundingVolumef& boundingVolume = entityGfx.GetBoundingVolume(i);
@ -95,19 +99,25 @@ namespace Ndk
{ {
NazaraAssert(m_entityOwner, "DebugRenderable has no owner"); NazaraAssert(m_entityOwner, "DebugRenderable has no owner");
// TODO const DebugComponent& entityDebug = m_entityOwner->GetComponent<DebugComponent>();
/*const DebugComponent& entityDebug = m_entityOwner->GetComponent<DebugComponent>();
const GraphicsComponent& entityGfx = m_entityOwner->GetComponent<GraphicsComponent>(); const GraphicsComponent& entityGfx = m_entityOwner->GetComponent<GraphicsComponent>();
Nz::Boxf obb = entityGfx.GetAABB().obb.localBox; auto DrawBox = [&](const Nz::Boxf& box, const Nz::Matrix4f& transformMatrix)
{
Nz::Matrix4f boxMatrix = Nz::Matrix4f::Identity();
boxMatrix.SetScale(box.GetLengths());
boxMatrix.SetTranslation(box.GetCenter());
boxMatrix.ConcatenateAffine(transformMatrix);
Nz::Matrix4f transformMatrix = instanceData.transformMatrix; renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), boxMatrix, scissorRect);
Nz::Vector3f obbCenter = transformMatrix.Transform(obb.GetCenter(), 0.f); //< Apply rotation/scale to obb center, to display it at a correct position };
transformMatrix.ApplyScale(obb.GetLengths()); for (std::size_t i = 0; i < entityGfx.GetAttachedRenderableCount(); ++i)
transformMatrix.ApplyTranslation(obbCenter); {
const Nz::BoundingVolumef& boundingVolume = entityGfx.GetBoundingVolume(i);
renderQueue->AddMesh(0, m_material, m_meshData, Nz::Boxf::Zero(), transformMatrix, scissorRect);*/ if (boundingVolume.IsFinite())
DrawBox(boundingVolume.obb.localBox, entityGfx.GetTransformMatrix(i));
}
} }
std::unique_ptr<InstancedRenderable> Clone() const override std::unique_ptr<InstancedRenderable> Clone() const override