minor refactor
This commit is contained in:
parent
3b3c5f081c
commit
a4960097f0
@ -3,21 +3,17 @@
|
|||||||
|
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
|
|
||||||
using glm::vec3;
|
Camera::Camera(glm::vec3 position, float fov) : fov(fov), position(position), zoom(1.0f), rotation(1.0f) {
|
||||||
using glm::vec4;
|
|
||||||
using glm::mat4;
|
|
||||||
|
|
||||||
Camera::Camera(vec3 position, float fov) : fov(fov), position(position), zoom(1.0f), rotation(1.0f) {
|
|
||||||
updateVectors();
|
updateVectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::updateVectors(){
|
void Camera::updateVectors(){
|
||||||
front = vec3(rotation * vec4(0,0,-1,1));
|
front = glm::vec3(rotation * glm::vec4(0,0,-1,1));
|
||||||
right = vec3(rotation * vec4(1,0,0,1));
|
right = glm::vec3(rotation * glm::vec4(1,0,0,1));
|
||||||
up = vec3(rotation * vec4(0,1,0,1));
|
up = glm::vec3(rotation * glm::vec4(0,1,0,1));
|
||||||
dir = vec3(rotation * vec4(0,0,-1,1));
|
dir = glm::vec3(rotation * glm::vec4(0,0,-1,1));
|
||||||
dir.y = 0;
|
dir.y = 0;
|
||||||
float len = length(dir);
|
float len = glm::length(dir);
|
||||||
if (len > 0.0f){
|
if (len > 0.0f){
|
||||||
dir.x /= len;
|
dir.x /= len;
|
||||||
dir.z /= len;
|
dir.z /= len;
|
||||||
@ -25,14 +21,14 @@ void Camera::updateVectors(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Camera::rotate(float x, float y, float z){
|
void Camera::rotate(float x, float y, float z){
|
||||||
rotation = glm::rotate(rotation, z, vec3(0,0,1));
|
rotation = glm::rotate(rotation, z, glm::vec3(0,0,1));
|
||||||
rotation = glm::rotate(rotation, y, vec3(0,1,0));
|
rotation = glm::rotate(rotation, y, glm::vec3(0,1,0));
|
||||||
rotation = glm::rotate(rotation, x, vec3(1,0,0));
|
rotation = glm::rotate(rotation, x, glm::vec3(1,0,0));
|
||||||
|
|
||||||
updateVectors();
|
updateVectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 Camera::getProjection(){
|
glm::mat4 Camera::getProjection(){
|
||||||
float aspect = this->aspect;
|
float aspect = this->aspect;
|
||||||
if (aspect == 0.0f){
|
if (aspect == 0.0f){
|
||||||
aspect = (float)Window::width / (float)Window::height;
|
aspect = (float)Window::width / (float)Window::height;
|
||||||
@ -46,10 +42,10 @@ mat4 Camera::getProjection(){
|
|||||||
return glm::ortho(0.0f, fov*aspect, 0.0f, fov);
|
return glm::ortho(0.0f, fov*aspect, 0.0f, fov);
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 Camera::getView(bool pos){
|
glm::mat4 Camera::getView(bool pos){
|
||||||
vec3 position = this->position;
|
glm::vec3 position = this->position;
|
||||||
if (!pos) {
|
if (!pos) {
|
||||||
position = vec3(0.0f);
|
position = glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
if (perspective) {
|
if (perspective) {
|
||||||
return glm::lookAt(position, position+front, up);
|
return glm::lookAt(position, position+front, up);
|
||||||
@ -58,7 +54,7 @@ mat4 Camera::getView(bool pos){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 Camera::getProjView(bool pos){
|
glm::mat4 Camera::getProjView(bool pos){
|
||||||
return getProjection()*getView(pos);
|
return getProjection()*getView(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user