1#include "Base/Camera.h"
3#include "imgui/imgui.h"
7#include <glm/gtc/constants.hpp>
8#include <glm/gtc/quaternion.hpp>
9#include <glm/gtc/matrix_transform.hpp>
10#include <glm/ext/matrix_relational.hpp>
11#include <glm/ext/vector_relational.hpp>
12#include <glm/ext/scalar_relational.hpp>
16Camera::Camera(
bool ps)
22 aspect = 16.0f / 9.0f;
23 pitch = yaw = roll = 0;
24 view = glm::mat4(1.0f);
26 pers = glm::perspective(fov, 16.0f / 9.0f, cNear, cFar);
27 mposition = glm::vec3(0.0f, 0.0f, 3.0f);
28 mrotation = glm::vec3(1.0f);
33 rotation[1] = 2530.0f;
41 data[
"cNear"] = cNear;
43 data[
"aspect"] = aspect;
47 tmp[
"x"] = position[0];
48 tmp[
"y"] = position[1];
49 tmp[
"z"] = position[2];
50 data[
"position"] = tmp;
52 tmp[
"x"] = rotation[0];
53 tmp[
"y"] = rotation[1];
54 tmp[
"z"] = rotation[2];
55 data[
"rotation"] = tmp;
61 cNear = data[
"cNear"];
63 aspect = data[
"aspect"];
66 position[0] = data[
"position"][
"x"];
67 position[1] = data[
"position"][
"y"];
68 position[2] = data[
"position"][
"z"];
69 rotation[0] = data[
"rotation"][
"x"];
70 rotation[1] = data[
"rotation"][
"y"];
71 rotation[2] = data[
"rotation"][
"z"];
74void Camera::UpdateCamera(
float xmax,
float ymax)
76 mposition.x = position[0];
77 mposition.y = position[1];
78 mposition.z = position[2];
79 mrotation.x = glm::radians(rotation[0]);
80 mrotation.y = glm::radians(rotation[1]);
81 mrotation.z = glm::radians(rotation[2]);
85 view = glm::lookAt(mposition, mposition + cameraFront, cameraUp);
86 view = glm::rotate(view, glm::radians(mrotation.y), glm::vec3(1.0f, 0.0f, 0.0f));
87 view = glm::rotate(view, glm::radians(mrotation.x), glm::vec3(0.0f, 1.0f, 0.0f));
89 if (aspect > 200 || aspect < -200)
96 pers = glm::perspective(fov, (
float)(fabs(aspect) < 100 ? fabs(aspect) : 1.0f), cNear, cFar);
101 pers = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, cNear, cFar);
107void Camera::ShowSettings(
bool renderWindow,
bool *pOpen)
109 if(pOpen ==
nullptr || *pOpen)
113 ImGui::Begin((
"Camera Controls##" + std::to_string(camID)).c_str(), pOpen);
116 ImGui::Text(
"Camera Position");
117 ImGui::DragFloat3(
"##cameraPosition", position, 0.1f);
120 ImGui::Text(
"Camera Rotation");
121 ImGui::DragFloat3(
"##cameraRotation", rotation, 10);
124 ImGui::Text(
"Projection Settings");
126 ImGui::DragFloat(
"FOV", &fov, 0.01f);
127 ImGui::DragFloat(
"Aspect Ratio", &aspect, 0.01f);
128 ImGui::DragFloat(
"Near Clipping", &cNear, 0.01f);
129 ImGui::DragFloat(
"Far Clipping", &cFar, 0.01f);
a class to store JSON values
basic_json<> json
default JSON class