-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (69 loc) · 2.04 KB
/
main.cpp
File metadata and controls
89 lines (69 loc) · 2.04 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
#include <iostream>
#include "axis3d.h"
#include "camera.h"
#include "constants.h"
#include "engine.h"
#include "gltf.h"
#include "lineset.h"
#include "mesh.h"
class TestApp : public ogleng::Engine {
ogleng::OrbitCamera camera;
GLTFScene gltf;
ogleng::Axis3D axis;
bool draw_axis = true;
bool wireframe = false;
void orbit_camera_control() {
if (get_mouse(ogleng::Input::MOUSE_LEFT).held) {
camera.rotate(get_dmouse_x(), get_dmouse_y());
}
if (get_mouse(ogleng::Input::MOUSE_MIDDLE).held) {
camera.pan(get_dmouse_x(), get_dmouse_y());
}
camera.zoom(get_scroll_y());
}
bool create() override {
axis.init();
gltf = GLTFScene("../data/arissa.glb");
return true;
}
bool destroy() override {
return true;
}
bool update(float dt) override {
if (get_key(ogleng::Input::Key::ESCAPE).pressed) {
return false;
}
orbit_camera_control();
ogleng::mat4 vp = camera.projection() * camera.view();
if (draw_axis) {
axis.draw(vp);
}
gltf.update(get_current_time());
gltf.draw(vp, wireframe);
return true;
}
bool imgui(float dt) override {
ImGui::Begin("Misc.");
ImGui::Text("ImGUI says \"Hello!\"");
ImGui::Text("FPS: %.0f - %.2f ms per frame", fps, dt * 1000.0f);
ImGui::Checkbox("Vsync", &vsync);
ImGui::Checkbox("Draw axis", &draw_axis);
ImGui::Checkbox("Wireframe", &wireframe);
gltf.imgui_display(get_current_time());
ImGui::End();
return true;
}
// hook into the window resize calback
bool u_framebuffer_size_callback(int width, int height) override {
camera.set_aspect((float)width / (float)height);
// continue with the original callback function
return false;
}
};
int main(int argc, char *argv[]) {
TestApp app;
if (app.initialize(1280, 720, "OpenGL Viewer")) {
app.start();
}
return 0;
}