From 7e29ea339e6d48df9d4d618bbe711a269abf790e Mon Sep 17 00:00:00 2001 From: Orange Date: Sat, 30 Nov 2024 14:11:39 +0300 Subject: [PATCH] modified output dir --- CMakeLists.txt | 3 ++ source/Matrix.cpp | 109 +++++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2d004b..f79bac9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,9 @@ project(omath VERSION 1.0.0) set(CMAKE_CXX_STANDARD 26) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}") + option(OMATH_BUILD_TESTS "Build unit tests" ON) option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON) option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF) diff --git a/source/Matrix.cpp b/source/Matrix.cpp index de92ab9..b07dde4 100644 --- a/source/Matrix.cpp +++ b/source/Matrix.cpp @@ -1,13 +1,12 @@ #include "omath/Matrix.hpp" -#include "omath/Vector3.hpp" #include "omath/Angles.hpp" +#include "omath/Vector3.hpp" +#include #include -#include #include #include -#include namespace omath @@ -31,23 +30,23 @@ namespace omath m_columns = rows.begin()->size(); - for (const auto& row : rows) + for (const auto& row: rows) if (row.size() != m_columns) throw std::invalid_argument("All rows must have the same number of columns."); m_data = std::make_unique(m_rows * m_columns); size_t i = 0; - for (const auto& row : rows) + for (const auto& row: rows) { size_t j = 0; - for (const auto& value : row) + for (const auto& value: row) At(i, j++) = value; ++i; } } - Matrix::Matrix(const Matrix &other) + Matrix::Matrix(const Matrix& other) { m_rows = other.m_rows; m_columns = other.m_columns; @@ -59,7 +58,7 @@ namespace omath At(i, j) = other.At(i, j); } - Matrix::Matrix(const size_t rows, const size_t columns, const float *pRaw) + Matrix::Matrix(const size_t rows, const size_t columns, const float* pRaw) { m_rows = rows; m_columns = columns; @@ -67,9 +66,8 @@ namespace omath m_data = std::make_unique(m_rows * m_columns); - for (size_t i = 0; i < rows*columns; ++i) + for (size_t i = 0; i < rows * columns; ++i) At(i / rows, i % columns) = pRaw[i]; - } size_t Matrix::RowCount() const noexcept @@ -77,7 +75,7 @@ namespace omath return m_rows; } - Matrix::Matrix(Matrix &&other) noexcept + Matrix::Matrix(Matrix&& other) noexcept { m_rows = other.m_rows; m_columns = other.m_columns; @@ -99,7 +97,7 @@ namespace omath return {RowCount(), ColumnsCount()}; } - float &Matrix::At(const size_t iRow, const size_t iCol) + float& Matrix::At(const size_t iRow, const size_t iCol) { return const_cast(std::as_const(*this).At(iRow, iCol)); } @@ -115,12 +113,12 @@ namespace omath return sum; } - const float &Matrix::At(const size_t iRow, const size_t iCol) const + const float& Matrix::At(const size_t iRow, const size_t iCol) const { return m_data[iRow * m_columns + iCol]; } - Matrix Matrix::operator*(const Matrix &other) const + Matrix Matrix::operator*(const Matrix& other) const { if (m_columns != other.m_rows) throw std::runtime_error("n != m"); @@ -136,7 +134,7 @@ namespace omath return outMat; } - Matrix & Matrix::operator*=(const Matrix &other) + Matrix& Matrix::operator*=(const Matrix& other) { *this = *this * other; return *this; @@ -152,7 +150,7 @@ namespace omath return out; } - Matrix &Matrix::operator*=(const float f) + Matrix& Matrix::operator*=(const float f) { for (size_t i = 0; i < RowCount(); i++) for (size_t j = 0; j < ColumnsCount(); j++) @@ -164,8 +162,8 @@ namespace omath { Set(0.f); } - - Matrix &Matrix::operator=(const Matrix &other) + + Matrix& Matrix::operator=(const Matrix& other) { if (this == &other) return *this; @@ -175,10 +173,9 @@ namespace omath At(i, j) = other.At(i, j); return *this; - } - Matrix &Matrix::operator=(Matrix &&other) noexcept + Matrix& Matrix::operator=(Matrix&& other) noexcept { if (this == &other) return *this; @@ -191,10 +188,9 @@ namespace omath other.m_columns = 0; return *this; - } - Matrix &Matrix::operator/=(const float f) + Matrix& Matrix::operator/=(const float f) { for (size_t i = 0; i < m_rows; ++i) for (size_t j = 0; j < m_columns; ++j) @@ -221,9 +217,9 @@ namespace omath { for (size_t j = 0; j < m_columns; ++j) { - str += std::format("{:.1f}",At(i, j)); + str += std::format("{:.1f}", At(i, j)); - if (j == m_columns-1) + if (j == m_columns - 1) str += '\n'; else str += ' '; @@ -306,49 +302,42 @@ namespace omath Matrix Matrix::ToScreenMatrix(const float screenWidth, const float screenHeight) { - return - { - {screenWidth / 2.f, 0.f, 0.f, 0.f}, - {0.f, -screenHeight / 2.f, 0.f, 0.f}, - {0.f, 0.f, 1.f, 0.f}, - {screenWidth / 2.f, screenHeight / 2.f, 0.f, 1.f}, - }; - } - - Matrix Matrix::TranslationMatrix(const Vector3 &diff) - { - return - { - {1.f, 0.f, 0.f, 0.f}, - {0.f, 1.f, 0.f, 0.f}, - {0.f, 0.f, 1.f, 0.f}, - {diff.x, diff.y, diff.z, 1.f}, + return { + {screenWidth / 2.f, 0.f, 0.f, 0.f}, + {0.f, -screenHeight / 2.f, 0.f, 0.f}, + {0.f, 0.f, 1.f, 0.f}, + {screenWidth / 2.f, screenHeight / 2.f, 0.f, 1.f}, }; } - Matrix Matrix::OrientationMatrix(const Vector3 &forward, const Vector3 &right, const Vector3 &up) + Matrix Matrix::TranslationMatrix(const Vector3& diff) { - return - { - {right.x, up.x, forward.x, 0.f}, - {right.y, up.y, forward.y, 0.f}, - {right.z, up.z, forward.z, 0.f}, - {0.f, 0.f, 0.f, 1.f}, + return { + {1.f, 0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f, 0.f}, + {0.f, 0.f, 1.f, 0.f}, + {diff.x, diff.y, diff.z, 1.f}, }; } - Matrix Matrix::ProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, - const float far) + Matrix Matrix::OrientationMatrix(const Vector3& forward, const Vector3& right, const Vector3& up) + { + return { + {right.x, up.x, forward.x, 0.f}, + {right.y, up.y, forward.y, 0.f}, + {right.z, up.z, forward.z, 0.f}, + {0.f, 0.f, 0.f, 1.f}, + }; + } + + Matrix Matrix::ProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, const float far) { const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f); - return - { - {1.f / (aspectRatio*fovHalfTan), 0.f, 0.f, 0.f}, - {0.f, 1.f / fovHalfTan, 0.f, 0.f}, - {0.f, 0.f, (far + near) / (far - near), 2.f * near * far / (far - near)}, - {0.f, 0.f, -1.f, 0.f} - }; + return {{1.f / (aspectRatio * fovHalfTan), 0.f, 0.f, 0.f}, + {0.f, 1.f / fovHalfTan, 0.f, 0.f}, + {0.f, 0.f, (far + near) / (far - near), 2.f * near * far / (far - near)}, + {0.f, 0.f, -1.f, 0.f}}; } const float* Matrix::Raw() const @@ -356,9 +345,9 @@ namespace omath return m_data.get(); } - void Matrix::SetDataFromRaw(const float *pRawMatrix) + void Matrix::SetDataFromRaw(const float* pRawMatrix) { - for (size_t i = 0; i < m_columns*m_rows; ++i) + for (size_t i = 0; i < m_columns * m_rows; ++i) At(i / m_rows, i % m_columns) = pRawMatrix[i]; } @@ -368,4 +357,4 @@ namespace omath m_rows = 0; m_data = nullptr; } -} \ No newline at end of file +} // namespace omath