Add basic sine animation component + system for it
This commit is contained in:
parent
59e3132d6e
commit
30b36bd9f8
@ -7,7 +7,7 @@ find_package(OpenGL REQUIRED)
|
||||
find_package(glfw3 REQUIRED)
|
||||
find_package(glm REQUIRED)
|
||||
|
||||
add_executable(ecsgame Util/glad.c Util/OBJ_Loader.h Rendering/Shader.cpp Rendering/Shader.h main.cpp ECS/Components/Transform.h ECS/Components/Movement.h ECS/Events/InputEvent.h ECS/Events/MouseMoveEvent.h ECS/Systems/GravitySystem.h ECS/Systems/PositionDebugSystem.h ECS/Systems/KeyboardMovementSystem.h ECS/Components/Camera.h ECS/Systems/RenderSystem.h ECS/Components/Mesh.h ECS/Systems/MouseLookSystem.h ECS/Components/MouseLook.h ECS/Components/ObjMesh.h Util/stb_setup.cpp ECS/Components/Texture.h ECS/Components/LODObjMesh.h ECS/Components/SineAnimation.h ECS/Systems/SineAnimationSystem.h)
|
||||
add_executable(ecsgame Util/glad.c Util/OBJ_Loader.h Rendering/Shader.cpp Rendering/Shader.h main.cpp ECS/Components/Transform.h ECS/Components/Movement.h ECS/Events/InputEvent.h ECS/Events/MouseMoveEvent.h ECS/Systems/GravitySystem.h ECS/Systems/PositionDebugSystem.h ECS/Systems/KeyboardMovementSystem.h ECS/Components/Camera.h ECS/Systems/RenderSystem.h ECS/Components/Mesh.h ECS/Systems/MouseLookSystem.h ECS/Components/MouseLook.h ECS/Components/ObjMesh.h Util/stb_setup.cpp ECS/Components/Texture.h ECS/Components/LODObjMesh.h ECS/Components/SineAnimation.h ECS/Systems/SineAnimationSystem.h ECS/Components/DirectionalLight.h)
|
||||
|
||||
include_directories(${OPENGL_INCLUDE_DIRS})
|
||||
|
||||
|
15
ECS/Components/SineAnimation.h
Normal file
15
ECS/Components/SineAnimation.h
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by karl on 15.01.20.
|
||||
//
|
||||
|
||||
#ifndef ECSGAME_SINEANIMATION_H
|
||||
#define ECSGAME_SINEANIMATION_H
|
||||
|
||||
struct SineAnimation {
|
||||
SineAnimation(const glm::vec3 &maxDistance, float speedScale) : maxDistance(maxDistance), speedScale(speedScale) {}
|
||||
|
||||
glm::vec3 maxDistance;
|
||||
float speedScale;
|
||||
};
|
||||
|
||||
#endif //ECSGAME_SINEANIMATION_H
|
@ -41,10 +41,10 @@ public:
|
||||
|
||||
void tick(World *pWorld, float deltaTime) override {
|
||||
pWorld->each<Transform, MouseLook, Camera>([&](Entity *ent, ComponentHandle<Transform> transform, ComponentHandle<MouseLook> mouse, ComponentHandle<Camera> camera) {
|
||||
if(mouse->pitch > 89.0f)
|
||||
mouse->pitch = 89.0f;
|
||||
if(mouse->pitch < -89.0f)
|
||||
mouse->pitch = -89.0f;
|
||||
if(mouse->pitch > 50.0f)
|
||||
mouse->pitch = 50.0f;
|
||||
if(mouse->pitch < -50.0f)
|
||||
mouse->pitch = -50.0f;
|
||||
|
||||
glm::mat4x4 newTransform = glm::mat4x4(1.0);
|
||||
|
||||
|
28
ECS/Systems/SineAnimationSystem.h
Normal file
28
ECS/Systems/SineAnimationSystem.h
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by karl on 15.01.20.
|
||||
//
|
||||
|
||||
#ifndef ECSGAME_SINEANIMATIONSYSTEM_H
|
||||
#define ECSGAME_SINEANIMATIONSYSTEM_H
|
||||
|
||||
#include "../ECS.h"
|
||||
#include "../Components/Transform.h"
|
||||
#include "../Components/SineAnimation.h"
|
||||
|
||||
using namespace ECS;
|
||||
|
||||
class SineAnimationSystem : public EntitySystem {
|
||||
public:
|
||||
void tick(World *pWorld, float deltaTime) override {
|
||||
passedTime += deltaTime;
|
||||
|
||||
pWorld->each<Transform, SineAnimation>([&](Entity *ent, ComponentHandle<Transform> transform, ComponentHandle<SineAnimation> anim) {
|
||||
transform->translate(anim->maxDistance * glm::sin(passedTime * anim->speedScale) * deltaTime);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
float passedTime = 0.0;
|
||||
};
|
||||
|
||||
#endif //ECSGAME_SINEANIMATIONSYSTEM_H
|
18
main.cpp
18
main.cpp
@ -14,6 +14,8 @@
|
||||
#include "ECS/Systems/MouseLookSystem.h"
|
||||
#include "ECS/Components/ObjMesh.h"
|
||||
#include "ECS/Components/Texture.h"
|
||||
#include "ECS/Components/SineAnimation.h"
|
||||
#include "ECS/Systems/SineAnimationSystem.h"
|
||||
|
||||
using namespace ECS;
|
||||
|
||||
@ -75,6 +77,7 @@ int main() {
|
||||
// world->registerSystem(new PositionDebugOutputSystem());
|
||||
world->registerSystem(new KeyboardMovementSystem());
|
||||
world->registerSystem(new MouseLookSystem(640, 480));
|
||||
world->registerSystem(new SineAnimationSystem());
|
||||
|
||||
RenderSystem* renderSystem = new RenderSystem();
|
||||
world->registerSystem(renderSystem);
|
||||
@ -90,6 +93,7 @@ int main() {
|
||||
monkey->assign<Transform>();
|
||||
monkey->assign<LODObjMesh>(std::vector{ObjMesh("Resources/Monkey.obj", ObjMesh::Settings(0.0, 8.0)), ObjMesh("Resources/MonkeySimple.obj", ObjMesh::Settings(8.0, 100.0))});
|
||||
monkey->assign<Texture>("Resources/Marble.jpg", Texture::Settings(true, false));
|
||||
monkey->assign<SineAnimation>(glm::vec3(0.0, 0.3, 0.0), 0.5);
|
||||
monkey->get<Transform>()->translate(glm::vec3(0.0f, 2.0f, -6.0f));
|
||||
|
||||
Entity *wall1 = world->create();
|
||||
@ -104,6 +108,20 @@ int main() {
|
||||
wall2->assign<Texture>("Resources/Glass.png", Texture::Settings(true, true));
|
||||
wall2->get<Transform>()->translate(glm::vec3(0.0f, 0.0f, -10.0f));
|
||||
|
||||
Entity *wall3 = world->create();
|
||||
wall3->assign<Transform>();
|
||||
wall3->assign<ObjMesh>(ObjMesh("Resources/Wall.obj", ObjMesh::Settings()));
|
||||
wall3->assign<Texture>("Resources/Glass.png", Texture::Settings(true, true));
|
||||
wall3->get<Transform>()->translate(glm::vec3(4.0f, 0.0f, -6.0f));
|
||||
wall3->get<Transform>()->rotate(90.0, glm::vec3(0.0, 1.0, 0.0));
|
||||
|
||||
Entity *wall4 = world->create();
|
||||
wall4->assign<Transform>();
|
||||
wall4->assign<ObjMesh>(ObjMesh("Resources/Wall.obj", ObjMesh::Settings()));
|
||||
wall4->assign<Texture>("Resources/Glass.png", Texture::Settings(true, true));
|
||||
wall4->get<Transform>()->translate(glm::vec3(-4.0f, 0.0f, -6.0f));
|
||||
wall4->get<Transform>()->rotate(90.0, glm::vec3(0.0, 1.0, 0.0));
|
||||
|
||||
Entity *ground = world->create();
|
||||
ground->assign<Transform>();
|
||||
ground->assign<ObjMesh>(ObjMesh("Resources/Ground.obj", ObjMesh::Settings()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user