-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (45 loc) · 1.81 KB
/
Copy pathmain.cpp
File metadata and controls
61 lines (45 loc) · 1.81 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
#include "engine.hpp"
#include "matrix.hpp"
#include "sdlapp.hpp"
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_scancode.h>
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 800;
const std::pair<int, int> DIMS = {SCREEN_WIDTH, SCREEN_HEIGHT};
int main() {
SDLApp sdl("3D Engine C++", SCREEN_WIDTH, SCREEN_HEIGHT);
SDL_SetWindowRelativeMouseMode(sdl.get_window(), true);
Camera camera(Vec4(6, 2, 3), Vec4(0, 0, 0), radians(70.f), {0.01, 1000}, DIMS);
camera.gen_projection_matrix();
camera.gen_view_matrix();
DirectionalLight sun(Vec4(1, -1, 1), Color(238,231,202), 0.8f);
Mesh mesh;
if (mesh.load_from_obj("models/Untitled.obj")) std::cout << "OBJ imported\n";
mesh.color = Color(200, 200, 200);
mesh.scale = Vec4(1,1,1);
std::cout << "Number of indexes:\t" << mesh.indexes.size() << "\n";
std::cout << "Number of vertices:\t" << mesh.vertices.size() << "\n\n";
float speed = 0.05f;
Vec2f mouse;
Mat comp_matrix;
while (sdl.isRunning()) {
sdl.pollEvents();
int numkeys;
const bool* state = SDL_GetKeyboardState(&numkeys);
SDL_GetRelativeMouseState(&mouse.x, &mouse.y);
if (mouse.x != 0 || mouse.y!=0) camera.rotate(mouse.x, mouse.y);
if (state[SDL_SCANCODE_W]) camera.move_forward(speed);
if (state[SDL_SCANCODE_S]) camera.move_forward(-speed);
if (state[SDL_SCANCODE_A]) camera.move_sideways(-speed);
if (state[SDL_SCANCODE_D]) camera.move_sideways(speed);
if (state[SDL_SCANCODE_R]) camera.move_altitude(speed);
if (state[SDL_SCANCODE_F]) camera.move_altitude(-speed);
sdl.clear(Color(0, 0, 0));
camera.gen_view_matrix();
comp_matrix = camera.projection_matrix * camera.view_matrix;
//mesh.rotation.y += M_PI/180;
sdl.draw_mesh(mesh, comp_matrix, {camera.zn, camera.zf}, camera.position, sun);
sdl.present();
}
return 0;
}