Sdk/CameraComponent: Add Size property for Orthogonal rendering

Former-commit-id: 0cdebac880e7e97685c7a0a2980dba973ec651a3
This commit is contained in:
Lynix 2016-01-13 18:43:42 +01:00
parent 4562243c5f
commit f49f77b75d
3 changed files with 31 additions and 2 deletions

View File

@ -41,6 +41,7 @@ namespace Ndk
inline unsigned int GetLayer() const;
inline const Nz::Matrix4f& GetProjectionMatrix() const override;
inline Nz::ProjectionType GetProjectionType() const;
inline const Nz::Vector2f& GetSize() const;
inline const Nz::RenderTarget* GetTarget() const override;
inline const Nz::Rectf& GetTargetRegion() const;
inline const Nz::Matrix4f& GetViewMatrix() const override;
@ -51,6 +52,8 @@ namespace Ndk
inline void SetFOV(float fov);
inline void SetLayer(unsigned int layer);
inline void SetProjectionType(Nz::ProjectionType projection);
inline void SetSize(const Nz::Vector2f& size);
inline void SetSize(float width, float height);
inline void SetTarget(const Nz::RenderTarget* renderTarget);
inline void SetTargetRegion(const Nz::Rectf& region);
inline void SetViewport(const Nz::Recti& viewport);
@ -89,6 +92,7 @@ namespace Ndk
Nz::Rectf m_targetRegion;
mutable Nz::Recti m_viewport;
const Nz::RenderTarget* m_target;
Nz::Vector2f m_size;
mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated;

View File

@ -4,12 +4,14 @@
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include "CameraComponent.hpp"
namespace Ndk
{
inline CameraComponent::CameraComponent() :
m_projectionType(Nz::ProjectionType_Perspective),
m_targetRegion(0.f, 0.f, 1.f, 1.f),
m_size(0.f),
m_target(nullptr),
m_frustumUpdated(false),
m_projectionMatrixUpdated(false),
@ -28,6 +30,7 @@ namespace Ndk
AbstractViewer(camera),
m_projectionType(camera.m_projectionType),
m_targetRegion(camera.m_targetRegion),
m_size(camera.m_size),
m_target(nullptr),
m_frustumUpdated(false),
m_projectionMatrixUpdated(false),
@ -102,6 +105,11 @@ namespace Ndk
return m_projectionType;
}
inline const Nz::Vector2f & CameraComponent::GetSize() const
{
return m_size;
}
inline const Nz::RenderTarget* CameraComponent::GetTarget() const
{
return m_target;
@ -151,6 +159,18 @@ namespace Ndk
InvalidateProjectionMatrix();
}
inline void CameraComponent::SetSize(const Nz::Vector2f& size)
{
m_size = size;
InvalidateProjectionMatrix();
}
inline void CameraComponent::SetSize(float width, float height)
{
SetSize({width, height});
}
inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget)
{
m_target = renderTarget;

View File

@ -119,9 +119,14 @@ namespace Ndk
switch (m_projectionType)
{
case Nz::ProjectionType_Orthogonal:
EnsureViewportUpdate();
if (m_size.x <= 0.f || m_size.y <= 0.f)
{
EnsureViewportUpdate();
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
}
else
m_projectionMatrix.MakeOrtho(0.f, m_size.x, 0.f, m_size.y, m_zNear, m_zFar);
break;
case Nz::ProjectionType_Perspective: