diff --git a/examples/dev_testing/src/main.cpp b/examples/dev_testing/src/main.cpp index 5ff3a3d..d58be80 100644 --- a/examples/dev_testing/src/main.cpp +++ b/examples/dev_testing/src/main.cpp @@ -3,6 +3,7 @@ #include "simpleengine/ecs/component/mesh_component.h" #include #include "simpleengine/ecs/component/transform_component.h" +#include #include "simpleengine/ecs/entity.h" #include "simpleengine/gfx/light.h" #include "simpleengine/gfx/material.h" @@ -184,6 +185,7 @@ int main(int argc, char *argv[]) { // Create an Entity in the Scene and add components to it. se::ecs::Entity entity = scene->create_entity(); entity.add_component("examples/dev_testing/resources/dragon.obj"); + entity.add_component(); auto& transform_comp = entity.add_component(); transform_comp.translate(12.f, -4.f, 0.f); diff --git a/include/simpleengine/ecs/component/rotating_component.h b/include/simpleengine/ecs/component/rotating_component.h new file mode 100644 index 0000000..ab33827 --- /dev/null +++ b/include/simpleengine/ecs/component/rotating_component.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace simpleengine { + /** + * @brief A component that will rotate the transform every frame. + * + */ + class RotatingComponent { + public: + float rate; + glm::vec3 rotation_axis; + + RotatingComponent() : rate(10.f), rotation_axis(glm::vec3(0, 1, 0)) { + + } + + RotatingComponent(float rate) : rate(rate), rotation_axis(glm::vec3(0, 1, 0)) { + + } + + RotatingComponent(glm::vec3 rotation_axis) : rotation_axis(rotation_axis) { + + } + + RotatingComponent(float rate, glm::vec3 rotation_axis) : rate(rate), rotation_axis(rotation_axis) { + + } + }; +} \ No newline at end of file diff --git a/src/scene.cpp b/src/scene.cpp index 00bdb9e..c2caeff 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -2,6 +2,7 @@ #include "ecs/component/mesh_component.h" #include "ecs/component/model_component.h" #include "ecs/component/transform_component.h" +#include "ecs/component/rotating_component.h" #include "ecs/entity.h" #include "gfx/renderer.h" @@ -25,5 +26,9 @@ namespace simpleengine { registry.view().each([this](const TransformComponent& transform, MeshComponent& mesh_component) { renderer->queue_job(gfx::RenderingJob(mesh_component.mesh, transform.transform_matrix)); }); + + registry.view().each([this, &delta_time](TransformComponent& transform, RotatingComponent& rotating) { + transform.rotate(rotating.rate * delta_time, rotating.rotation_axis); + }); } } \ No newline at end of file