WE BE RENDERING BABY
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <destrum/FS/AssetFS.h>
|
||||
|
||||
#include "glm/gtx/transform.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
App::App(): renderer{meshCache} {
|
||||
@@ -49,6 +50,11 @@ void App::init(const AppParams& params) {
|
||||
float aspectRatio = static_cast<float>(params.renderSize.x) / static_cast<float>(params.renderSize.y);
|
||||
camera.setAspectRatio(aspectRatio);
|
||||
|
||||
//Look 90 deg to the right
|
||||
camera.SetRotation(glm::radians(glm::vec2(90.f, 0.f)));
|
||||
|
||||
inputManager.Init();
|
||||
|
||||
}
|
||||
|
||||
void App::run() {
|
||||
@@ -84,6 +90,7 @@ void App::run() {
|
||||
}
|
||||
|
||||
while (accumulator >= dt) {
|
||||
inputManager.BeginFrame();
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
@@ -99,28 +106,68 @@ void App::run() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
inputManager.ProcessEvent(event);
|
||||
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_W)) {
|
||||
camera.m_position += camera.GetForward() * dt * 5.f;
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_S)) {
|
||||
camera.m_position -= camera.GetForward() * dt * 5.f;
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_A)) {
|
||||
camera.m_position -= camera.GetRight() * dt * 5.f;
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_D)) {
|
||||
camera.m_position += camera.GetRight() * dt * 5.f;
|
||||
}
|
||||
|
||||
// rotation
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_LEFT)) {
|
||||
camera.SetRotation(camera.GetYaw() - glm::radians(90.f) * dt, camera.GetPitch());
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_RIGHT)) {
|
||||
camera.SetRotation(camera.GetYaw() + glm::radians(90.f) * dt, camera.GetPitch());
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_UP)) {
|
||||
camera.SetRotation(camera.GetYaw(), camera.GetPitch() + glm::radians(90.f) * dt);
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_DOWN)) {
|
||||
camera.SetRotation(camera.GetYaw(), camera.GetPitch() - glm::radians(90.f) * dt);
|
||||
}
|
||||
|
||||
camera.Update(dt);
|
||||
|
||||
}
|
||||
|
||||
if (gfxDevice.needsSwapchainRecreate()) {
|
||||
spdlog::info("Recreating swapchain to size: {}x{}", m_params.windowSize.x, m_params.windowSize.y);
|
||||
gfxDevice.recreateSwapchain(m_params.windowSize.x, m_params.windowSize.y);
|
||||
renderer.resize(gfxDevice, { m_params.windowSize.x, m_params.windowSize.y });
|
||||
float aspectRatio = float(m_params.windowSize.x) / float(m_params.windowSize.y);
|
||||
camera.setAspectRatio(aspectRatio);
|
||||
}
|
||||
|
||||
accumulator -= dt;
|
||||
}
|
||||
|
||||
if (!gfxDevice.needsSwapchainRecreate()) {
|
||||
glm::mat4 objMatrix = glm::mat4(1.f);
|
||||
objMatrix = glm::translate(objMatrix, glm::vec3(0.f, -3.0f, 0.f));
|
||||
renderer.beginDrawing(gfxDevice);
|
||||
renderer.drawMesh(testMeshID, glm::mat4(1.f), 0);
|
||||
renderer.drawMesh(testMeshID, objMatrix, 0);
|
||||
renderer.endDrawing();
|
||||
|
||||
|
||||
auto cmd = gfxDevice.beginFrame();
|
||||
const auto& drawImage = renderer.getDrawImage(gfxDevice);
|
||||
renderer.draw(cmd, gfxDevice, camera, GameRenderer::SceneData{
|
||||
camera, glm::vec3(0.1f), 0.5f, glm::vec3(0.5f), 0.01f
|
||||
});
|
||||
gfxDevice.endFrame(cmd, GPUImage{}, {});
|
||||
gfxDevice.endFrame(cmd, drawImage, {
|
||||
.clearColor = {{0.f, 0.f, 0.5f, 1.f}},
|
||||
.drawImageBlitRect = glm::ivec4{}}
|
||||
);
|
||||
}
|
||||
if (frameLimit) {
|
||||
// Delay to not overload the CPU
|
||||
|
||||
Reference in New Issue
Block a user