diff --git a/headers/enduro2d/high/components/colliders.hpp b/headers/enduro2d/high/components/colliders.hpp index a5acb81d..40085589 100644 --- a/headers/enduro2d/high/components/colliders.hpp +++ b/headers/enduro2d/high/components/colliders.hpp @@ -136,6 +136,7 @@ namespace e2d static const char* title; void operator()(gcomponent& c) const; + void operator()(gcomponent& c, gizmos_context& ctx) const; }; template <> @@ -144,6 +145,7 @@ namespace e2d static const char* title; void operator()(gcomponent& c) const; + void operator()(gcomponent& c, gizmos_context& ctx) const; }; template <> @@ -152,6 +154,7 @@ namespace e2d static const char* title; void operator()(gcomponent& c) const; + void operator()(gcomponent& c, gizmos_context& ctx) const; }; } diff --git a/headers/enduro2d/math/trig.hpp b/headers/enduro2d/math/trig.hpp index 49fb6fe7..dc519009 100644 --- a/headers/enduro2d/math/trig.hpp +++ b/headers/enduro2d/math/trig.hpp @@ -90,6 +90,11 @@ namespace e2d::math return deg * deg_to_rad(); } + template < typename T > + rad deg_to_rad(const deg& deg) noexcept { + return rad(deg_to_rad(deg.value)); + } + // // rad_to_deg // @@ -111,6 +116,11 @@ namespace e2d::math rad_to_deg(T rad) noexcept { return rad * rad_to_deg(); } + + template < typename T > + deg rad_to_deg(const rad& rad) noexcept { + return deg(rad_to_deg(rad.value)); + } } namespace e2d @@ -129,7 +139,7 @@ namespace e2d struct unit_converter { template < typename T > deg operator()(const rad& u) const noexcept { - return make_deg(math::rad_to_deg(u.value)); + return math::rad_to_deg(u); } }; @@ -138,7 +148,7 @@ namespace e2d public: template < typename T > rad operator()(const deg& u) const noexcept { - return make_rad(math::deg_to_rad(u.value)); + return math::deg_to_rad(u); } }; } @@ -154,11 +164,21 @@ namespace e2d::math return u.template convert_to(); } + template < typename T, typename Tag > + T to_deg_v(const unit& u) noexcept { + return to_deg(u).value; + } + template < typename T, typename Tag > rad to_rad(const unit& u) noexcept { return u.template convert_to(); } + template < typename T, typename Tag > + T to_rad_v(const unit& u) noexcept { + return to_rad(u).value; + } + // // cos/sin/tan // diff --git a/samples/bin/library/scenes/sample_08.json b/samples/bin/library/scenes/sample_08.json index 0b4f55fd..e832b4ca 100644 --- a/samples/bin/library/scenes/sample_08.json +++ b/samples/bin/library/scenes/sample_08.json @@ -31,6 +31,9 @@ }, "rect_collider" : { "size" : [66,113] + }, + "circle_collider" : { + "radius" : 33 } } },{ @@ -52,6 +55,14 @@ }, "rect_collider" : { "size" : [66,113] + }, + "polygon_collider" : { + "points" : [ + [-20,0], + [20,0], + [30,-50], + [-30,-50] + ] } } },{ diff --git a/samples/bin/library/sprites/ship_sprite.json b/samples/bin/library/sprites/ship_sprite.json index c6235341..d8d0203e 100644 --- a/samples/bin/library/sprites/ship_sprite.json +++ b/samples/bin/library/sprites/ship_sprite.json @@ -1,5 +1,5 @@ { "texture" : "ships.png", - "pivot" : { "x" : 441, "y" : 340 }, + "pivot" : { "x" : 441, "y" : 340.5 }, "texrect" : { "x" : 408, "y" : 284, "w" : 66, "h" : 113 } } diff --git a/scripts/cloc_all.sh b/scripts/cloc_all.sh index 8562034a..866dfa4c 100755 --- a/scripts/cloc_all.sh +++ b/scripts/cloc_all.sh @@ -6,4 +6,15 @@ cloc \ $SCRIPT_DIR/../samples/bin \ $SCRIPT_DIR/../samples/sources \ $SCRIPT_DIR/../untests/bin \ - $SCRIPT_DIR/../untests/sources + $SCRIPT_DIR/../untests/sources \ + $SCRIPT_DIR/../modules/curly.hpp/headers \ + $SCRIPT_DIR/../modules/curly.hpp/sources \ + $SCRIPT_DIR/../modules/curly.hpp/untests \ + $SCRIPT_DIR/../modules/ecs.hpp/headers \ + $SCRIPT_DIR/../modules/ecs.hpp/untests \ + $SCRIPT_DIR/../modules/enum.hpp/headers \ + $SCRIPT_DIR/../modules/enum.hpp/untests \ + $SCRIPT_DIR/../modules/flat.hpp/headers \ + $SCRIPT_DIR/../modules/flat.hpp/untests \ + $SCRIPT_DIR/../modules/promise.hpp/headers \ + $SCRIPT_DIR/../modules/promise.hpp/untests diff --git a/scripts/cloc_engine.sh b/scripts/cloc_engine.sh index 57b570c6..e7d31dbd 100755 --- a/scripts/cloc_engine.sh +++ b/scripts/cloc_engine.sh @@ -2,4 +2,10 @@ SCRIPT_DIR=`dirname "$BASH_SOURCE"` cloc \ $SCRIPT_DIR/../headers/enduro2d \ - $SCRIPT_DIR/../sources/enduro2d + $SCRIPT_DIR/../sources/enduro2d \ + $SCRIPT_DIR/../modules/curly.hpp/headers \ + $SCRIPT_DIR/../modules/curly.hpp/sources \ + $SCRIPT_DIR/../modules/ecs.hpp/headers \ + $SCRIPT_DIR/../modules/enum.hpp/headers \ + $SCRIPT_DIR/../modules/flat.hpp/headers \ + $SCRIPT_DIR/../modules/promise.hpp/headers diff --git a/scripts/cloc_modules.sh b/scripts/cloc_modules.sh new file mode 100755 index 00000000..7fba43c1 --- /dev/null +++ b/scripts/cloc_modules.sh @@ -0,0 +1,14 @@ +#!/bin/bash +SCRIPT_DIR=`dirname "$BASH_SOURCE"` +cloc \ + $SCRIPT_DIR/../modules/curly.hpp/headers \ + $SCRIPT_DIR/../modules/curly.hpp/sources \ + $SCRIPT_DIR/../modules/curly.hpp/untests \ + $SCRIPT_DIR/../modules/ecs.hpp/headers \ + $SCRIPT_DIR/../modules/ecs.hpp/untests \ + $SCRIPT_DIR/../modules/enum.hpp/headers \ + $SCRIPT_DIR/../modules/enum.hpp/untests \ + $SCRIPT_DIR/../modules/flat.hpp/headers \ + $SCRIPT_DIR/../modules/flat.hpp/untests \ + $SCRIPT_DIR/../modules/promise.hpp/headers \ + $SCRIPT_DIR/../modules/promise.hpp/untests diff --git a/sources/enduro2d/high/components/colliders.cpp b/sources/enduro2d/high/components/colliders.cpp index dd0b5e34..d7dbfecd 100644 --- a/sources/enduro2d/high/components/colliders.cpp +++ b/sources/enduro2d/high/components/colliders.cpp @@ -240,6 +240,20 @@ namespace e2d collider_base_inspector(*c); } + + void component_inspector::operator()( + gcomponent& c, + gizmos_context& ctx) const + { + const v2f& p = c->offset() - c->size() * 0.5f; + const v2f& s = c->size(); + ctx.draw_wire_rect( + p, + p + s * v2f::unit_x(), + p + s, + p + s * v2f::unit_y(), + ctx.selected() ? color32::cyan() : color32::green()); + } } namespace e2d @@ -255,6 +269,17 @@ namespace e2d collider_base_inspector(*c); } + + void component_inspector::operator()( + gcomponent& c, + gizmos_context& ctx) const + { + ctx.draw_wire_circle( + c->offset(), + c->radius(), + math::to_rad_v(math::two_pi()) * c->radius() * 0.2f, + ctx.selected() ? color32::cyan() : color32::green()); + } } namespace e2d @@ -288,4 +313,18 @@ namespace e2d collider_base_inspector(*c); } + + void component_inspector::operator()( + gcomponent& c, + gizmos_context& ctx) const + { + const v2f& o = c->offset(); + const vector& points = c->points(); + for ( std::size_t i = 0, e = c->points().size(); i < e; ++i ) { + ctx.draw_line( + o + points[i], + o + (i + 1u == e ? points[0] : points[i + 1u]), + ctx.selected() ? color32::cyan() : color32::green()); + } + } } diff --git a/untests/bin/library/prefab.json b/untests/bin/library/prefab.json index cb3920b5..06d206ae 100644 --- a/untests/bin/library/prefab.json +++ b/untests/bin/library/prefab.json @@ -5,17 +5,17 @@ "rect_collider" : { "size" : [1,2], - "pivot" : [2,4] + "offset" : [2,4] }, "circle_collider" : { "radius" : 5, - "pivot" : [4,2] + "offset" : [4,2] }, "polygon_collider" : { "points" : [[1,2],[2,3],[3,4]], - "pivot" : [8,4] + "offset" : [8,4] } } } diff --git a/untests/sources/untests_high/library.cpp b/untests/sources/untests_high/library.cpp index 35b18ee6..674ec248 100644 --- a/untests/sources/untests_high/library.cpp +++ b/untests/sources/untests_high/library.cpp @@ -255,15 +255,15 @@ TEST_CASE("library"){ REQUIRE(e.exists_component()); REQUIRE(e.get_component().size() == v2f(1.f,2.f)); - REQUIRE(e.get_component().pivot() == v2f(2.f,4.f)); + REQUIRE(e.get_component().offset() == v2f(2.f,4.f)); REQUIRE(e.exists_component()); REQUIRE(math::approximately(e.get_component().radius(), 5.f)); - REQUIRE(e.get_component().pivot() == v2f(4.f,2.f)); + REQUIRE(e.get_component().offset() == v2f(4.f,2.f)); REQUIRE(e.exists_component()); REQUIRE(e.get_component().points() == vector{{1,2},{2,3},{3,4}}); - REQUIRE(e.get_component().pivot() == v2f(8.f,4.f)); + REQUIRE(e.get_component().offset() == v2f(8.f,4.f)); } } }