From c9b26054cb569ced5d2807c2da6bb090ed2bc6a4 Mon Sep 17 00:00:00 2001 From: benkyd Date: Sun, 13 Nov 2022 21:36:40 +0000 Subject: [PATCH] airplane --- libhart/scene/camera.hpp | 2 ++ src/inferno.cpp | 16 ++++++++++++---- src/scene/camera.cpp | 17 +++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libhart/scene/camera.hpp b/libhart/scene/camera.hpp index 55ab1ac..637d509 100644 --- a/libhart/scene/camera.hpp +++ b/libhart/scene/camera.hpp @@ -17,6 +17,7 @@ public: glm::mat4 GetFrustrumMatrix(); void UpdateProjection(int width, int height); + void UpdateProjection(); // Keyboard void MoveCamera(uint8_t posDelta); @@ -33,6 +34,7 @@ public: glm::vec3 Position = {}; float Roll, Pitch, Yaw; + float FOV = 45.0f; glm::vec3 LookDirection = {}; private: diff --git a/src/inferno.cpp b/src/inferno.cpp index f27333c..a9d5499 100644 --- a/src/inferno.cpp +++ b/src/inferno.cpp @@ -176,9 +176,7 @@ int Inferno::run() if (showPreview && ImGui::Begin("Preview", nullptr, ImGuiWindowFlags_NoScrollbar)) { - const bool allowMove = ImGui::IsWindowHovered(); - - if (allowMove) + if (ImGui::IsWindowHovered()) { this->moveInput(); } else @@ -201,12 +199,18 @@ int Inferno::run() if (ImGui::Begin("Render")) { + ImGui::End(); } if (showRenderSettings && ImGui::Begin("Inferno HART")) { + if (ImGui::TreeNode("Render")) + { + ImGui::TreePop(); + } + if (ImGui::TreeNode("Camera")) { ImGui::PushItemWidth(100); @@ -223,9 +227,13 @@ int Inferno::run() camera.UpdateView(); ImGui::PopItemWidth(); + + ImGui::Text("Camera Zoom"); + ImGui::DragFloat("Zoom", &camera.FOV, -0.1f, 0.0f, 180.0f, "%.2f", ImGuiSliderFlags_None); ImGui::SameLine(); + camera.UpdateProjection(); + ImGui::TreePop(); } - ImGui::ShowDemoWindow(); ImGui::End(); } diff --git a/src/scene/camera.cpp b/src/scene/camera.cpp index e607d94..904910b 100644 --- a/src/scene/camera.cpp +++ b/src/scene/camera.cpp @@ -4,7 +4,7 @@ using namespace inferno; Camera::Camera() { - mProjMatrix = glm::perspective( glm::radians( 45.0f ), 1.0f, 0.1f, 1000.0f ); + mProjMatrix = glm::perspective( glm::radians(FOV), 1.0f, 0.1f, 1000.0f ); Roll = 0.0f; Pitch = 0.0f; @@ -20,7 +20,7 @@ Camera::Camera() Camera::Camera(int w, int h) { - mProjMatrix = glm::perspective(glm::radians(45.0f), (float)w / (float)h, 0.1f, 1000.0f); + mProjMatrix = glm::perspective(glm::radians(FOV), (float)w / (float)h, 0.1f, 1000.0f); Roll = 0.0f; Pitch = 0.0f; @@ -42,9 +42,9 @@ void Camera::UpdateView() glm::mat4 matYaw = glm::mat4(1.0f); //identity matrix // roll, pitch and yaw - matRoll = glm::rotate( matRoll, Roll, glm::vec3(0.0f, 0.0f, 1.0f)); - matPitch = glm::rotate( matPitch, Pitch, glm::vec3(1.0f, 0.0f, 0.0f)); - matYaw = glm::rotate( matYaw, Yaw, glm::vec3( 0.0f, 1.0f, 0.0f)); + matRoll = glm::rotate(matRoll, Roll, glm::vec3(0.0f, 0.0f, 1.0f)); + matPitch = glm::rotate(matPitch, Pitch, glm::vec3(1.0f, 0.0f, 0.0f)); + matYaw = glm::rotate(matYaw, Yaw, glm::vec3( 0.0f, 1.0f, 0.0f)); glm::mat4 rotate = matRoll * matPitch * matYaw; @@ -74,7 +74,12 @@ glm::mat4 Camera::GetProjectionMatrix() void Camera::UpdateProjection(int width, int height) { mViewport = {width, height}; - mProjMatrix = glm::perspective(glm::radians(45.0f), (float)width / (float)height, 0.1f, 1000.0f); + mProjMatrix = glm::perspective(glm::radians(FOV), (float)width / (float)height, 0.1f, 1000.0f); +} + +void Camera::UpdateProjection() +{ + mProjMatrix = glm::perspective(glm::radians(FOV), mViewport.x / mViewport.y, 0.1f, 1000.0f); } void Camera::MoveCamera(uint8_t posDelta)