diff --git a/Renderer/Renderer.cpp b/Renderer/Renderer.cpp index a6c745a..73ba52f 100644 --- a/Renderer/Renderer.cpp +++ b/Renderer/Renderer.cpp @@ -18,16 +18,6 @@ #include - -// const static std::vector triangle = { -// {{ 1.0, -1.0, -1.0 }, {}, { 1.0, 0.0 }}, -// {{ 1.0, 1.0, -1.0 }, {}, { 1.0, 1.0 }}, -// {{-1.0, 1.0, -1.0 }, {}, { 0.0, 1.0 }}, -// {{-1.0, 1.0, -1.0 }, {}, { 0.0, 1.0 }}, -// {{-1.0, -1.0, -1.0 }, {}, { 0.0, 0.0 }}, -// {{ 1.0, -1.0, -1.0 }, {}, { 1.0, 0.0 }}, -// }; - using namespace std::string_literals; Renderer::Renderer(Window& win) : win(win) { @@ -325,7 +315,7 @@ void Renderer::draw() { const auto t = static_cast(frame) * 0.0167f; uniform_buffer->upload(UniformData{ - .mvp = p * glm::rotate(glm::translate(glm::mat4(1.0), -glm::vec3(0.0, 0.0, 3.0) * t / 3.0f), t, glm::vec3(1.0, 0.0, 0.0)), + .mvp = p * cam.view(), .time = t, .aspect_ratio = static_cast(sz.width)/static_cast(sz.height), }); diff --git a/Renderer/Renderer.hpp b/Renderer/Renderer.hpp index f6c01c4..832c701 100644 --- a/Renderer/Renderer.hpp +++ b/Renderer/Renderer.hpp @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -57,4 +59,6 @@ struct Renderer { std::vector> models; std::unique_ptr ui; + + Camera cam {}; }; diff --git a/Scene/Camera.hpp b/Scene/Camera.hpp new file mode 100644 index 0000000..bb8a310 --- /dev/null +++ b/Scene/Camera.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +using glm::sin; +using glm::cos; + +struct Camera { + /* using the math convention of theta = azimuthal */ + float theta = glm::radians(90.0f); + float phi = 0.0f; + /* r always = 1 */ + + glm::vec3 pos = glm::vec3(0.0f); + + inline glm::mat4 view() { + return glm::lookAt(pos, pos+glm::vec3(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi)), glm::vec3(0.0, 1.0, 0.0)); + } +}; \ No newline at end of file diff --git a/UI/UI.cpp b/UI/UI.cpp index 4e72235..bd3d4de 100644 --- a/UI/UI.cpp +++ b/UI/UI.cpp @@ -9,7 +9,9 @@ #include -UI::UI(Renderer* ren) : dev(ren->dev) { +#include + +UI::UI(Renderer* ren) : dev(ren->dev), info{ .cam = ren->cam } { IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -88,6 +90,11 @@ void UI::newFrame() { ImGui::Begin("Rendering Info", nullptr); ImGui::Text("FPS: %f", info.fps); + ImGui::SliderAngle("Theta", &info.cam.theta, 0.01, 179.9); + ImGui::SliderAngle("Phi", &info.cam.phi); + ImGui::SliderFloat("cam.x", &info.cam.pos.x, -1e2, 1e2); + ImGui::SliderFloat("cam.y", &info.cam.pos.y, -1e2, 1e2); + ImGui::SliderFloat("cam.z", &info.cam.pos.z, -1e2, 1e2); ImGui::End(); } diff --git a/UI/UI.hpp b/UI/UI.hpp index 630de33..a4fa466 100644 --- a/UI/UI.hpp +++ b/UI/UI.hpp @@ -6,10 +6,13 @@ #include struct Renderer; +struct Camera; struct UI { struct UI_Info { float fps = 0.0; + /* camera stuff */ + Camera& cam; } info; vk::Device dev;