diff --git a/include/omath/Mat.hpp b/include/omath/Mat.hpp index 9d91ab5..17964cf 100644 --- a/include/omath/Mat.hpp +++ b/include/omath/Mat.hpp @@ -34,11 +34,13 @@ namespace omath class Mat final { public: - constexpr Mat() + constexpr Mat() noexcept { Clear(); } - constexpr static MatStoreType GetStoreOrdering() + + [[nodiscard]] + constexpr static MatStoreType GetStoreOrdering() noexcept { return StoreType; } @@ -72,6 +74,7 @@ namespace omath m_data = other.m_data; } + [[nodiscard]] constexpr Type& operator[](const size_t row, const size_t col) { return At(row, col); @@ -100,7 +103,8 @@ namespace omath return {Rows, Columns}; } - [[nodiscard]] constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const + [[nodiscard]] + constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const { if (rowIndex >= Rows || columnIndex >= Columns) throw std::out_of_range("Index out of range"); @@ -177,6 +181,7 @@ namespace omath return *this = *this * other; } + [[nodiscard]] constexpr Mat operator*(const Type& f) const noexcept { Mat result(*this); @@ -192,6 +197,7 @@ namespace omath return *this; } + [[nodiscard]] constexpr Mat operator/(const Type& f) const noexcept { Mat result(*this); diff --git a/include/omath/projection/Camera.hpp b/include/omath/projection/Camera.hpp index 4d96737..c6bacbb 100644 --- a/include/omath/projection/Camera.hpp +++ b/include/omath/projection/Camera.hpp @@ -38,7 +38,7 @@ namespace omath::projection { } - + protected: virtual void LookAt(const Vector3& target) = 0; [[nodiscard]] virtual Mat4x4Type CalcViewMatrix() const = 0; @@ -49,41 +49,44 @@ namespace omath::projection { return CalcProjectionMatrix() * CalcViewMatrix(); } + public: + + [[nodiscard]] const Mat4x4Type& GetViewProjectionMatrix() const + { + if (!m_viewProjectionMatrix.has_value()) + m_viewProjectionMatrix = CalcViewProjectionMatrix(); + + return m_viewProjectionMatrix.value(); + } void SetFieldOfView(const FieldOfView& fov) { m_fieldOfView = fov; - m_viewProjectionMatrix = CalcViewProjectionMatrix(); } void SetNearPlane(const float near) { m_nearPlaneDistance = near; - m_viewProjectionMatrix = CalcViewProjectionMatrix(); } void SetFarPlane(const float far) { m_farPlaneDistance = far; - m_viewProjectionMatrix = CalcViewProjectionMatrix(); } void SetViewAngles(const ViewAnglesType& viewAngles) { m_viewAngles = viewAngles; - m_viewProjectionMatrix = CalcViewProjectionMatrix(); } void SetOrigin(const Vector3& origin) { m_origin = origin; - m_viewProjectionMatrix = CalcViewProjectionMatrix(); } void SetViewPort(const ViewPort& viewPort) { m_viewPort = viewPort; - m_viewProjectionMatrix = CalcViewProjectionMatrix(); } [[nodiscard]] const FieldOfView& GetFieldOfView() const @@ -113,10 +116,9 @@ namespace omath::projection [[nodiscard]] std::expected, Error> WorldToScreen(const Vector3& worldPosition) const { - if (!m_viewProjectionMatrix.has_value()) - m_viewProjectionMatrix = CalcViewProjectionMatrix(); + const auto& viewProjMatrix = GetViewProjectionMatrix(); - auto projected = m_viewProjectionMatrix.value() * MatColumnFromVector(worldPosition); + auto projected = viewProjMatrix * MatColumnFromVector(worldPosition); if (projected.At(3, 0) == 0.0f) return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);