-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
107 lines (83 loc) · 2.9 KB
/
Copy pathmain.cc
File metadata and controls
107 lines (83 loc) · 2.9 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
#include "scene/scene.h"
#include "scene/camera.h"
#include "scene/entity.h"
#include "scene/light_manager.h"
#include "math/vector.h"
#include "light/directional_light.h"
#include "light_models/blinn_phong.h"
#include "fps_counter/fps_counter.h"
#include "io/input_handler.h"
#include "io/output_handler.h"
#include "rendering/renderer.h"
#include "preprocess/test.h"
#include "preprocess/texture_register.h"
#include "world/camera_controller.h"
#include "world/world.h"
#include "world/test_world.h"
int main(int argc, char* argv[])
{
const int width = 120;
const int height = 30;
Scene scene;
auto input_handler = std::make_shared<Input_Handler>(nullptr, true);
auto texture_manager_ptr = std::make_shared<Texture_Manager>();
TextureRegisterPreprocess(*texture_manager_ptr);
scene.SetTextureManager(texture_manager_ptr);
Vec3 camera_pos = Vec3(5.5f, 5.5f, 5.5f);
Vec3 camera_target = Vec3(0.0f, 0.0f, 0.0f);
Vec3 camera_up = Vec3(0.0f, 1.0, 0.0f);
float fov = 45.0f;
float cell_aspect = 0.5f;
float aspect = (float)width / (float)height * cell_aspect;
float near_plane = -0.1f;
float far_plane = -50.0f;
auto camera = std::make_shared<Camera>(
camera_pos,
camera_target,
camera_up,
fov,
aspect,
near_plane,
far_plane
);
auto camera_controller = std::make_shared<Camera_Controller>(input_handler, camera);
scene.SetCamera(camera);
scene.GetLightManager()->SetAmbient(Vec3(0.30f, 0.30f, 0.30f));
auto key_light = std::make_shared<Directional_Light>(Vec3(50, 100, 50), 1.0f);
scene.GetLightManager()->AddLight(key_light);
/*
std::shared_ptr<Entity> entity;
if (true)
entity = CreateCubeEntity_Flat24_Fixed(5.0f);
else
entity = CreateCubeEntity_Fla t24_Debug(5.0f);
scene.AddEntity(entity);
*/
std::unique_ptr<World> world = std::make_unique<Test_World>();
world->SetWorld();
auto world_info = world->GetWorldInfo();
for (const std::shared_ptr<Entity>& entity : world_info )
{
scene.AddEntity(entity);
}
camera->SetPosition(world_info[0]->transform.position);
Renderer renderer(width, height);
renderer.SetLightingModel(std::make_unique<Blinn_Phong>());
Output_Handler output_handler(width, height);
Fps_Counter fps_counter;
fps_counter.Start();
auto lastTime = std::chrono::high_resolution_clock::now();
int fps = 0;
while ( true )
{
auto now = std::chrono::high_resolution_clock::now();
float dt = std::chrono::duration<float>(now - lastTime).count();
lastTime = now;
input_handler->Poll();
if (input_handler->IsKeyDown(Key::SPACE)) break;
camera_controller->Update(dt);
renderer.Render(scene);
output_handler.PrintBuffer(renderer.GetFrameBuffer(), fps);
fps = fps_counter.Get_Fps();
}
}