fix tests and samples

This commit is contained in:
2019-11-30 10:03:54 +07:00
parent 4b266de434
commit a131739b25
6 changed files with 69 additions and 59 deletions

View File

@@ -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" : {

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
-- -----------------------------------------------------------------------------

View File

@@ -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<rotator, actor>(
[&event](const ecs::const_entity&, const rotator& rot, actor& act){
owner.for_joined_components<node_rotator, actor>(
[&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<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.prototype()
.component<rotator>(rotator{v3f::unit_y()})
.component<renderer_rotator>(v3f::unit_y())
.component<renderer>(renderer().materials({model_mat}))
.component<model_renderer>(model_res);
the<world>().instantiate(
prefab,
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.prototype()
.component<rotator>(rotator{v3f::unit_z()})
.component<node_rotator>()
.component<renderer>()
.component<sprite_renderer>(sprite_renderer(sprite_res)
.materials({{"normal", sprite_mat}}));
@@ -118,13 +128,13 @@ namespace
the<world>().instantiate(
prefab,
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_a.prototype()
.component<rotator>(rotator{v3f::unit_z()})
.component<node_rotator>()
.component<renderer>()
.component<sprite_renderer>(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<world>().instantiate(
prefab_a,
scene_i.component<actor>()->node(),
@@ -146,11 +156,11 @@ namespace
prefab prefab_b = prefab_a;
prefab_b.prototype()
.component<rotator>(rotator{v3f::unit_z()})
.component<actor>(node::create(make_trs3(
v3f{20.f,0.f,0.f},
q4f::identity(),
v3f{0.3f,0.3f,3.f})));
.component<node_rotator>()
.component<actor>(node::create(make_trs2(
v2f{20.f,0.f},
radf::zero(),
v2f{0.3f,0.3f})));
the<world>().instantiate(
prefab_b,

View File

@@ -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") {