diff --git a/include/Nazara/Graphics/View.hpp b/include/Nazara/Graphics/View.hpp index 899c34de6..bc048aeb6 100644 --- a/include/Nazara/Graphics/View.hpp +++ b/include/Nazara/Graphics/View.hpp @@ -20,6 +20,7 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget { public: NzView(); + NzView(const NzVector2f& size); ~NzView(); void EnsureFrustumUpdate() const; @@ -32,6 +33,7 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget NzVector3f GetForward() const; const NzFrustumf& GetFrustum() const; const NzMatrix4f& GetProjectionMatrix() const; + const NzVector2f& GetSize() const; const NzRenderTarget* GetTarget() const; const NzRectf& GetTargetRegion() const; const NzMatrix4f& GetViewMatrix() const; @@ -39,6 +41,7 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget float GetZFar() const; float GetZNear() const; + void SetSize(const NzVector2f& size); void SetTarget(const NzRenderTarget* renderTarget); void SetTarget(const NzRenderTarget& renderTarget); void SetTargetRegion(const NzRectf& region); @@ -63,6 +66,7 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget mutable NzMatrix4f m_viewMatrix; NzRectf m_targetRegion; mutable NzRecti m_viewport; + NzVector2f m_size; const NzRenderTarget* m_target; mutable bool m_frustumUpdated; mutable bool m_projectionMatrixUpdated; diff --git a/src/Nazara/Graphics/View.cpp b/src/Nazara/Graphics/View.cpp index 3caa0b48f..44d00294c 100644 --- a/src/Nazara/Graphics/View.cpp +++ b/src/Nazara/Graphics/View.cpp @@ -10,6 +10,7 @@ NzView::NzView() : m_targetRegion(0.f, 0.f, 1.f, 1.f), +m_size(0.f), m_target(nullptr), m_frustumUpdated(false), m_projectionMatrixUpdated(false), @@ -20,6 +21,12 @@ m_zNear(-1.f) { } +NzView::NzView(const NzVector2f& size) : +NzView() // On délègue +{ + m_size = size; +} + NzView::~NzView() { if (m_target) @@ -256,10 +263,16 @@ void NzView::UpdateFrustum() const void NzView::UpdateProjectionMatrix() const { - if (!m_viewportUpdated) - UpdateViewport(); + if (m_size.x <= 0.f || m_size.y <= 0.f) // Si la taille est nulle, on prendra la taille du viewport + { + if (!m_viewportUpdated) + UpdateViewport(); + + m_projectionMatrix.MakeOrtho(0.f, m_viewport.width, 0.f, 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); - m_projectionMatrix.MakeOrtho(m_viewport.x, m_viewport.x + m_viewport.width, m_viewport.y, m_viewport.y + m_viewport.height, m_zNear, m_zFar); m_projectionMatrixUpdated = true; }