mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
~ | ImGui camera modification
This commit is contained in:
19
srcs/RT.cpp
19
srcs/RT.cpp
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user