normalize

v1
Brett 2024-09-20 00:37:39 -04:00
parent 1ceb71aac9
commit 39fd5a73d6
3 changed files with 47 additions and 4 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake) include(cmake/color.cmake)
set(BLT_VERSION 0.20.12) set(BLT_VERSION 0.20.13)
set(BLT_TEST_VERSION 0.0.1) set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT) set(BLT_TARGET BLT)

View File

@ -137,7 +137,7 @@ namespace blt
T magnitude() const T magnitude() const
{ {
T ret; T ret{};
for (blt::u32 i = 0; i < columns; i++) for (blt::u32 i = 0; i < columns; i++)
{ {
for (blt::u32 j = 0; j < rows; j++) for (blt::u32 j = 0; j < rows; j++)
@ -175,6 +175,49 @@ namespace blt
return data[column][row] = value; return data[column][row] = value;
}; };
/**
* Assign to this matrix from the row information in each column of a matrix
* Where columns can be assigned directly from each-other, row stored data must be assigned this way
* this was hacked together for an assignment and a better way is a TODO;
* @param to_column column in this matrix to assign to
* @param row the row place that the value is store in to assign from. Defaults to the first element in each column
*/
template<blt::u32 p>
constexpr inline matrix_t& assign_to_column_from_column_rows(generalized_matrix<T, p, rows> mat, blt::u32 to_column, blt::u32 row = 0)
{
for (blt::u32 j = 0; j < rows; j++)
data[to_column][j] = mat[j][row];
return *this;
}
constexpr inline matrix_t& operator+=(const matrix_t& other)
{
for (blt::u32 i = 0; i < columns; i++)
data[i] += other[i];
return *this;
}
constexpr inline matrix_t& operator-=(const matrix_t& other)
{
for (blt::u32 i = 0; i < columns; i++)
data[i] -= other[i];
return *this;
}
constexpr inline matrix_t& operator*=(const matrix_t& other)
{
for (blt::u32 i = 0; i < columns; i++)
data[i] *= other[i];
return *this;
}
constexpr inline matrix_t& operator/=(const matrix_t& other)
{
for (blt::u32 i = 0; i < columns; i++)
data[i] /= other[i];
return *this;
}
// adds the two mat4x4 left and right // adds the two mat4x4 left and right
constexpr inline friend matrix_t operator+(const matrix_t& left, const matrix_t& right) constexpr inline friend matrix_t operator+(const matrix_t& left, const matrix_t& right)
{ {

View File

@ -140,12 +140,12 @@ namespace blt
return *this / mag; return *this / mag;
} }
constexpr inline T& operator[](int index) constexpr inline T& operator[](blt::size_t index)
{ {
return elements[index]; return elements[index];
} }
constexpr inline T operator[](int index) const constexpr inline T operator[](blt::size_t index) const
{ {
return elements[index]; return elements[index];
} }