Ndk/CameraComponent: Added [Get/Set]Layer method

Former-commit-id: 51ee045d4eaa7c7274181129ced56d861def3b8e
This commit is contained in:
Lynix 2015-05-06 22:51:31 +02:00
parent 04d864e171
commit b84a1f0663
2 changed files with 20 additions and 5 deletions

View File

@ -70,6 +70,11 @@ namespace Ndk
return m_frustum; return m_frustum;
} }
inline unsigned int CameraComponent::GetLayer() const
{
return m_layer;
}
inline const NzMatrix4f& CameraComponent::GetProjectionMatrix() const inline const NzMatrix4f& CameraComponent::GetProjectionMatrix() const
{ {
EnsureProjectionMatrixUpdate(); EnsureProjectionMatrixUpdate();

View File

@ -8,6 +8,13 @@
namespace Ndk 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() void CameraComponent::OnAttached()
{ {
InvalidateViewMatrix(); InvalidateViewMatrix();
@ -45,7 +52,7 @@ namespace Ndk
NazaraUnused(node); NazaraUnused(node);
NazaraUnused(userdata); 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(); InvalidateViewMatrix();
return true; return true;
} }
@ -82,13 +89,14 @@ namespace Ndk
EnsureProjectionMatrixUpdate(); EnsureProjectionMatrixUpdate();
EnsureViewMatrixUpdate(); EnsureViewMatrixUpdate();
// Extract the frustum from the view and projection matrices
m_frustum.Extract(m_viewMatrix, m_projectionMatrix); m_frustum.Extract(m_viewMatrix, m_projectionMatrix);
m_frustumUpdated = true; m_frustumUpdated = true;
} }
void CameraComponent::UpdateProjectionMatrix() const 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_projectionMatrix.MakePerspective(m_fov, m_aspectRatio, m_zNear, m_zFar);
m_projectionMatrixUpdated = true; m_projectionMatrixUpdated = true;
@ -100,6 +108,7 @@ namespace Ndk
NodeComponent& nodeComponent = m_entity->GetComponent<NodeComponent>(); NodeComponent& nodeComponent = m_entity->GetComponent<NodeComponent>();
// Build the view matrix using the NodeComponent position/rotation
m_viewMatrix.MakeViewMatrix(nodeComponent.GetPosition(nzCoordSys_Global), nodeComponent.GetRotation(nzCoordSys_Global)); m_viewMatrix.MakeViewMatrix(nodeComponent.GetPosition(nzCoordSys_Global), nodeComponent.GetRotation(nzCoordSys_Global));
m_viewMatrixUpdated = true; m_viewMatrixUpdated = true;
} }
@ -109,16 +118,16 @@ namespace Ndk
NazaraAssert(m_target, "CameraComponent has no target"); NazaraAssert(m_target, "CameraComponent has no target");
unsigned int targetWidth = m_target->GetWidth(); 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); NzRectf fViewport(m_targetRegion);
fViewport.x *= targetWidth; fViewport.x *= targetWidth;
fViewport.y *= targetHeight; fViewport.y *= targetHeight;
fViewport.width *= targetWidth; fViewport.width *= targetWidth;
fViewport.height *= targetHeight; 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; float aspectRatio = fViewport.width/fViewport.height;
if (!NzNumberEquals(m_aspectRatio, aspectRatio, 0.001f)) if (!NzNumberEquals(m_aspectRatio, aspectRatio, 0.001f))
{ {
@ -127,6 +136,7 @@ namespace Ndk
InvalidateProjectionMatrix(); InvalidateProjectionMatrix();
} }
// Convert it back to int
m_viewport.Set(fViewport); m_viewport.Set(fViewport);
m_viewportUpdated = true; m_viewportUpdated = true;
} }