2022-09-19 01:20:51 +00:00
|
|
|
#include "first_app.hpp"
|
2022-09-25 23:05:56 +00:00
|
|
|
#include "chunk.hpp"
|
2022-09-19 01:20:51 +00:00
|
|
|
|
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-26 03:08:03 +00:00
|
|
|
std::shared_ptr<xe::Image> image = xeEngine.loadImageFromFile("res/image/dirt.jpg");
|
2022-09-21 02:02:58 +00:00
|
|
|
|
|
|
|
SimpleRenderer renderer{xeEngine, image.get()};
|
2022-09-22 15:14:00 +00:00
|
|
|
|
2022-09-25 01:16:13 +00:00
|
|
|
xe::Sound 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
|
|
|
|
2022-09-25 01:16:13 +00:00
|
|
|
auto viewerObject = xe::GameObject::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-25 23:05:56 +00:00
|
|
|
KeyboardMovementController cameraController{xeEngine.getInput(), viewerObject};
|
2022-09-19 01:20:51 +00:00
|
|
|
|
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-25 23:05:56 +00:00
|
|
|
cameraController.update(frameTime);
|
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-26 03:08:03 +00:00
|
|
|
renderer.render(gameObjects, xeEngine.getCamera(), image.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-25 23:05:56 +00:00
|
|
|
Chunk::reset();
|
|
|
|
|
2022-09-19 20:35:45 +00:00
|
|
|
xeEngine.close();
|
2022-09-19 01:20:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void FirstApp::loadGameObjects() {
|
2022-09-25 23:05:56 +00:00
|
|
|
|
2022-09-26 15:03:27 +00:00
|
|
|
for(int x = 0; x < 10; x++) {
|
|
|
|
for(int z = 0; z < 10; z++) {
|
|
|
|
Chunk* chunk = Chunk::newChunk(x, z, 53463);
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 23:05:56 +00:00
|
|
|
|
2022-09-26 15:03:27 +00:00
|
|
|
for(int x = 0; x < 10; x++) {
|
|
|
|
for(int z = 0; z < 10; z++) {
|
|
|
|
Chunk* chunk = Chunk::getChunk(x,z);
|
|
|
|
chunk->createMesh();
|
|
|
|
|
|
|
|
auto chunkObject = xe::GameObject::createGameObject();
|
|
|
|
chunkObject.model = chunk->getMesh();
|
|
|
|
chunkObject.transform.translation = {16.f*x, 0.f, 16.f*z};
|
|
|
|
gameObjects.push_back(std::move(chunkObject));
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 23:05:56 +00:00
|
|
|
|
2022-09-19 01:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|