NDK/RenderSystem: Begin to implement Update

Former-commit-id: 404b7998afffa79568c722677f9760c467e78166
This commit is contained in:
Lynix 2015-06-02 17:20:57 +02:00
parent 844062cfd0
commit 2d0cf1794e
3 changed files with 43 additions and 3 deletions

View File

@ -10,6 +10,7 @@
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Utility/Node.hpp>
#include <NDK/Component.hpp>
@ -18,12 +19,14 @@ namespace Ndk
{
class Entity;
class NDK_API CameraComponent : public Component<CameraComponent>, NzNode::Listener, NzRenderTarget::Listener
class NDK_API CameraComponent : public Component<CameraComponent>, public NzAbstractViewer, NzNode::Listener, NzRenderTarget::Listener
{
public:
CameraComponent();
~CameraComponent();
void ApplyView() const override;
void EnsureFrustumUpdate() const;
void EnsureProjectionMatrixUpdate() const;
void EnsureViewMatrixUpdate() const;

View File

@ -3,11 +3,40 @@
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/CameraComponent.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/Components/NodeComponent.hpp>
namespace Ndk
{
void CameraComponent::ApplyView() const
{
NazaraAssert(m_target, "CameraComponent has no target");
EnsureProjectionMatrixUpdate();
EnsureViewMatrixUpdate();
EnsureViewportUpdate();
NzRenderer::SetMatrix(nzMatrixType_Projection, m_projectionMatrix);
NzRenderer::SetMatrix(nzMatrixType_View, m_viewMatrix);
NzRenderer::SetTarget(m_target);
NzRenderer::SetViewport(m_viewport);
}
NzVector3f CameraComponent::GetEyePosition() const
{
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "CameraComponent requires NodeComponent");
return m_entity->GetComponent<NodeComponent>().GetPosition();
}
NzVector3f CameraComponent::GetForward() const
{
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "CameraComponent requires NodeComponent");
return m_entity->GetComponent<NodeComponent>().GetForward();
}
void CameraComponent::SetLayer(unsigned int layer)
{
m_layer = layer;

View File

@ -5,6 +5,7 @@
#include <NDK/Systems/RenderSystem.hpp>
#include <NDK/Components/CameraComponent.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
namespace Ndk
{
@ -14,6 +15,13 @@ namespace Ndk
void RenderSystem::Update(float elapsedTime)
{
for (const Ndk::EntityHandle& camera : m_cameras)
{
CameraComponent& camComponent = camera->GetComponent<CameraComponent>();
NodeComponent& cameraNode = camera->GetComponent<NodeComponent>();
camComponent.ApplyView();
}
}
void RenderSystem::OnEntityRemoved(Entity* entity)
@ -24,7 +32,7 @@ namespace Ndk
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
{
if (entity->HasComponent<CameraComponent>())
if (entity->HasComponent<CameraComponent>() && entity->HasComponent<NodeComponent>())
{
m_cameras.Insert(entity);
std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2)
@ -35,7 +43,7 @@ namespace Ndk
else
m_cameras.Remove(entity);
if (entity->HasComponent<GraphicsComponent>())
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
m_drawables.Insert(entity);
else
m_drawables.Remove(entity);