Add Basic Camera

This commit is contained in:
4VRDriver
2020-09-03 15:33:51 +02:00
parent cd302d0005
commit 919f65fac7
8 changed files with 87 additions and 10 deletions

29
Camera.cpp Normal file
View File

@@ -0,0 +1,29 @@
#include "Camera.h"
#include <glm/gtc/matrix_transform.hpp>
#include <glm/ext/matrix_transform.hpp>
Camera::Camera(float fov, int width, int height) {
//projectionMatrix = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -10.f, 100.0f);
this->fov = fov;
projectionMatrix = glm::perspective(this->fov/2.0f, (float)width / (float)height, 0.1f, 1000.0f);
viewMatrix = glm::mat4(1.0f);
updateVPM();
}
glm::mat4 Camera::getViewProj() {
return viewProjectionMatrix;
}
void Camera::updateVPM() {
viewProjectionMatrix = projectionMatrix * viewMatrix;
}
void Camera::updateAspectRatio(int width, int height) {
projectionMatrix = glm::perspective(fov/2.0f, (float)width / (float)height, 0.1f, 1000.0f);
updateVPM();
}
void Camera::translate(glm::vec3 vector) {
viewMatrix = glm::translate(viewMatrix, vector * -1.0f);
}