SDK/CameraComponent: Add projection scale

This commit is contained in:
Lynix 2020-01-05 14:35:31 +01:00
parent 380c5eb9ae
commit c378ad26a9
4 changed files with 30 additions and 4 deletions

View File

@ -315,6 +315,7 @@ Nazara Development Kit:
- ⚠ ConstraintComponent2D has been reworked to handle entity destruction and remove constraints at will - ⚠ ConstraintComponent2D has been reworked to handle entity destruction and remove constraints at will
- Fixed crash when pressing up/down key with no history in the console - Fixed crash when pressing up/down key with no history in the console
- (Rich)TextAreaWidget text style is now alterable - (Rich)TextAreaWidget text style is now alterable
- Added CameraComponent::SetProjectionScale
# 0.4: # 0.4:

View File

@ -43,6 +43,7 @@ namespace Ndk
const Nz::Frustumf& GetFrustum() const override; const Nz::Frustumf& GetFrustum() const override;
inline unsigned int GetLayer() const; inline unsigned int GetLayer() const;
const Nz::Matrix4f& GetProjectionMatrix() const override; const Nz::Matrix4f& GetProjectionMatrix() const override;
inline const Nz::Vector3f& GetProjectionScale() const;
Nz::ProjectionType GetProjectionType() const override; Nz::ProjectionType GetProjectionType() const override;
inline const Nz::Vector2f& GetSize() const; inline const Nz::Vector2f& GetSize() const;
const Nz::RenderTarget* GetTarget() const override; const Nz::RenderTarget* GetTarget() const override;
@ -54,6 +55,7 @@ namespace Ndk
inline void SetFOV(float fov); inline void SetFOV(float fov);
void SetLayer(unsigned int layer); void SetLayer(unsigned int layer);
inline void SetProjectionScale(const Nz::Vector3f& scale);
inline void SetProjectionType(Nz::ProjectionType projection); inline void SetProjectionType(Nz::ProjectionType projection);
inline void SetSize(const Nz::Vector2f& size); inline void SetSize(const Nz::Vector2f& size);
inline void SetSize(float width, float height); inline void SetSize(float width, float height);
@ -99,6 +101,7 @@ namespace Ndk
mutable Nz::Recti m_viewport; mutable Nz::Recti m_viewport;
const Nz::RenderTarget* m_target; const Nz::RenderTarget* m_target;
Nz::Vector2f m_size; Nz::Vector2f m_size;
Nz::Vector3f m_projectionScale;
mutable bool m_frustumUpdated; mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated; mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated; mutable bool m_viewMatrixUpdated;

View File

@ -17,6 +17,7 @@ namespace Ndk
m_targetRegion(0.f, 0.f, 1.f, 1.f), m_targetRegion(0.f, 0.f, 1.f, 1.f),
m_target(nullptr), m_target(nullptr),
m_size(0.f), m_size(0.f),
m_projectionScale(1.f, 1.f, 1.f),
m_frustumUpdated(false), m_frustumUpdated(false),
m_projectionMatrixUpdated(false), m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false), m_viewMatrixUpdated(false),
@ -43,6 +44,7 @@ namespace Ndk
m_targetRegion(camera.m_targetRegion), m_targetRegion(camera.m_targetRegion),
m_target(nullptr), m_target(nullptr),
m_size(camera.m_size), m_size(camera.m_size),
m_projectionScale(camera.m_projectionScale),
m_frustumUpdated(false), m_frustumUpdated(false),
m_projectionMatrixUpdated(false), m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false), m_viewMatrixUpdated(false),
@ -115,11 +117,19 @@ namespace Ndk
return m_layer; return m_layer;
} }
/*!
* \brief Gets the projection scale of the camera
* \return Projection scale
*/
const Nz::Vector3f& CameraComponent::GetProjectionScale() const
{
return m_projectionScale;
}
/*! /*!
* \brief Gets the size of the camera * \brief Gets the size of the camera
* \return Size of the camera * \return Size of the camera
*/ */
inline const Nz::Vector2f & CameraComponent::GetSize() const inline const Nz::Vector2f & CameraComponent::GetSize() const
{ {
return m_size; return m_size;

View File

@ -154,11 +154,10 @@ namespace Ndk
} }
/*! /*!
* \brief Sets the layer of the camera in case of multiples fields * \brief Sets the layer of the camera in case of multiples layers
* *
* \param layer Layer of the camera * \param layer Layer of the camera
*/ */
void CameraComponent::SetLayer(unsigned int layer) void CameraComponent::SetLayer(unsigned int layer)
{ {
m_layer = layer; m_layer = layer;
@ -166,10 +165,21 @@ namespace Ndk
m_entity->Invalidate(); // Invalidate the entity to make it passes through RenderSystem validation m_entity->Invalidate(); // Invalidate the entity to make it passes through RenderSystem validation
} }
/*!
* \brief Sets the camera projection scale
*
* \param scale New projection scale
*/
inline void CameraComponent::SetProjectionScale(const Nz::Vector3f& scale)
{
m_projectionScale = scale;
InvalidateProjectionMatrix();
}
/*! /*!
* \brief Operation to perform when component is attached to an entity * \brief Operation to perform when component is attached to an entity
*/ */
void CameraComponent::OnAttached() void CameraComponent::OnAttached()
{ {
if (m_entity->HasComponent<NodeComponent>()) if (m_entity->HasComponent<NodeComponent>())
@ -304,6 +314,8 @@ namespace Ndk
break; break;
} }
m_projectionMatrix *= Nz::Matrix4f::Scale(m_projectionScale);
m_projectionMatrixUpdated = true; m_projectionMatrixUpdated = true;
} }