From b84a1f0663b33e8adb881a1e20b1792e977c1545 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 6 May 2015 22:51:31 +0200 Subject: [PATCH] Ndk/CameraComponent: Added [Get/Set]Layer method Former-commit-id: 51ee045d4eaa7c7274181129ced56d861def3b8e --- .../NDK/Components/CameraComponent.inl | 5 +++++ SDK/src/NDK/Components/CameraComponent.cpp | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/SDK/include/NDK/Components/CameraComponent.inl b/SDK/include/NDK/Components/CameraComponent.inl index 210a75389..5ac830f1f 100644 --- a/SDK/include/NDK/Components/CameraComponent.inl +++ b/SDK/include/NDK/Components/CameraComponent.inl @@ -70,6 +70,11 @@ namespace Ndk return m_frustum; } + inline unsigned int CameraComponent::GetLayer() const + { + return m_layer; + } + inline const NzMatrix4f& CameraComponent::GetProjectionMatrix() const { EnsureProjectionMatrixUpdate(); diff --git a/SDK/src/NDK/Components/CameraComponent.cpp b/SDK/src/NDK/Components/CameraComponent.cpp index 457acbbbd..4bda6b306 100644 --- a/SDK/src/NDK/Components/CameraComponent.cpp +++ b/SDK/src/NDK/Components/CameraComponent.cpp @@ -8,6 +8,13 @@ namespace Ndk { + void CameraComponent::SetLayer(unsigned int layer) + { + m_layer = layer; + + m_entity->Invalidate(); // Invalidate the entity to make it passes through RenderSystem validation + } + void CameraComponent::OnAttached() { InvalidateViewMatrix(); @@ -45,7 +52,7 @@ namespace Ndk NazaraUnused(node); NazaraUnused(userdata); - // La matrice de vue dépend directement des données du node, invalidons-là + // Our view matrix depends on NodeComponent position/rotation InvalidateViewMatrix(); return true; } @@ -82,13 +89,14 @@ namespace Ndk EnsureProjectionMatrixUpdate(); EnsureViewMatrixUpdate(); + // Extract the frustum from the view and projection matrices m_frustum.Extract(m_viewMatrix, m_projectionMatrix); m_frustumUpdated = true; } void CameraComponent::UpdateProjectionMatrix() const { - EnsureViewportUpdate(); // Peut affecter l'aspect ratio + EnsureViewportUpdate(); // Can affect aspect ratio m_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar); m_projectionMatrixUpdated = true; @@ -100,6 +108,7 @@ namespace Ndk NodeComponent& nodeComponent = m_entity->GetComponent(); + // Build the view matrix using the NodeComponent position/rotation m_viewMatrix.MakeViewMatrix(nodeComponent.GetPosition(nzCoordSys_Global), nodeComponent.GetRotation(nzCoordSys_Global)); m_viewMatrixUpdated = true; } @@ -109,16 +118,16 @@ namespace Ndk NazaraAssert(m_target, "CameraComponent has no target"); unsigned int targetWidth = m_target->GetWidth(); - unsigned int targetHeight = std::max(m_target->GetHeight(), 1U); // Pour éviter une division par zéro + unsigned int targetHeight = std::max(m_target->GetHeight(), 1U); // Let's make sure we won't divide by zero - // La zone visée est définie en "pourcentage" (0...1), on calcule les valeurs en pixel + // Our target region is expressed as % of the viewport dimensions, let's compute it in pixels NzRectf fViewport(m_targetRegion); fViewport.x *= targetWidth; fViewport.y *= targetHeight; fViewport.width *= targetWidth; fViewport.height *= targetHeight; - // On calcule le rapport largeur/hauteur, et s'il est différent on invalide + // Compute the new aspect ratio, if it's different we need to invalidate the projection matrix float aspectRatio = fViewport.width/fViewport.height; if (!NzNumberEquals(m_aspectRatio, aspectRatio, 0.001f)) { @@ -127,6 +136,7 @@ namespace Ndk InvalidateProjectionMatrix(); } + // Convert it back to int m_viewport.Set(fViewport); m_viewportUpdated = true; }