diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dae960..85d8510 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) 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_TARGET BLT) diff --git a/include/blt/math/matrix.h b/include/blt/math/matrix.h index dbab8e3..5a3200a 100644 --- a/include/blt/math/matrix.h +++ b/include/blt/math/matrix.h @@ -137,7 +137,7 @@ namespace blt T magnitude() const { - T ret; + T ret{}; for (blt::u32 i = 0; i < columns; i++) { for (blt::u32 j = 0; j < rows; j++) @@ -175,6 +175,49 @@ namespace blt 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 + constexpr inline matrix_t& assign_to_column_from_column_rows(generalized_matrix 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 constexpr inline friend matrix_t operator+(const matrix_t& left, const matrix_t& right) { diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h index 8de0a9c..f7a88a9 100644 --- a/include/blt/math/vectors.h +++ b/include/blt/math/vectors.h @@ -140,12 +140,12 @@ namespace blt return *this / mag; } - constexpr inline T& operator[](int index) + constexpr inline T& operator[](blt::size_t index) { return elements[index]; } - constexpr inline T operator[](int index) const + constexpr inline T operator[](blt::size_t index) const { return elements[index]; }