diff --git a/samples/bin/library/scenes/sample_07.json b/samples/bin/library/scenes/sample_07.json index 7d8a9360..bfc3d104 100644 --- a/samples/bin/library/scenes/sample_07.json +++ b/samples/bin/library/scenes/sample_07.json @@ -11,7 +11,7 @@ "prototype" : "../prefabs/gnome_prefab.json", "components" : { "actor" : { - "translation" : [0,0,0], + "translation" : [0,0], "scale" : 20 }, "behaviour" : { @@ -28,7 +28,7 @@ "outline_color" : [0,0,0,255] }, "actor" : { - "translation" : [-315,-235,0], + "translation" : [-315,-235], "scale" : 1 }, "behaviour" : { diff --git a/samples/bin/library/scenes/scene_prefab.json b/samples/bin/library/scenes/scene_prefab.json index f1d07b21..6a0c19ed 100644 --- a/samples/bin/library/scenes/scene_prefab.json +++ b/samples/bin/library/scenes/scene_prefab.json @@ -8,7 +8,7 @@ "prototype" : "../prefabs/gnome_prefab.json", "components" : { "actor" : { - "translation" : [0,0,0], + "translation" : [0,0], "scale" : 20 } } @@ -19,7 +19,7 @@ "blending" : "additive" }, "actor" : { - "translation" : [-50,-50,0] + "translation" : [-50,-50] } } }, { @@ -29,7 +29,7 @@ "tint" : [255,0,0,255] }, "actor" : { - "translation" : [50,-50,0] + "translation" : [50,-50] } } }, { @@ -42,7 +42,7 @@ "outline_color" : [0,0,0,255] }, "actor" : { - "translation" : [0,180,0], + "translation" : [0,180], "scale" : 3 } } @@ -56,7 +56,7 @@ "outline_color" : [0,0,0,255] }, "actor" : { - "translation" : [0.5,-180.5,0], + "translation" : [0.5,-180.5], "scale" : 3 } } diff --git a/samples/bin/library/scenes/spine_scene_prefab.json b/samples/bin/library/scenes/spine_scene_prefab.json index 8eebb6fa..5254139b 100644 --- a/samples/bin/library/scenes/spine_scene_prefab.json +++ b/samples/bin/library/scenes/spine_scene_prefab.json @@ -8,7 +8,7 @@ "prototype" : "../prefabs/coin_prefab.json", "components" : { "actor" : { - "translation" : [350,250,0], + "translation" : [350,250], "scale" : 0.25 } } @@ -16,7 +16,7 @@ "prototype" : "../prefabs/raptor_prefab.json", "components" : { "actor" : { - "translation" : [300,-350,0], + "translation" : [300,-350], "scale" : 0.25 } } @@ -24,7 +24,7 @@ "prototype" : "../prefabs/dragon_prefab.json", "components" : { "actor" : { - "translation" : [-100,0,0], + "translation" : [-100,0], "scale" : 0.9 } } diff --git a/samples/bin/library/scripts/sample_07/gnome.lua b/samples/bin/library/scripts/sample_07/gnome.lua index 2882c7aa..fd5af887 100644 --- a/samples/bin/library/scripts/sample_07/gnome.lua +++ b/samples/bin/library/scripts/sample_07/gnome.lua @@ -21,7 +21,7 @@ end ---@param go gobject local function update_gnome_rotation(meta, go) local time = the_engine.time - go.actor.node.rotation = q4f.make_from_euler_angles(0, time, 0) + go.renderer.rotation = q4f.make_from_euler_angles(0, time, 0) end -- ----------------------------------------------------------------------------- diff --git a/samples/sources/sample_03/sample_03.cpp b/samples/sources/sample_03/sample_03.cpp index daefe26b..723995f4 100644 --- a/samples/sources/sample_03/sample_03.cpp +++ b/samples/sources/sample_03/sample_03.cpp @@ -9,7 +9,10 @@ using namespace e2d; namespace { - struct rotator { + struct node_rotator { + }; + + struct renderer_rotator { v3f axis; }; @@ -61,14 +64,21 @@ namespace ecs::registry& owner, const systems::update_event& event) override { - owner.for_joined_components( - [&event](const ecs::const_entity&, const rotator& rot, actor& act){ + owner.for_joined_components( + [&event](const ecs::const_entity&, const node_rotator&, actor& act){ const node_iptr node = act.node(); if ( node ) { - const q4f q = math::make_quat_from_axis_angle(make_rad(event.time), rot.axis); - node->rotation(q); + node->rotation(make_rad(event.time)); } }); + + owner.for_joined_components( + [&event](const ecs::const_entity&, const renderer_rotator& rot, renderer& r){ + const q4f q = math::make_quat_from_axis_angle( + make_rad(event.time), + rot.axis); + r.rotation(q); + }); } }; @@ -97,20 +107,20 @@ namespace { prefab prefab; prefab.prototype() - .component(rotator{v3f::unit_y()}) + .component(v3f::unit_y()) .component(renderer().materials({model_mat})) .component(model_res); the().instantiate( prefab, scene_i.component()->node(), - make_trs3(v3f{0,50.f,0}, q4f::identity(), v3f{20.f})); + make_trs2(v2f{0,50.f}, radf::zero(), v2f{20.f})); } { prefab prefab; prefab.prototype() - .component(rotator{v3f::unit_z()}) + .component() .component() .component(sprite_renderer(sprite_res) .materials({{"normal", sprite_mat}})); @@ -118,13 +128,13 @@ namespace the().instantiate( prefab, scene_i.component()->node(), - math::make_translation_trs3(v3f{0,-50.f,0})); + math::make_translation_trs2(v2f{0,-50.f})); } { prefab prefab_a; prefab_a.prototype() - .component(rotator{v3f::unit_z()}) + .component() .component() .component(sprite_renderer() .filtering(false) @@ -135,10 +145,10 @@ namespace for ( std::size_t i = 0; i < 2; ++i ) for ( std::size_t j = 0; j < 5; ++j ) { - t3f trans{ - {-80.f + j * 40.f, -200.f + i * 40.f, 0}, - q4f::identity(), - {2.f,2.f,1.f}}; + t2f trans{ + {-80.f + j * 40.f, -200.f + i * 40.f}, + radf::zero(), + {2.f,2.f}}; gobject inst = the().instantiate( prefab_a, scene_i.component()->node(), @@ -146,11 +156,11 @@ namespace prefab prefab_b = prefab_a; prefab_b.prototype() - .component(rotator{v3f::unit_z()}) - .component(node::create(make_trs3( - v3f{20.f,0.f,0.f}, - q4f::identity(), - v3f{0.3f,0.3f,3.f}))); + .component() + .component(node::create(make_trs2( + v2f{20.f,0.f}, + radf::zero(), + v2f{0.3f,0.3f}))); the().instantiate( prefab_b, diff --git a/untests/sources/untests_high/node.cpp b/untests/sources/untests_high/node.cpp index 5c78f4ca..73ee891d 100644 --- a/untests/sources/untests_high/node.cpp +++ b/untests/sources/untests_high/node.cpp @@ -655,82 +655,82 @@ TEST_CASE("node") { SECTION("transform") { auto p = node::create(); - REQUIRE(p->transform() == t3f::identity()); - REQUIRE(p->translation() == v3f::zero()); - REQUIRE(p->rotation() == q4f::identity()); - REQUIRE(p->scale() == v3f::unit()); + REQUIRE(p->transform() == t2f::identity()); + REQUIRE(p->translation() == v2f::zero()); + REQUIRE(p->rotation() == radf::zero()); + REQUIRE(p->scale() == v2f::unit()); - p->translation(v3f(1,2,3)); - REQUIRE(p->translation() == v3f(1,2,3)); + p->translation(v2f(1,2)); + REQUIRE(p->translation() == v2f(1,2)); - p->rotation(q4f(1,2,3,4)); - REQUIRE(p->rotation() == q4f(1,2,3,4)); + p->rotation(radf(1.f)); + REQUIRE(p->rotation() == radf(1.f)); - p->scale(v3f(1,2,3)); - REQUIRE(p->scale() == v3f(1,2,3)); + p->scale(v2f(1,2)); + REQUIRE(p->scale() == v2f(1,2)); } SECTION("local_matrix") { { auto p = node::create(); - p->transform(math::make_translation_trs3(v3f{10.f,0.f,0.f})); + p->transform(math::make_translation_trs2(v2f{10.f,0.f})); auto n = node::create(p); - n->transform(math::make_translation_trs3(v3f{20.f,0.f,0.f})); - REQUIRE(n->local_matrix() == math::make_translation_matrix4(20.f,0.f,0.f)); + n->transform(math::make_translation_trs2(v2f{20.f,0.f})); + REQUIRE(n->local_matrix() == math::make_translation_matrix4(20.f,0.f)); auto v = v4f(5.f,0.f,0.f,1.f); REQUIRE(v * n->local_matrix() == v4f{25.f,0.f,0.f,1.f}); - n->transform(math::make_scale_trs3(v3f(1.f,2.f,3.f))); - REQUIRE(n->local_matrix() == math::make_scale_matrix4(1.f,2.f,3.f)); + n->transform(math::make_scale_trs2(v2f(1.f,2.f))); + REQUIRE(n->local_matrix() == math::make_scale_matrix4(1.f,2.f)); } } SECTION("world_matrix") { { auto p = node::create(); - p->translation({10.f,0.f,0.f}); + p->translation({10.f,0.f}); auto n = node::create(p); - n->translation({20.f,0.f,0.f}); + n->translation({20.f,0.f}); auto v = v4f(5.f,0.f,0.f,1.f); REQUIRE(v * n->world_matrix() == v4f{35.f,0.f,0.f,1.f}); - n->transform(math::make_scale_trs3(v3f(1.f,2.f,3.f))); + n->transform(math::make_scale_trs2(v2f(1.f,2.f))); REQUIRE(n->world_matrix() == - math::make_scale_matrix4(1.f,2.f,3.f) * - math::make_translation_matrix4(10.f,0.f,0.f)); + math::make_scale_matrix4(1.f,2.f) * + math::make_translation_matrix4(10.f,0.f)); } { auto n = node::create(); - n->translation({20.f,0.f,0.f}); + n->translation({20.f,0.f}); REQUIRE(n->world_matrix() == - math::make_translation_matrix4(20.f,0.f,0.f)); + math::make_translation_matrix4(20.f,0.f)); auto p = node::create(); - p->transform(math::make_translation_trs3(v3f{10.f,0.f,0.f})); + p->transform(math::make_translation_trs2(v2f{10.f,0.f})); p->add_child(n); REQUIRE(n->world_matrix() == - math::make_translation_matrix4(30.f,0.f,0.f)); + math::make_translation_matrix4(30.f,0.f)); } { auto p1 = node::create(); - p1->translation({10.f,0.f,0.f}); + p1->translation({10.f,0.f}); auto p2 = node::create(); - p2->transform(math::make_translation_trs3(v3f{20.f,0.f,0.f})); + p2->transform(math::make_translation_trs2(v2f{20.f,0.f})); auto n = node::create(p2); - n->transform(math::make_translation_trs3(v3f{30.f,0.f,0.f})); + n->transform(math::make_translation_trs2(v2f{30.f,0.f})); REQUIRE(n->world_matrix() == - math::make_translation_matrix4(50.f,0.f,0.f)); + math::make_translation_matrix4(50.f,0.f)); p1->add_child(p2); REQUIRE(n->world_matrix() == - math::make_translation_matrix4(60.f,0.f,0.f)); + math::make_translation_matrix4(60.f,0.f)); } } SECTION("lifetime") {