diff --git a/CMakeLists.txt b/CMakeLists.txt index 3978d16..a585a05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.25) include(FetchContent) -set(BLT_GRAPHICS_VERSION 2.0.6) +set(BLT_GRAPHICS_VERSION 2.0.7) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/renderer/batch_2d_renderer.h b/include/blt/gfx/renderer/batch_2d_renderer.h index e58feb6..48648ef 100644 --- a/include/blt/gfx/renderer/batch_2d_renderer.h +++ b/include/blt/gfx/renderer/batch_2d_renderer.h @@ -123,7 +123,8 @@ namespace blt::gfx [[nodiscard]] f32 length_fast() const; - vec2 m_p0, m_p1, m_p2, m_p3; + vec2 m_p0, m_p1, m_p2; + std::optional m_p3; }; struct point2d_t diff --git a/src/blt/gfx/renderer/batch_2d_renderer.cpp b/src/blt/gfx/renderer/batch_2d_renderer.cpp index 3cd52a9..8042970 100644 --- a/src/blt/gfx/renderer/batch_2d_renderer.cpp +++ b/src/blt/gfx/renderer/batch_2d_renderer.cpp @@ -127,14 +127,13 @@ namespace blt::gfx return length; } - curve2d_t::curve2d_t(const vec2 p0, const vec2 p1): m_p0(p0), m_p3(p1) + curve2d_t::curve2d_t(const vec2 p0, const vec2 p1): m_p0(p0), m_p2(p1) { - const auto dir = (p1 - p0) / 3; + const auto dir = (p1 - p0) / 2; m_p1 = p0 + dir; - m_p2 = p1 - dir; } - curve2d_t::curve2d_t(const vec2 p0, const vec2 p1, const vec2 p2): m_p0(p0), m_p1(p1), m_p2(p1), m_p3(p2) + curve2d_t::curve2d_t(const vec2 p0, const vec2 p1, const vec2 p2): m_p0(p0), m_p1(p1), m_p2(p2) {} curve2d_t::curve2d_t(const vec2 p0, const vec2 p1, const vec2 p2, const vec2 p3): m_p0(p0), m_p1(p1), m_p2(p2), m_p3(p3) @@ -144,10 +143,14 @@ namespace blt::gfx { const auto t_inv = 1.0f - t; const auto t_inv_sq = t_inv * t_inv; - const auto t_inv_cub = t_inv_sq * t_inv; const auto t_sq = t * t; - const auto t_cub = t_sq * t; - return t_inv_cub * m_p0 + 3 * t_inv_sq * t * m_p1 + 3 * t_inv * t_sq * m_p2 + t_cub * m_p3; + if (m_p3) + { + const auto t_inv_cub = t_inv_sq * t_inv; + const auto t_cub = t_sq * t; + return t_inv_cub * m_p0 + 3 * t_inv_sq * t * m_p1 + 3 * t_inv * t_sq * m_p2 + t_cub * *m_p3; + } + return t_inv_sq * m_p0 + 2 * t_inv * t * m_p1 + t_sq * m_p2; } std::vector curve2d_t::to_lines(const i32 segments, const float thickness) const @@ -196,8 +199,12 @@ namespace blt::gfx { const auto d1 = (m_p1 - m_p0).magnitude(); const auto d2 = (m_p2 - m_p1).magnitude(); - const auto d3 = (m_p3 - m_p2).magnitude(); - return d1 + d2 + d3; + if (m_p3) + { + const auto d3 = (*m_p3 - m_p2).magnitude(); + return d1 + d2 + d3; + } + return d1 + d2; } void batch_renderer_2d::create()