@@ -29,21 +29,21 @@ void Camera::rotate(float x, float y, float z) {
|
||||
updateVectors();
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getProjection() {
|
||||
glm::mat4 Camera::getProjection() const {
|
||||
constexpr float epsilon = 1e-6f; // 0.000001
|
||||
float aspect_ratio = this->aspect;
|
||||
if (std::fabs(aspect_ratio) < epsilon) {
|
||||
aspect_ratio = (float)Window::width / (float)Window::height;
|
||||
}
|
||||
if (perspective)
|
||||
return glm::perspective(fov * zoom, aspect_ratio, 0.05f, 1500.0f);
|
||||
return glm::perspective(fov * zoom, aspect_ratio, near, far);
|
||||
else if (flipped)
|
||||
return glm::ortho(0.0f, fov * aspect_ratio, fov, 0.0f);
|
||||
else
|
||||
return glm::ortho(0.0f, fov * aspect_ratio, 0.0f, fov);
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getView(bool pos) {
|
||||
glm::mat4 Camera::getView(bool pos) const {
|
||||
glm::vec3 camera_pos = this->position;
|
||||
if (!pos) {
|
||||
camera_pos = glm::vec3(0.0f);
|
||||
@@ -55,7 +55,7 @@ glm::mat4 Camera::getView(bool pos) {
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getProjView(bool pos) {
|
||||
glm::mat4 Camera::getProjView(bool pos) const {
|
||||
return getProjection() * getView(pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ public:
|
||||
bool perspective = true;
|
||||
bool flipped = false;
|
||||
float aspect = 0.0f;
|
||||
float near = 0.05f;
|
||||
float far = 1500.0f;
|
||||
|
||||
Camera() {
|
||||
updateVectors();
|
||||
@@ -27,9 +29,9 @@ public:
|
||||
void updateVectors();
|
||||
void rotate(float x, float y, float z);
|
||||
|
||||
glm::mat4 getProjection();
|
||||
glm::mat4 getView(bool position = true);
|
||||
glm::mat4 getProjView(bool position = true);
|
||||
glm::mat4 getProjection() const;
|
||||
glm::mat4 getView(bool position = true) const;
|
||||
glm::mat4 getProjView(bool position = true) const;
|
||||
|
||||
void setFov(float fov);
|
||||
float getFov() const;
|
||||
|
||||
Reference in New Issue
Block a user