Ndk: Add support for 2D rendering

Former-commit-id: bdf9257816c8f48b8c0679647978480785720053
This commit is contained in:
Lynix
2015-09-18 12:34:05 +02:00
parent dd7afa970f
commit 859544eaa7
10 changed files with 140 additions and 11 deletions

View File

@@ -116,9 +116,21 @@ namespace Ndk
void CameraComponent::UpdateProjectionMatrix() const
{
EnsureViewportUpdate(); // Can affect aspect ratio
switch (m_projectionType)
{
case nzProjectionType_Orthogonal:
EnsureViewportUpdate();
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
break;
case nzProjectionType_Perspective:
EnsureViewportUpdate(); // Can affect aspect ratio
m_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar);
break;
}
m_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar);
m_projectionMatrixUpdated = true;
}
@@ -153,7 +165,8 @@ namespace Ndk
{
m_aspectRatio = aspectRatio;
InvalidateProjectionMatrix();
if (m_projectionType == nzProjectionType_Perspective)
InvalidateProjectionMatrix();
}
// Convert it back to int

View File

@@ -3,15 +3,16 @@
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/World.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#include <NDK/Components/NodeComponent.hpp>
namespace Ndk
{
void GraphicsComponent::InvalidateRenderableData(const NzInstancedRenderable* renderable, nzUInt32 flags, unsigned int index)
{
NazaraUnused(renderable);
NazaraAssert(index < m_renderables.size(), "Invalid renderable index");
NazaraUnused(renderable);
Renderable& r = m_renderables[index];
r.dataUpdated = false;
@@ -66,7 +67,9 @@ namespace Ndk
{
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "GraphicsComponent requires NodeComponent");
m_transformMatrix = m_entity->GetComponent<NodeComponent>().GetTransformMatrix();
Ndk::RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<Ndk::RenderSystem>();
m_transformMatrix = renderSystem.GetCoordinateSystemMatrix() * m_entity->GetComponent<NodeComponent>().GetTransformMatrix();
m_transformMatrixUpdated = true;
}