mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
fix tests and samples
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
"prototype" : "../prefabs/gnome_prefab.json",
|
"prototype" : "../prefabs/gnome_prefab.json",
|
||||||
"components" : {
|
"components" : {
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [0,0,0],
|
"translation" : [0,0],
|
||||||
"scale" : 20
|
"scale" : 20
|
||||||
},
|
},
|
||||||
"behaviour" : {
|
"behaviour" : {
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
"outline_color" : [0,0,0,255]
|
"outline_color" : [0,0,0,255]
|
||||||
},
|
},
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [-315,-235,0],
|
"translation" : [-315,-235],
|
||||||
"scale" : 1
|
"scale" : 1
|
||||||
},
|
},
|
||||||
"behaviour" : {
|
"behaviour" : {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"prototype" : "../prefabs/gnome_prefab.json",
|
"prototype" : "../prefabs/gnome_prefab.json",
|
||||||
"components" : {
|
"components" : {
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [0,0,0],
|
"translation" : [0,0],
|
||||||
"scale" : 20
|
"scale" : 20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"blending" : "additive"
|
"blending" : "additive"
|
||||||
},
|
},
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [-50,-50,0]
|
"translation" : [-50,-50]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
"tint" : [255,0,0,255]
|
"tint" : [255,0,0,255]
|
||||||
},
|
},
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [50,-50,0]
|
"translation" : [50,-50]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
"outline_color" : [0,0,0,255]
|
"outline_color" : [0,0,0,255]
|
||||||
},
|
},
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [0,180,0],
|
"translation" : [0,180],
|
||||||
"scale" : 3
|
"scale" : 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"outline_color" : [0,0,0,255]
|
"outline_color" : [0,0,0,255]
|
||||||
},
|
},
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [0.5,-180.5,0],
|
"translation" : [0.5,-180.5],
|
||||||
"scale" : 3
|
"scale" : 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"prototype" : "../prefabs/coin_prefab.json",
|
"prototype" : "../prefabs/coin_prefab.json",
|
||||||
"components" : {
|
"components" : {
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [350,250,0],
|
"translation" : [350,250],
|
||||||
"scale" : 0.25
|
"scale" : 0.25
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
"prototype" : "../prefabs/raptor_prefab.json",
|
"prototype" : "../prefabs/raptor_prefab.json",
|
||||||
"components" : {
|
"components" : {
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [300,-350,0],
|
"translation" : [300,-350],
|
||||||
"scale" : 0.25
|
"scale" : 0.25
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"prototype" : "../prefabs/dragon_prefab.json",
|
"prototype" : "../prefabs/dragon_prefab.json",
|
||||||
"components" : {
|
"components" : {
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [-100,0,0],
|
"translation" : [-100,0],
|
||||||
"scale" : 0.9
|
"scale" : 0.9
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ end
|
|||||||
---@param go gobject
|
---@param go gobject
|
||||||
local function update_gnome_rotation(meta, go)
|
local function update_gnome_rotation(meta, go)
|
||||||
local time = the_engine.time
|
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
|
end
|
||||||
|
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ using namespace e2d;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct rotator {
|
struct node_rotator {
|
||||||
|
};
|
||||||
|
|
||||||
|
struct renderer_rotator {
|
||||||
v3f axis;
|
v3f axis;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,14 +64,21 @@ namespace
|
|||||||
ecs::registry& owner,
|
ecs::registry& owner,
|
||||||
const systems::update_event& event) override
|
const systems::update_event& event) override
|
||||||
{
|
{
|
||||||
owner.for_joined_components<rotator, actor>(
|
owner.for_joined_components<node_rotator, actor>(
|
||||||
[&event](const ecs::const_entity&, const rotator& rot, actor& act){
|
[&event](const ecs::const_entity&, const node_rotator&, actor& act){
|
||||||
const node_iptr node = act.node();
|
const node_iptr node = act.node();
|
||||||
if ( node ) {
|
if ( node ) {
|
||||||
const q4f q = math::make_quat_from_axis_angle(make_rad(event.time), rot.axis);
|
node->rotation(make_rad(event.time));
|
||||||
node->rotation(q);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
owner.for_joined_components<renderer_rotator, renderer>(
|
||||||
|
[&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 prefab;
|
||||||
prefab.prototype()
|
prefab.prototype()
|
||||||
.component<rotator>(rotator{v3f::unit_y()})
|
.component<renderer_rotator>(v3f::unit_y())
|
||||||
.component<renderer>(renderer().materials({model_mat}))
|
.component<renderer>(renderer().materials({model_mat}))
|
||||||
.component<model_renderer>(model_res);
|
.component<model_renderer>(model_res);
|
||||||
|
|
||||||
the<world>().instantiate(
|
the<world>().instantiate(
|
||||||
prefab,
|
prefab,
|
||||||
scene_i.component<actor>()->node(),
|
scene_i.component<actor>()->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 prefab;
|
||||||
prefab.prototype()
|
prefab.prototype()
|
||||||
.component<rotator>(rotator{v3f::unit_z()})
|
.component<node_rotator>()
|
||||||
.component<renderer>()
|
.component<renderer>()
|
||||||
.component<sprite_renderer>(sprite_renderer(sprite_res)
|
.component<sprite_renderer>(sprite_renderer(sprite_res)
|
||||||
.materials({{"normal", sprite_mat}}));
|
.materials({{"normal", sprite_mat}}));
|
||||||
@@ -118,13 +128,13 @@ namespace
|
|||||||
the<world>().instantiate(
|
the<world>().instantiate(
|
||||||
prefab,
|
prefab,
|
||||||
scene_i.component<actor>()->node(),
|
scene_i.component<actor>()->node(),
|
||||||
math::make_translation_trs3(v3f{0,-50.f,0}));
|
math::make_translation_trs2(v2f{0,-50.f}));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
prefab prefab_a;
|
prefab prefab_a;
|
||||||
prefab_a.prototype()
|
prefab_a.prototype()
|
||||||
.component<rotator>(rotator{v3f::unit_z()})
|
.component<node_rotator>()
|
||||||
.component<renderer>()
|
.component<renderer>()
|
||||||
.component<sprite_renderer>(sprite_renderer()
|
.component<sprite_renderer>(sprite_renderer()
|
||||||
.filtering(false)
|
.filtering(false)
|
||||||
@@ -135,10 +145,10 @@ namespace
|
|||||||
|
|
||||||
for ( std::size_t i = 0; i < 2; ++i )
|
for ( std::size_t i = 0; i < 2; ++i )
|
||||||
for ( std::size_t j = 0; j < 5; ++j ) {
|
for ( std::size_t j = 0; j < 5; ++j ) {
|
||||||
t3f trans{
|
t2f trans{
|
||||||
{-80.f + j * 40.f, -200.f + i * 40.f, 0},
|
{-80.f + j * 40.f, -200.f + i * 40.f},
|
||||||
q4f::identity(),
|
radf::zero(),
|
||||||
{2.f,2.f,1.f}};
|
{2.f,2.f}};
|
||||||
gobject inst = the<world>().instantiate(
|
gobject inst = the<world>().instantiate(
|
||||||
prefab_a,
|
prefab_a,
|
||||||
scene_i.component<actor>()->node(),
|
scene_i.component<actor>()->node(),
|
||||||
@@ -146,11 +156,11 @@ namespace
|
|||||||
|
|
||||||
prefab prefab_b = prefab_a;
|
prefab prefab_b = prefab_a;
|
||||||
prefab_b.prototype()
|
prefab_b.prototype()
|
||||||
.component<rotator>(rotator{v3f::unit_z()})
|
.component<node_rotator>()
|
||||||
.component<actor>(node::create(make_trs3(
|
.component<actor>(node::create(make_trs2(
|
||||||
v3f{20.f,0.f,0.f},
|
v2f{20.f,0.f},
|
||||||
q4f::identity(),
|
radf::zero(),
|
||||||
v3f{0.3f,0.3f,3.f})));
|
v2f{0.3f,0.3f})));
|
||||||
|
|
||||||
the<world>().instantiate(
|
the<world>().instantiate(
|
||||||
prefab_b,
|
prefab_b,
|
||||||
|
|||||||
@@ -655,82 +655,82 @@ TEST_CASE("node") {
|
|||||||
SECTION("transform") {
|
SECTION("transform") {
|
||||||
auto p = node::create();
|
auto p = node::create();
|
||||||
|
|
||||||
REQUIRE(p->transform() == t3f::identity());
|
REQUIRE(p->transform() == t2f::identity());
|
||||||
REQUIRE(p->translation() == v3f::zero());
|
REQUIRE(p->translation() == v2f::zero());
|
||||||
REQUIRE(p->rotation() == q4f::identity());
|
REQUIRE(p->rotation() == radf::zero());
|
||||||
REQUIRE(p->scale() == v3f::unit());
|
REQUIRE(p->scale() == v2f::unit());
|
||||||
|
|
||||||
p->translation(v3f(1,2,3));
|
p->translation(v2f(1,2));
|
||||||
REQUIRE(p->translation() == v3f(1,2,3));
|
REQUIRE(p->translation() == v2f(1,2));
|
||||||
|
|
||||||
p->rotation(q4f(1,2,3,4));
|
p->rotation(radf(1.f));
|
||||||
REQUIRE(p->rotation() == q4f(1,2,3,4));
|
REQUIRE(p->rotation() == radf(1.f));
|
||||||
|
|
||||||
p->scale(v3f(1,2,3));
|
p->scale(v2f(1,2));
|
||||||
REQUIRE(p->scale() == v3f(1,2,3));
|
REQUIRE(p->scale() == v2f(1,2));
|
||||||
}
|
}
|
||||||
SECTION("local_matrix") {
|
SECTION("local_matrix") {
|
||||||
{
|
{
|
||||||
auto p = node::create();
|
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);
|
auto n = node::create(p);
|
||||||
n->transform(math::make_translation_trs3(v3f{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,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);
|
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});
|
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)));
|
n->transform(math::make_scale_trs2(v2f(1.f,2.f)));
|
||||||
REQUIRE(n->local_matrix() == math::make_scale_matrix4(1.f,2.f,3.f));
|
REQUIRE(n->local_matrix() == math::make_scale_matrix4(1.f,2.f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SECTION("world_matrix") {
|
SECTION("world_matrix") {
|
||||||
{
|
{
|
||||||
auto p = node::create();
|
auto p = node::create();
|
||||||
p->translation({10.f,0.f,0.f});
|
p->translation({10.f,0.f});
|
||||||
|
|
||||||
auto n = node::create(p);
|
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);
|
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});
|
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() ==
|
REQUIRE(n->world_matrix() ==
|
||||||
math::make_scale_matrix4(1.f,2.f,3.f) *
|
math::make_scale_matrix4(1.f,2.f) *
|
||||||
math::make_translation_matrix4(10.f,0.f,0.f));
|
math::make_translation_matrix4(10.f,0.f));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto n = node::create();
|
auto n = node::create();
|
||||||
n->translation({20.f,0.f,0.f});
|
n->translation({20.f,0.f});
|
||||||
REQUIRE(n->world_matrix() ==
|
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();
|
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);
|
p->add_child(n);
|
||||||
REQUIRE(n->world_matrix() ==
|
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();
|
auto p1 = node::create();
|
||||||
p1->translation({10.f,0.f,0.f});
|
p1->translation({10.f,0.f});
|
||||||
|
|
||||||
auto p2 = node::create();
|
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);
|
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() ==
|
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);
|
p1->add_child(p2);
|
||||||
|
|
||||||
REQUIRE(n->world_matrix() ==
|
REQUIRE(n->world_matrix() ==
|
||||||
math::make_translation_matrix4(60.f,0.f,0.f));
|
math::make_translation_matrix4(60.f,0.f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SECTION("lifetime") {
|
SECTION("lifetime") {
|
||||||
|
|||||||
Reference in New Issue
Block a user