Files
Tower-Defense2/include/td/render/Camera.h
2025-07-16 12:54:50 +02:00

47 lines
878 B
C++

#pragma once
#include <td/Maths.h>
#include <td/misc/ObjectNotifier.h>
namespace td {
namespace render {
class ICameraListener {
public:
virtual void OnPerspectiveChange() {}
virtual void OnViewChange() {}
};
using CameraNotifier = utils::ObjectNotifier<ICameraListener>;
class Camera : public CameraNotifier {
private:
Mat4f m_ViewMatrix;
Mat4f m_ProjectionMatrix;
Mat4f m_InvViewMatrix;
Mat4f m_InvProjectionMatrix;
float m_CamDistance = 25.0f;
Vec3f m_CamPos{0, m_CamDistance, 0};
Vec2f m_CamLook{};
float m_Yaw = -PI / 2.0f;
float m_Pitch = -PI / 2.0f + 0.0000001f;
public:
const Mat4f& GetViewMatrix() const {
return m_ViewMatrix;
}
const Mat4f& GetProjectionMatrix() const {
return m_ProjectionMatrix;
}
void UpdatePerspective(float a_AspectRatio);
void SetCamPos(const Vec3f& a_NewPos);
};
} // namespace render
} // namespace td