-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGame.cpp
More file actions
114 lines (96 loc) · 2.59 KB
/
Game.cpp
File metadata and controls
114 lines (96 loc) · 2.59 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "Game.h"
#include "Input/InputManager.h"
#include "Application/WinApplication.h"
#include "Render/Renderer.h"
using namespace StudyEngine;
// settings
const std::string TERRAIN_PATH = "models/Plane.obj";
const std::string SKY_PATH = "models/sphere.obj";
Game::Game()
{
running = new bool(false);
}
Game::~Game()
{
}
bool Game::Init()
{
WinApplication::Init(this);
Renderer::Init();
InputManager::Init();
terrain = new GameObject();
sky = new Atmosphere();
terrain->LoadModel(TERRAIN_PATH);
sky->LoadModel(SKY_PATH);
//terrain->CreateVertexBuffer();
//terrain->CreateIndexBuffer();
//sky->CreateVertexBuffer();
//sky->CreateIndexBuffer();
terrain->BindGraphicPipeline("shaders/terrainVert.spv", "shaders/terrainFrag.spv");
sky->BindGraphicPipeline("shaders/skyVert.spv", "shaders/skyFrag.spv");
camera = new Camera();
BindInput();
return true;
}
void Game::Update(float deltaTime)
{
WinApplication::Update();
if (InputManager::IsKeyPressed(InputEvents::Key_W))
{
camera->AddMovement(Vector3(0, 0, 1));
}
if (InputManager::IsKeyPressed(InputEvents::Key_S))
{
camera->AddMovement(Vector3(0, 0, -1));
}
if (InputManager::IsKeyPressed(InputEvents::Key_A))
{
camera->AddMovement(Vector3(-1, 0, 0));
}
if (InputManager::IsKeyPressed(InputEvents::Key_D))
{
camera->AddMovement(Vector3(1, 0, 0));
}
if (InputManager::IsKeyPressed(InputEvents::Key_UP))
{
sky->UpdateSun(0.01f);
}
if (InputManager::IsKeyPressed(InputEvents::Key_DOWN))
{
sky->UpdateSun(-0.01f);
}
camera->UpdateCameraTransform(deltaTime);
}
void Game::ShutDown()
{
Renderer::PreShutDown();
delete camera;
delete terrain;
delete sky;
Renderer::ShutDown();
}
void Game::DrawFrame()
{
Renderer::BeginRender();
camera->UploadCameraBuffer();
sky->Draw();
terrain->Draw();
Renderer::EndRender();
}
void Game::BindInput()
{
inputHandler.BindKey(InputEvents::Key_ESCAPE, [this]() {
if (running) { *running = false; }
});
inputHandler.BindKey(InputEvents::Key_F, [this]() {
camera->PrintCurrentCamMatrix();
});
inputHandler.BindMouseMove([this](float xposIn, float yposIn) {
if(*enableMouseCallback) camera->ProcessInput(xposIn, yposIn);
});
inputHandler.BindKey(InputEvents::Key_LEFT_CONTROL, [this]() {
*enableMouseCallback = !*enableMouseCallback;
InputManager::EnableMouseCallback(enableMouseCallback);
});
InputManager::RegisterHandler(&inputHandler);
}