Move projectionView retrieving to camera system

This commit is contained in:
Riyyi
2021-01-14 12:16:09 +01:00
parent 0b2cc9f411
commit f47643d257
3 changed files with 22 additions and 7 deletions
+1 -7
View File
@@ -99,13 +99,7 @@ namespace Inferno {
glm::mat4 Scene::cameraProjectionView() glm::mat4 Scene::cameraProjectionView()
{ {
auto view = m_registry->view<TransformComponent, PerspectiveCameraComponent>(); return CameraSystem::the().cameraProjectionView();
for(auto&& [entity, transform, perspective] : view.each()) {
return perspective.projection * transform.transform;
}
return glm::mat4 { 1.0f };
} }
} }
+19
View File
@@ -43,6 +43,25 @@ namespace Inferno {
s_instance = nullptr; s_instance = nullptr;
} }
glm::mat4 CameraSystem::cameraProjectionView()
{
auto orthoView = m_registry->view<TransformComponent, OrthographicCameraComponment>();
for(auto&& [entity, transform, orthographic] : orthoView.each()) {
return orthographic.projection * transform.transform;
}
auto perspectiveView = m_registry->view<TransformComponent, PerspectiveCameraComponent>();
for(auto&& [entity, transform, perspective] : perspectiveView.each()) {
return perspective.projection * transform.transform;
}
ASSERT_NOT_REACHED();
return glm::mat4 { 1.0f };
}
void CameraSystem::updateOrthographic(TransformComponent& transform, OrthographicCameraComponment& orthographic) void CameraSystem::updateOrthographic(TransformComponent& transform, OrthographicCameraComponment& orthographic)
{ {
+2
View File
@@ -24,6 +24,8 @@ namespace Inferno {
void update(); void update();
void destroy(); void destroy();
glm::mat4 cameraProjectionView();
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; }; void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; };
static inline CameraSystem& the() { return *s_instance; } static inline CameraSystem& the() { return *s_instance; }