diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c95062..6dae960 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.11) +set(BLT_VERSION 0.20.12) 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 d49ec2f..dbab8e3 100644 --- a/include/blt/math/matrix.h +++ b/include/blt/math/matrix.h @@ -135,6 +135,26 @@ namespace blt return mat; } + T magnitude() const + { + T ret; + for (blt::u32 i = 0; i < columns; i++) + { + for (blt::u32 j = 0; j < rows; j++) + ret += (data[i][j] * data[i][j]); + } + return std::sqrt(ret); + } + + matrix_t normalize() const + { + auto mag = magnitude(); + matrix_t mat = *this; + if (mag == 0) + return mat; + return mat / mag; + } + constexpr inline const blt::vec& operator[](u32 column) const { return data[column];