-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgui_impl.h
More file actions
121 lines (100 loc) · 3.85 KB
/
imgui_impl.h
File metadata and controls
121 lines (100 loc) · 3.85 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
115
116
117
118
119
120
121
#pragma once
#include "imgui.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#include "camera.cuh"
#include "cutil_math.h"
class ImGuiManager {
private:
static Camera initial_camera;
static int initial_samples;
public:
static void Init(GLFWwindow* window) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 330");
}
static void Shutdown() {
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
static void BeginFrame() {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
static void EndFrame() {
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
static void SetInitialState(const Camera& camera, int samples) {
initial_camera = camera;
initial_samples = samples;
}
static void CameraControls(Camera& camera, int& samples_per_pixel, int& samples_per_frame) {
ImGui::Begin("Camera Controls");
float lookfrom[3] = {camera.lookfrom.x, camera.lookfrom.y, camera.lookfrom.z};
float lookat[3] = {camera.lookat.x, camera.lookat.y, camera.lookat.z};
float up[3] = {camera.up.x, camera.up.y, camera.up.z};
float vfov = camera.vfov;
// Camera Position - both input and slider
if (ImGui::DragFloat3("Camera Position", lookfrom, 0.1f)) {
camera.lookfrom = make_float3(lookfrom[0], lookfrom[1], lookfrom[2]);
}
/* Commented out slider control
float pos_slider[3] = {lookfrom[0], lookfrom[1], lookfrom[2]};
if (ImGui::SliderFloat3("Camera Position Slider", pos_slider, -1000.0f, 1000.0f)) {
camera.lookfrom = make_float3(pos_slider[0], pos_slider[1], pos_slider[2]);
lookfrom[0] = pos_slider[0];
lookfrom[1] = pos_slider[1];
lookfrom[2] = pos_slider[2];
}
*/
// Look At - both input and slider
if (ImGui::DragFloat3("Look At", lookat, 0.1f)) {
camera.lookat = make_float3(lookat[0], lookat[1], lookat[2]);
}
/* Commented out slider control
float look_slider[3] = {lookat[0], lookat[1], lookat[2]};
if (ImGui::SliderFloat3("Look At Slider", look_slider, -1000.0f, 1000.0f)) {
camera.lookat = make_float3(look_slider[0], look_slider[1], look_slider[2]);
lookat[0] = look_slider[0];
lookat[1] = look_slider[1];
lookat[2] = look_slider[2];
}
*/
if (ImGui::DragFloat3("Up Vector", up, 0.1f)) {
camera.up = make_float3(up[0], up[1], up[2]);
}
if (ImGui::DragFloat("FOV", &vfov, 0.1f, 1.0f, 179.0f)) {
camera.vfov = vfov;
}
ImGui::Separator();
// Samples per pixel control - input box (commented out)
/*
if (ImGui::InputInt("Samples per Pixel", &samples_per_pixel, 100, 1000)) {
// Clamp the value to a reasonable range
samples_per_pixel = std::max(1, std::min(10000, samples_per_pixel));
}
*/
// Samples per frame slider
if (ImGui::SliderInt("Samples per Frame", &samples_per_frame, 1, 10)) {
// Clamp for safety
samples_per_frame = std::max(1, std::min(10, samples_per_frame));
}
ImGui::Separator();
// Reset camera button
if (ImGui::Button("Reset Camera")) {
camera = initial_camera;
}
ImGui::End();
}
};
// Initialize static members
Camera ImGuiManager::initial_camera;
int ImGuiManager::initial_samples;