Skip to content

Commit

Permalink
feat(engine): add LocalToWorld automagically
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Jun 18, 2023
1 parent 2631d4e commit 0d09018
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions engine/samples/renderer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void setupScene(Commands commands, Write<Assets> assets, Write<ActiveCame

// Create a simple palette with 3 materials (red, green and blue).
(*renderer)->setPalette(Palette{{
{{1, 0, 0, 1}},
{{100, 0, 0, 1}},
{{0, 1, 0, 1}},
{{0, 0, 1, 1}},
}});
Expand All @@ -49,8 +49,8 @@ static void setupScene(Commands commands, Write<Assets> assets, Write<ActiveCame
.entity();

// Split the screen but use the same camera.
camera->entities[1] = camera->entities[0];
camera->entities[2] = camera->entities[0];
//camera->entities[1] = camera->entities[0];
//camera->entities[2] = camera->entities[0];

// Spawn a point light.
commands.create()
Expand Down
14 changes: 14 additions & 0 deletions engine/src/cubos/engine/transform/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

#include <cubos/engine/transform/plugin.hpp>

using cubos::core::ecs::Commands;
using cubos::core::ecs::OptRead;
using cubos::core::ecs::Query;
using cubos::core::ecs::Write;
using namespace cubos::engine;

static void autoLocalToWorld(Commands cmds,
Query<OptRead<LocalToWorld>, OptRead<Position>, OptRead<Rotation>, OptRead<Scale>> query)
{
for (auto [entity, localToWorld, position, rotation, scale] : query)
{
if (!localToWorld && (position || rotation || scale))
{
cmds.add(entity, LocalToWorld{});
}
}
}

static void applyTransform(Query<Write<LocalToWorld>, OptRead<Position>, OptRead<Rotation>, OptRead<Scale>> query)
{
for (auto [entity, localToWorld, position, rotation, scale] : query)
Expand Down Expand Up @@ -36,5 +49,6 @@ void cubos::engine::transformPlugin(Cubos& cubos)
cubos.addComponent<Scale>();
cubos.addComponent<LocalToWorld>();

cubos.system(autoLocalToWorld).tagged("cubos.transform.update");
cubos.system(applyTransform).tagged("cubos.transform.update");
}

0 comments on commit 0d09018

Please sign in to comment.