-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrotating-cube.cpp
58 lines (47 loc) · 1.59 KB
/
rotating-cube.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "rotating-cube.h"
#include <imgui.h>
#include "systems/render-system.h"
#include "systems/camera-system.h"
#include "components/graphics/mesh.h"
#include "components/graphics/pipeline.h"
#include "components/physics/transform.h"
#include "factories/components/mesh-primitive-factory.h"
namespace basicExample {
RotatingCube::RotatingCube(Context& context) : m_ctx(context) {
// Init
m_systems = {
std::make_shared<RenderSystem>(context),
std::make_shared<CameraSystem>(context)
};
MeshPrimitiveFactory primFactory(context);
// Pipeline
scomp::ShaderPipeline shaders = {};
shaders.vs = m_ctx.rcommand->createVertexShader("res/shaders/basics/rotating-cube/rotating-cube.vert");
shaders.fs = m_ctx.rcommand->createFragmentShader("res/shaders/basics/rotating-cube/rotating-cube.frag");
scomp::ConstantBufferIndex cbIndices[] = {
scomp::PER_MESH,
scomp::PER_FRAME
};
comp::Pipeline pipeline = m_ctx.rcommand->createPipeline(shaders, cbIndices, std::size(cbIndices));
// Mesh
comp::Mesh mesh = primFactory.createBox();
// Transform
comp::Transform transform = {};
// Assign data to entity
auto entity = m_ctx.registry.create();
m_ctx.registry.assign<comp::Mesh>(entity, mesh);
m_ctx.registry.assign<comp::Pipeline>(entity, pipeline);
m_ctx.registry.assign<comp::Transform>(entity, transform);
}
RotatingCube::~RotatingCube() {}
void RotatingCube::update() {
for (auto& system : m_systems) {
system->update();
}
}
void RotatingCube::imGuiUpdate() {
ImGui::Begin("Exemple properties");
ImGui::Text("Rotating cube");
ImGui::End();
}
}