modified output dir

This commit is contained in:
2024-11-30 14:11:39 +03:00
parent dac0684405
commit 7e29ea339e
2 changed files with 52 additions and 60 deletions

View File

@@ -6,6 +6,9 @@ project(omath VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 26) 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_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_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) option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)

View File

@@ -1,13 +1,12 @@
#include "omath/Matrix.hpp" #include "omath/Matrix.hpp"
#include "omath/Vector3.hpp"
#include "omath/Angles.hpp" #include "omath/Angles.hpp"
#include "omath/Vector3.hpp"
#include <complex>
#include <format> #include <format>
#include <utility>
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
#include <complex>
namespace omath namespace omath
@@ -31,23 +30,23 @@ namespace omath
m_columns = rows.begin()->size(); m_columns = rows.begin()->size();
for (const auto& row : rows) for (const auto& row: rows)
if (row.size() != m_columns) if (row.size() != m_columns)
throw std::invalid_argument("All rows must have the same number of columns."); throw std::invalid_argument("All rows must have the same number of columns.");
m_data = std::make_unique<float[]>(m_rows * m_columns); m_data = std::make_unique<float[]>(m_rows * m_columns);
size_t i = 0; size_t i = 0;
for (const auto& row : rows) for (const auto& row: rows)
{ {
size_t j = 0; size_t j = 0;
for (const auto& value : row) for (const auto& value: row)
At(i, j++) = value; At(i, j++) = value;
++i; ++i;
} }
} }
Matrix::Matrix(const Matrix &other) Matrix::Matrix(const Matrix& other)
{ {
m_rows = other.m_rows; m_rows = other.m_rows;
m_columns = other.m_columns; m_columns = other.m_columns;
@@ -59,7 +58,7 @@ namespace omath
At(i, j) = other.At(i, j); 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_rows = rows;
m_columns = columns; m_columns = columns;
@@ -67,9 +66,8 @@ namespace omath
m_data = std::make_unique<float[]>(m_rows * m_columns); m_data = std::make_unique<float[]>(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]; At(i / rows, i % columns) = pRaw[i];
} }
size_t Matrix::RowCount() const noexcept size_t Matrix::RowCount() const noexcept
@@ -77,7 +75,7 @@ namespace omath
return m_rows; return m_rows;
} }
Matrix::Matrix(Matrix &&other) noexcept Matrix::Matrix(Matrix&& other) noexcept
{ {
m_rows = other.m_rows; m_rows = other.m_rows;
m_columns = other.m_columns; m_columns = other.m_columns;
@@ -99,7 +97,7 @@ namespace omath
return {RowCount(), ColumnsCount()}; 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<float&>(std::as_const(*this).At(iRow, iCol)); return const_cast<float&>(std::as_const(*this).At(iRow, iCol));
} }
@@ -115,12 +113,12 @@ namespace omath
return sum; 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]; 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) if (m_columns != other.m_rows)
throw std::runtime_error("n != m"); throw std::runtime_error("n != m");
@@ -136,7 +134,7 @@ namespace omath
return outMat; return outMat;
} }
Matrix & Matrix::operator*=(const Matrix &other) Matrix& Matrix::operator*=(const Matrix& other)
{ {
*this = *this * other; *this = *this * other;
return *this; return *this;
@@ -152,7 +150,7 @@ namespace omath
return out; 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 i = 0; i < RowCount(); i++)
for (size_t j = 0; j < ColumnsCount(); j++) for (size_t j = 0; j < ColumnsCount(); j++)
@@ -165,7 +163,7 @@ namespace omath
Set(0.f); Set(0.f);
} }
Matrix &Matrix::operator=(const Matrix &other) Matrix& Matrix::operator=(const Matrix& other)
{ {
if (this == &other) if (this == &other)
return *this; return *this;
@@ -175,10 +173,9 @@ namespace omath
At(i, j) = other.At(i, j); At(i, j) = other.At(i, j);
return *this; return *this;
} }
Matrix &Matrix::operator=(Matrix &&other) noexcept Matrix& Matrix::operator=(Matrix&& other) noexcept
{ {
if (this == &other) if (this == &other)
return *this; return *this;
@@ -191,10 +188,9 @@ namespace omath
other.m_columns = 0; other.m_columns = 0;
return *this; 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 i = 0; i < m_rows; ++i)
for (size_t j = 0; j < m_columns; ++j) for (size_t j = 0; j < m_columns; ++j)
@@ -221,9 +217,9 @@ namespace omath
{ {
for (size_t j = 0; j < m_columns; ++j) 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'; str += '\n';
else else
str += ' '; str += ' ';
@@ -306,8 +302,7 @@ namespace omath
Matrix Matrix::ToScreenMatrix(const float screenWidth, const float screenHeight) Matrix Matrix::ToScreenMatrix(const float screenWidth, const float screenHeight)
{ {
return return {
{
{screenWidth / 2.f, 0.f, 0.f, 0.f}, {screenWidth / 2.f, 0.f, 0.f, 0.f},
{0.f, -screenHeight / 2.f, 0.f, 0.f}, {0.f, -screenHeight / 2.f, 0.f, 0.f},
{0.f, 0.f, 1.f, 0.f}, {0.f, 0.f, 1.f, 0.f},
@@ -315,10 +310,9 @@ namespace omath
}; };
} }
Matrix Matrix::TranslationMatrix(const Vector3 &diff) Matrix Matrix::TranslationMatrix(const Vector3& diff)
{
return
{ {
return {
{1.f, 0.f, 0.f, 0.f}, {1.f, 0.f, 0.f, 0.f},
{0.f, 1.f, 0.f, 0.f}, {0.f, 1.f, 0.f, 0.f},
{0.f, 0.f, 1.f, 0.f}, {0.f, 0.f, 1.f, 0.f},
@@ -326,10 +320,9 @@ namespace omath
}; };
} }
Matrix Matrix::OrientationMatrix(const Vector3 &forward, const Vector3 &right, const Vector3 &up) Matrix Matrix::OrientationMatrix(const Vector3& forward, const Vector3& right, const Vector3& up)
{
return
{ {
return {
{right.x, up.x, forward.x, 0.f}, {right.x, up.x, forward.x, 0.f},
{right.y, up.y, forward.y, 0.f}, {right.y, up.y, forward.y, 0.f},
{right.z, up.z, forward.z, 0.f}, {right.z, up.z, forward.z, 0.f},
@@ -337,18 +330,14 @@ namespace omath
}; };
} }
Matrix Matrix::ProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, Matrix Matrix::ProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, const float far)
const float far)
{ {
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f); const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f);
return return {{1.f / (aspectRatio * fovHalfTan), 0.f, 0.f, 0.f},
{
{1.f / (aspectRatio*fovHalfTan), 0.f, 0.f, 0.f},
{0.f, 1.f / fovHalfTan, 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, (far + near) / (far - near), 2.f * near * far / (far - near)},
{0.f, 0.f, -1.f, 0.f} {0.f, 0.f, -1.f, 0.f}};
};
} }
const float* Matrix::Raw() const const float* Matrix::Raw() const
@@ -356,9 +345,9 @@ namespace omath
return m_data.get(); 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]; At(i / m_rows, i % m_columns) = pRawMatrix[i];
} }
@@ -368,4 +357,4 @@ namespace omath
m_rows = 0; m_rows = 0;
m_data = nullptr; m_data = nullptr;
} }
} } // namespace omath