minecraftvulkan/src/first_app.cpp

79 lines
2.2 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-22 15:14:00 +00:00
#include "xe_sound.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
2022-09-21 02:02:58 +00:00
#include <string>
2022-09-20 01:28:41 +00:00
namespace app {
2022-09-19 01:20:51 +00:00
2022-09-22 17:36:03 +00:00
FirstApp::FirstApp() : xeEngine{WIDTH, HEIGHT, "Xenon Vulkan Engine"} {
2022-09-19 01:20:51 +00:00
loadGameObjects();
}
FirstApp::~FirstApp() {}
void FirstApp::run() {
2022-09-21 02:02:58 +00:00
std::shared_ptr<xe::XeImage> image = xeEngine.loadImage("res/image/texture.png");
std::shared_ptr<xe::XeImage> image2 = xeEngine.loadImage("res/image/scaly.png");
SimpleRenderer renderer{xeEngine, image.get()};
2022-09-22 15:14:00 +00:00
xe::XeSound sound{"res/sound/when_the_world_ends.wav"};
2022-09-22 17:36:03 +00:00
sound.setLooping(true);
2022-09-22 15:14:00 +00:00
sound.play();
2022-09-20 01:28:41 +00:00
auto viewerObject = xe::XeGameObject::createGameObject();
2022-09-20 03:17:15 +00:00
viewerObject.transform.translation = {-7.f, 3.f, -7.f};
viewerObject.transform.rotation.y = glm::radians(45.f);
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-21 02:02:58 +00:00
renderer.render(gameObjects, xeEngine.getCamera(), image2.get());
2022-09-19 20:35:45 +00:00
xeEngine.endFrame();
}
2022-09-22 17:36:03 +00:00
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
}
}