minecraftvulkan/src/first_app.cpp

68 lines
1.8 KiB
C++
Raw Normal View History

2022-09-19 01:20:51 +00:00
#include "first_app.hpp"
#include "xe_camera.hpp"
2022-09-20 01:28:41 +00:00
#include "xe_engine.hpp"
2022-09-19 01:20:51 +00:00
#include "xe_game_object.hpp"
#include "xe_model.hpp"
2022-09-20 01:28:41 +00:00
#include "xe_render_system.hpp"
2022-09-19 01:20:51 +00:00
#include "keyboard_movement_controller.hpp"
2022-09-20 01:28:41 +00:00
#include "simple_renderer.hpp"
2022-09-19 01:20:51 +00:00
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include <array>
2022-09-20 01:28:41 +00:00
namespace app {
2022-09-19 01:20:51 +00:00
2022-09-19 11:08:42 +00:00
FirstApp::FirstApp() : xeEngine{WIDTH, HEIGHT, "Hello, Vulkan!"} {
2022-09-19 01:20:51 +00:00
loadGameObjects();
}
FirstApp::~FirstApp() {}
void FirstApp::run() {
2022-09-20 01:28:41 +00:00
SimpleRenderer renderer{xeEngine};
xeEngine.getCamera().setViewTarget(glm::vec3(-1.f, -2.f, 20.f), glm::vec3(0.f, 0.f, 2.5f));
2022-09-19 20:35:45 +00:00
2022-09-20 01:28:41 +00:00
auto viewerObject = xe::XeGameObject::createGameObject();
2022-09-19 01:20:51 +00:00
KeyboardMovementController cameraController{};
2022-09-20 01:28:41 +00:00
while (xeEngine.poll()) {
2022-09-19 01:20:51 +00:00
2022-09-20 01:28:41 +00:00
float frameTime = xeEngine.getFrameTime();
2022-09-19 01:20:51 +00:00
2022-09-19 16:54:23 +00:00
cameraController.moveInPlaneXZ(xeEngine.getWindow().getGLFWwindow(), frameTime, viewerObject);
2022-09-20 01:28:41 +00:00
xeEngine.getCamera().setViewYXZ(viewerObject.transform.translation, viewerObject.transform.rotation);
2022-09-19 01:20:51 +00:00
2022-09-19 20:35:45 +00:00
if(xeEngine.beginFrame()) {
2022-09-20 01:28:41 +00:00
renderer.render(gameObjects, xeEngine.getCamera());
2022-09-19 20:35:45 +00:00
xeEngine.endFrame();
}
2022-09-19 01:20:51 +00:00
}
2022-09-19 20:35:45 +00:00
xeEngine.close();
2022-09-19 01:20:51 +00:00
}
void FirstApp::loadGameObjects() {
2022-09-20 01:28:41 +00:00
std::shared_ptr<xe::XeModel> xeModel = xeEngine.loadModelFromFile("res/models/stanford-dragon.obj");
auto dragon = xe::XeGameObject::createGameObject();
dragon.model = xeModel;
dragon.transform.translation = {.0f, .0f, 2.5f};
dragon.transform.scale = {.5f, .5f, .5f};
gameObjects.push_back(std::move(dragon));
auto dragon2 = xe::XeGameObject::createGameObject();
dragon2.model = xeModel;
dragon2.transform.translation = {5.0f, .0f, -1.5f};
dragon2.transform.rotation.y = glm::radians(90.f);
dragon2.transform.scale = {.35f, .35f, .35f};
gameObjects.push_back(std::move(dragon2));
2022-09-19 01:20:51 +00:00
}
}