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

@@ -1,13 +1,12 @@
#include "omath/Matrix.hpp"
#include "omath/Vector3.hpp"
#include "omath/Angles.hpp"
#include "omath/Vector3.hpp"
#include <complex>
#include <format>
#include <utility>
#include <stdexcept>
#include <utility>
#include <complex>
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<float[]>(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<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];
}
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<float&>(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;
}
}
} // namespace omath