camera notify

This commit is contained in:
2025-07-16 12:54:50 +02:00
parent aaf76a3ff0
commit 1bee6aed9c
8 changed files with 69 additions and 24 deletions

View File

@@ -8,6 +8,7 @@ namespace render {
void Camera::UpdatePerspective(float a_AspectRatio) {
m_ProjectionMatrix = maths::Perspective(80.0f / 180.0f * PI, a_AspectRatio, 0.1f, 160.0f);
m_InvProjectionMatrix = maths::Inverse(m_ProjectionMatrix);
NotifyListeners(&ICameraListener::OnPerspectiveChange);
}
void Camera::SetCamPos(const Vec3f& a_NewPos) {
@@ -20,6 +21,7 @@ void Camera::SetCamPos(const Vec3f& a_NewPos) {
m_CamPos = a_NewPos;
m_ViewMatrix = maths::Look(m_CamPos, front, { 0, 1, 0 });
m_InvViewMatrix = maths::Transpose(maths::Inverse(m_ViewMatrix)); // why transpose ? I don't know
NotifyListeners(&ICameraListener::OnViewChange);
}
} // namespace render

View File

@@ -7,20 +7,28 @@
namespace td {
namespace render {
WorldRenderer::WorldRenderer(Camera& a_Camera, const game::World& a_World) : Renderer(a_Camera), m_World(a_World){
WorldRenderer::WorldRenderer(Camera& a_Camera, const game::World& a_World) : Renderer(a_Camera), m_World(a_World) {
m_WorldVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::LoadWorldModel(&a_World)));
a_Camera.BindListener(this);
}
WorldRenderer::~WorldRenderer() {}
void WorldRenderer::Render() {
m_Shader.Start();
m_Shader.SetProjectionMatrix(m_Camera.GetProjectionMatrix());
m_Shader.SetViewMatrix(m_Camera.GetViewMatrix());
Renderer::Render(*m_WorldVao);
ImGui::ShowDemoWindow();
}
void WorldRenderer::OnPerspectiveChange() {
m_Shader.Start();
m_Shader.SetProjectionMatrix(m_Camera.GetProjectionMatrix());
}
void WorldRenderer::OnViewChange() {
m_Shader.Start();
m_Shader.SetViewMatrix(m_Camera.GetViewMatrix());
}
} // namespace render
} // namespace td