Created a working camera controlled by the UI, next step is to incorporate Input class and have it be mouse/keyboard controlled
This commit is contained in:
parent
538d3a7dcb
commit
ef90718135
@ -18,16 +18,6 @@
|
|||||||
|
|
||||||
#include <UI/UI.hpp>
|
#include <UI/UI.hpp>
|
||||||
|
|
||||||
|
|
||||||
// const static std::vector<Vertex> 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;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
Renderer::Renderer(Window& win) : win(win) {
|
Renderer::Renderer(Window& win) : win(win) {
|
||||||
@ -325,7 +315,7 @@ void Renderer::draw() {
|
|||||||
const auto t = static_cast<float>(frame) * 0.0167f;
|
const auto t = static_cast<float>(frame) * 0.0167f;
|
||||||
|
|
||||||
uniform_buffer->upload(UniformData{
|
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,
|
.time = t,
|
||||||
.aspect_ratio = static_cast<float>(sz.width)/static_cast<float>(sz.height),
|
.aspect_ratio = static_cast<float>(sz.width)/static_cast<float>(sz.height),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -9,6 +9,8 @@
|
|||||||
#include <Renderer/CommandBuffer.hpp>
|
#include <Renderer/CommandBuffer.hpp>
|
||||||
#include <Renderer/RenderPass.hpp>
|
#include <Renderer/RenderPass.hpp>
|
||||||
|
|
||||||
|
#include <Scene/Camera.hpp>
|
||||||
|
|
||||||
#include <Model/Model.hpp>
|
#include <Model/Model.hpp>
|
||||||
|
|
||||||
#include <UI/UI.hpp>
|
#include <UI/UI.hpp>
|
||||||
@ -57,4 +59,6 @@ struct Renderer {
|
|||||||
|
|
||||||
std::vector<std::shared_ptr<Model>> models;
|
std::vector<std::shared_ptr<Model>> models;
|
||||||
std::unique_ptr<UI> ui;
|
std::unique_ptr<UI> ui;
|
||||||
|
|
||||||
|
Camera cam {};
|
||||||
};
|
};
|
||||||
|
|||||||
20
Scene/Camera.hpp
Normal file
20
Scene/Camera.hpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
#include <Renderer/Renderer.hpp>
|
#include <Renderer/Renderer.hpp>
|
||||||
|
|
||||||
UI::UI(Renderer* ren) : dev(ren->dev) {
|
#include <Scene/Camera.hpp>
|
||||||
|
|
||||||
|
UI::UI(Renderer* ren) : dev(ren->dev), info{ .cam = ren->cam } {
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
|
|
||||||
@ -88,6 +90,11 @@ void UI::newFrame() {
|
|||||||
ImGui::Begin("Rendering Info", nullptr);
|
ImGui::Begin("Rendering Info", nullptr);
|
||||||
|
|
||||||
ImGui::Text("FPS: %f", info.fps);
|
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();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,13 @@
|
|||||||
#include <Renderer/CommandBuffer.hpp>
|
#include <Renderer/CommandBuffer.hpp>
|
||||||
|
|
||||||
struct Renderer;
|
struct Renderer;
|
||||||
|
struct Camera;
|
||||||
|
|
||||||
struct UI {
|
struct UI {
|
||||||
struct UI_Info {
|
struct UI_Info {
|
||||||
float fps = 0.0;
|
float fps = 0.0;
|
||||||
|
/* camera stuff */
|
||||||
|
Camera& cam;
|
||||||
} info;
|
} info;
|
||||||
|
|
||||||
vk::Device dev;
|
vk::Device dev;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user