From 8a5794cfee28ac21f6a1833f0b869a63282a0a00 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 1 May 2024 21:12:16 -0400 Subject: [PATCH] vec silly --- CMakeLists.txt | 2 +- include/blt/math/vectors.h | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64dce66..413556b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.16.17) +set(BLT_VERSION 0.16.18) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h index cd03f7d..ef0a971 100644 --- a/include/blt/math/vectors.h +++ b/include/blt/math/vectors.h @@ -423,6 +423,52 @@ namespace blt return color4{r, g, b, 1.0f}; } + template + inline blt::vec make_vec2(const blt::vec& t, size_t fill = 0) + { + if constexpr (size >= 2) + { + return blt::vec(t.x(), t.y()); + } else + { + return blt::vec(t.x(), fill); + } + } + + template + inline blt::vec make_vec3(const blt::vec& t, size_t fill = 0) + { + if constexpr (size >= 3) + { + return blt::vec(t.x(), t.y(), t.z()); + } else + { + blt::vec ret; + for (size_t i = 0; i < size; i++) + ret[i] = t[i]; + for (size_t i = size; i < 3; i++) + ret[i] = fill; + return ret; + } + } + + template + inline blt::vec make_vec4(const blt::vec& t, size_t fill = 0) + { + if constexpr (size >= 4) + { + return blt::vec(t.x(), t.y(), t.z(), t.w()); + } else + { + blt::vec ret; + for (size_t i = 0; i < size; i++) + ret[i] = t[i]; + for (size_t i = size; i < 4; i++) + ret[i] = fill; + return ret; + } + } + namespace vec_algorithm { static inline void findOrthogonalBasis(const vec3& v, vec3& v1, vec3& v2, vec3& v3)