diff --git a/include/omath/projection/Camera.hpp b/include/omath/projection/Camera.hpp index c94da1f..a6723a1 100644 --- a/include/omath/projection/Camera.hpp +++ b/include/omath/projection/Camera.hpp @@ -37,6 +37,7 @@ namespace omath::projection m_viewPort(viewPort), m_fieldOfView(fov), m_farPlaneDistance(far), m_nearPlaneDistance(near), m_viewAngles(viewAngles), m_origin(position) { + } virtual void LookAt(const Vector3& target) = 0; @@ -45,12 +46,15 @@ namespace omath::projection [[nodiscard]] virtual Mat4x4Type GetProjectionMatrix() const = 0; - [[nodiscard]] Mat4x4Type GetViewProjectionMatrix() const + [[nodiscard]] Mat4x4Type GetViewProjectionMatrix() { - return GetProjectionMatrix() * GetViewMatrix(); + if (!m_viewProjectionMatrix) + m_viewProjectionMatrix = GetProjectionMatrix() * GetViewMatrix(); + + return m_viewProjectionMatrix.value(); } - [[nodiscard]] std::expected WorldToScreen(const Vector3& worldPosition) const + [[nodiscard]] std::expected WorldToScreen(const Vector3& worldPosition) { auto projected = GetViewProjectionMatrix() * MatColumnFromVector(worldPosition); @@ -77,7 +81,7 @@ namespace omath::projection Vector3 m_origin; private: - + std::optional m_viewProjectionMatrix = std::nullopt; template [[nodiscard]] constexpr static bool IsNdcOutOfBounds(const Type& ndc)