Skip to content

Commit

Permalink
Only signal camera update when something actually changed
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaWillems committed Jan 13, 2024
1 parent 6782060 commit f6abda6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions base/camera.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Basic camera class
*
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
Expand All @@ -20,6 +20,8 @@ class Camera

void updateViewMatrix()
{
glm::mat4 currentMatrix = matrices.view;

glm::mat4 rotM = glm::mat4(1.0f);
glm::mat4 transM;

Expand All @@ -44,7 +46,9 @@ class Camera

viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);

updated = true;
if (matrices.view != currentMatrix) {
updated = true;
}
};
public:
enum CameraType { lookat, firstperson };
Expand All @@ -57,7 +61,7 @@ class Camera
float rotationSpeed = 1.0f;
float movementSpeed = 1.0f;

bool updated = false;
bool updated = true;
bool flipY = false;

struct
Expand Down Expand Up @@ -89,21 +93,29 @@ class Camera

void setPerspective(float fov, float aspect, float znear, float zfar)
{
glm::mat4 currentMatrix = matrices.perspective;
this->fov = fov;
this->znear = znear;
this->zfar = zfar;
matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar);
if (flipY) {
matrices.perspective[1][1] *= -1.0f;
}
if (matrices.view != currentMatrix) {
updated = true;
}
};

void updateAspectRatio(float aspect)
{
glm::mat4 currentMatrix = matrices.perspective;
matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar);
if (flipY) {
matrices.perspective[1][1] *= -1.0f;
}
if (matrices.view != currentMatrix) {
updated = true;
}
}

void setPosition(glm::vec3 position)
Expand Down

0 comments on commit f6abda6

Please sign in to comment.