~ | ImGui camera modification

This commit is contained in:
TheRedShip
2025-01-12 17:51:26 +01:00
parent 3f7eb5e05a
commit fec85708b6
7 changed files with 74 additions and 31 deletions

View File

@ -3,6 +3,6 @@ Pos=60,60
Size=400,400
[Window][Settings]
Pos=1508,73
Pos=1511,75
Size=368,276

View File

@ -42,14 +42,14 @@ class Camera
glm::vec3 getPosition();
glm::vec2 getDirection();
glm::vec3 getViewSetting();
glm::mat4 getViewMatrix();
int getBounce();
float getFov();
float getVelocity();
float &getFov();
float &getAperture();
float &getFocus();
int &getBounce();
GPUCamera getGPUData();

View File

@ -33,6 +33,9 @@ class Window
static void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos);
static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods);
void imGuiNewFrame();
void imGuiRender();
GLFWwindow *getWindow(void) const;
float getFps(void) const;
int getFrameCount(void) const;

View File

@ -1,4 +1,4 @@
CAM 18.2756 8.40071 48.9905 -0.2 -470.601 0.1 23.9 45 10
CAM 18.2756 8.40071 48.9905 -0.4 -466.401 0.249 23.227 45 10
MAT 255 050 050 1.0 0.0 0.0 // 0 red
MAT 050 255 050 1.0 0.0 0.0 // 1 green

View File

@ -22,13 +22,6 @@ int main(int argc, char **argv)
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window.getWindow(), true);
ImGui_ImplOpenGL3_Init("#version 430");
GLint max_gpu_size;
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
@ -88,20 +81,12 @@ int main(int argc, char **argv)
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
window.imGuiNewFrame();
glUseProgram(shader.getProgram());
shader.drawTriangles(size);
ImGui::Begin("Settings");
ImGui::Text("Fps: %d", int(window.getFps()));
ImGui::Checkbox("Accumulate", &window.getAccumulate());
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
window.imGuiRender();
window.display();
window.pollEvents();

View File

@ -100,11 +100,6 @@ glm::vec2 Camera::getDirection()
return (glm::vec2(_pitch, _yaw));
}
glm::vec3 Camera::getViewSetting()
{
return (glm::vec3(_aperture_size, _focus_distance, _fov));
}
GPUCamera Camera::getGPUData()
{
GPUCamera data;
@ -126,11 +121,26 @@ float Camera::getVelocity()
return (glm::length(_velocity));
}
int Camera::getBounce()
int &Camera::getBounce()
{
return (_bounce);
}
float &Camera::getFov()
{
return (_fov);
}
float &Camera::getAperture()
{
return (_aperture_size);
}
float &Camera::getFocus()
{
return (_focus_distance);
}
void Camera::setPosition(glm::vec3 position)
{
_position = position;

View File

@ -45,6 +45,13 @@ Window::Window(Scene *scene, int width, int height, const char *title, int sleep
gladLoadGL(glfwGetProcAddress);
glfwSwapInterval(sleep);
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO(); (void)io;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(_window, true);
ImGui_ImplOpenGL3_Init("#version 430");
}
Window::~Window(void)
@ -111,12 +118,14 @@ void Window::keyCallback(GLFWwindow *window, int key, int scancode, int action,
{
glm::vec3 pos = win->_scene->getCamera()->getPosition();
glm::vec2 dir = win->_scene->getCamera()->getDirection();
glm::vec3 settings = win->_scene->getCamera()->getViewSetting();
float aperture = win->_scene->getCamera()->getAperture();
float focus = win->_scene->getCamera()->getFocus();
float fov = win->_scene->getCamera()->getFov();
int bounce = win->_scene->getCamera()->getBounce();
std::cout << "\nCAM\t" << pos.x << " " << pos.y << " " << pos.z << "\t"
<< dir.x << " " << dir.y << " " << "\t"
<< settings.x << " " << settings.y << " " << settings.z << "\t" << bounce
<< aperture << " " << focus << " " << fov << "\t" << bounce
<< std::endl;
}
}
@ -151,6 +160,42 @@ bool Window::shouldClose()
return glfwWindowShouldClose(_window);
}
void Window::imGuiNewFrame()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
void Window::imGuiRender()
{
bool has_changed = false;
ImGui::Begin("Settings");
ImGui::Text("Fps: %d", int(_fps));
ImGui::Text("Frame: %d", _frameCount);
if (ImGui::CollapsingHeader("Camera"))
{
if (ImGui::Checkbox("Accumulate", &accumulate))
_frameCount = 0;
has_changed |= ImGui::SliderInt("Bounce", &_scene->getCamera()->getBounce(), 0, 20);
has_changed |= ImGui::SliderFloat("FOV", &_scene->getCamera()->getFov(), 1.0f, 180.0f);
has_changed |= ImGui::SliderFloat("Aperture", &_scene->getCamera()->getAperture(), 0.0f, 1.0f);
has_changed |= ImGui::SliderFloat("Focus", &_scene->getCamera()->getFocus(), 0.0f, 150.0f);
}
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (has_changed)
_frameCount = -1;
}
GLFWwindow *Window::getWindow(void) const
{
return (_window);