diff --git a/SDK/include/NDK/Components/CameraComponent.hpp b/SDK/include/NDK/Components/CameraComponent.hpp index f96d32da4..d5951109b 100644 --- a/SDK/include/NDK/Components/CameraComponent.hpp +++ b/SDK/include/NDK/Components/CameraComponent.hpp @@ -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; diff --git a/SDK/include/NDK/Components/CameraComponent.inl b/SDK/include/NDK/Components/CameraComponent.inl index 73e5b1cc3..7ff31d623 100644 --- a/SDK/include/NDK/Components/CameraComponent.inl +++ b/SDK/include/NDK/Components/CameraComponent.inl @@ -4,12 +4,14 @@ #include #include +#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; diff --git a/SDK/src/NDK/Components/CameraComponent.cpp b/SDK/src/NDK/Components/CameraComponent.cpp index ac369e566..1b7a3e06d 100644 --- a/SDK/src/NDK/Components/CameraComponent.cpp +++ b/SDK/src/NDK/Components/CameraComponent.cpp @@ -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(m_viewport.width), 0.f, static_cast(m_viewport.height), m_zNear, m_zFar); + m_projectionMatrix.MakeOrtho(0.f, static_cast(m_viewport.width), 0.f, static_cast(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: