Create a simple RotatingComponent
This commit is contained in:
parent
3b51dce796
commit
ab3f6c98ff
|
@ -3,6 +3,7 @@
|
|||
#include "simpleengine/ecs/component/mesh_component.h"
|
||||
#include <simpleengine/ecs/component/model_component.h>
|
||||
#include "simpleengine/ecs/component/transform_component.h"
|
||||
#include <simpleengine/ecs/component/rotating_component.h>
|
||||
#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<se::ModelComponent>("examples/dev_testing/resources/dragon.obj");
|
||||
entity.add_component<se::RotatingComponent>();
|
||||
auto& transform_comp = entity.add_component<se::TransformComponent>();
|
||||
transform_comp.translate(12.f, -4.f, 0.f);
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
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) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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<const TransformComponent, MeshComponent>().each([this](const TransformComponent& transform, MeshComponent& mesh_component) {
|
||||
renderer->queue_job(gfx::RenderingJob(mesh_component.mesh, transform.transform_matrix));
|
||||
});
|
||||
|
||||
registry.view<TransformComponent, RotatingComponent>().each([this, &delta_time](TransformComponent& transform, RotatingComponent& rotating) {
|
||||
transform.rotate(rotating.rate * delta_time, rotating.rotation_axis);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue