format: reformat project
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
+22
-22
@@ -1,60 +1,60 @@
|
||||
#include "Camera.hpp"
|
||||
#include "Window.hpp"
|
||||
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
#include "Window.hpp"
|
||||
|
||||
Camera::Camera(glm::vec3 position, float fov) : fov(fov), position(position) {
|
||||
updateVectors();
|
||||
}
|
||||
|
||||
void Camera::updateVectors(){
|
||||
front = glm::vec3(rotation * glm::vec4(0,0,-1,1));
|
||||
right = glm::vec3(rotation * glm::vec4(1,0,0,1));
|
||||
up = glm::vec3(rotation * glm::vec4(0,1,0,1));
|
||||
dir = glm::vec3(rotation * glm::vec4(0,0,-1,1));
|
||||
void Camera::updateVectors() {
|
||||
front = glm::vec3(rotation * glm::vec4(0, 0, -1, 1));
|
||||
right = glm::vec3(rotation * glm::vec4(1, 0, 0, 1));
|
||||
up = glm::vec3(rotation * glm::vec4(0, 1, 0, 1));
|
||||
dir = glm::vec3(rotation * glm::vec4(0, 0, -1, 1));
|
||||
dir.y = 0;
|
||||
float len = glm::length(dir);
|
||||
if (len > 0.0f){
|
||||
if (len > 0.0f) {
|
||||
dir.x /= len;
|
||||
dir.z /= len;
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::rotate(float x, float y, float z){
|
||||
rotation = glm::rotate(rotation, y, glm::vec3(0,1,0));
|
||||
rotation = glm::rotate(rotation, x, glm::vec3(1,0,0));
|
||||
rotation = glm::rotate(rotation, z, glm::vec3(0,0,1));
|
||||
void Camera::rotate(float x, float y, float z) {
|
||||
rotation = glm::rotate(rotation, y, glm::vec3(0, 1, 0));
|
||||
rotation = glm::rotate(rotation, x, glm::vec3(1, 0, 0));
|
||||
rotation = glm::rotate(rotation, z, glm::vec3(0, 0, 1));
|
||||
updateVectors();
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getProjection(){
|
||||
glm::mat4 Camera::getProjection() {
|
||||
float aspect = this->aspect;
|
||||
if (aspect == 0.0f){
|
||||
if (aspect == 0.0f) {
|
||||
aspect = (float)Window::width / (float)Window::height;
|
||||
}
|
||||
if (perspective)
|
||||
return glm::perspective(fov*zoom, aspect, 0.05f, 1500.0f);
|
||||
return glm::perspective(fov * zoom, aspect, 0.05f, 1500.0f);
|
||||
else if (flipped)
|
||||
return glm::ortho(0.0f, fov * aspect, fov, 0.0f);
|
||||
else
|
||||
if (flipped)
|
||||
return glm::ortho(0.0f, fov*aspect, fov, 0.0f);
|
||||
else
|
||||
return glm::ortho(0.0f, fov*aspect, 0.0f, fov);
|
||||
return glm::ortho(0.0f, fov * aspect, 0.0f, fov);
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getView(bool pos){
|
||||
glm::mat4 Camera::getView(bool pos) {
|
||||
glm::vec3 position = this->position;
|
||||
if (!pos) {
|
||||
position = glm::vec3(0.0f);
|
||||
}
|
||||
if (perspective) {
|
||||
return glm::lookAt(position, position+front, up);
|
||||
return glm::lookAt(position, position + front, up);
|
||||
} else {
|
||||
return glm::translate(glm::mat4(1.0f), position);
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getProjView(bool pos){
|
||||
return getProjection()*getView(pos);
|
||||
glm::mat4 Camera::getProjView(bool pos) {
|
||||
return getProjection() * getView(pos);
|
||||
}
|
||||
|
||||
void Camera::setFov(float fov) {
|
||||
|
||||
Reference in New Issue
Block a user