From 4b0226929b0cbc85d9c8cdf97920720c0306f728 Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 21 Apr 2023 21:04:19 -0400 Subject: [PATCH] add return statement to matrix class --- include/blt/math/matrix.h | 1 + include/blt/math/vectors.h | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/blt/math/matrix.h b/include/blt/math/matrix.h index ccec5d2..cd607bd 100644 --- a/include/blt/math/matrix.h +++ b/include/blt/math/matrix.h @@ -62,6 +62,7 @@ namespace blt { for (int i = 0; i < 16; i++) { data.single[i] = copy.data.single[i]; } + return *this; } explicit mat4x4(const float dat[16]) { diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h index 4362fcf..62d5206 100644 --- a/include/blt/math/vectors.h +++ b/include/blt/math/vectors.h @@ -21,14 +21,9 @@ namespace blt { } #define MSVC_COMPILER (!defined(__GNUC__) && !defined(__clang__)) - -#ifdef MSVC_COMPILER + template -#else - // STFINAE is broken in MSVC? - template::value>::type* = nullptr> -#endif struct vec { private: T elements[size]{}; @@ -159,7 +154,9 @@ namespace blt { return dot; } - static inline constexpr vec cross(const vec& left, const vec& right) { + static inline constexpr vec cross( + const vec& left, const vec& right + ) { // cross is only defined on vectors of size 3. 2D could be implemented, which is a TODO static_assert(size == 3); return {left.y() * right.z() - left.z() * right.y(), @@ -167,7 +164,9 @@ namespace blt { left.x() * right.y() - left.y() * right.x()}; } - static inline constexpr vec project(const vec& u, const vec& v){ + static inline constexpr vec project( + const vec& u, const vec& v + ) { T du = dot(u); T dv = dot(v); return (du / dv) * v; @@ -301,25 +300,25 @@ namespace blt { namespace vec_algorithm { static inline void findOrthogonalBasis(const vec3& v, vec3& v1, vec3& v2, vec3& v3) { v1 = v.normalize(); - + vec3 arbitraryVector{1, 0, 0}; if (std::abs(vec3::dot(v, arbitraryVector)) > 0.9) { arbitraryVector = vec3{0, 1, 0}; } - + v2 = vec3::cross(v, arbitraryVector).normalize(); v3 = vec3::cross(v1, v2); } - + // Gram-Schmidt orthonormalization algorithm static inline void gramSchmidt(std::vector& vectors) { - int n = (int)vectors.size(); + int n = (int) vectors.size(); std::vector basis; - + // normalize first vector basis.push_back(vectors[0]); basis[0] = basis[0].normalize(); - + // iterate over the rest of the vectors for (int i = 1; i < n; ++i) { // subtract the projections of the vector onto the previous basis vectors @@ -334,7 +333,7 @@ namespace blt { new_vector = new_vector.normalize(); basis.push_back(new_vector); } - + vectors = basis; } }