Only signal camera update when something actually changed
This commit is contained in:
parent
67820604b8
commit
f6abda6cca
1 changed files with 15 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Basic camera class
|
* 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)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -20,6 +20,8 @@ private:
|
||||||
|
|
||||||
void updateViewMatrix()
|
void updateViewMatrix()
|
||||||
{
|
{
|
||||||
|
glm::mat4 currentMatrix = matrices.view;
|
||||||
|
|
||||||
glm::mat4 rotM = glm::mat4(1.0f);
|
glm::mat4 rotM = glm::mat4(1.0f);
|
||||||
glm::mat4 transM;
|
glm::mat4 transM;
|
||||||
|
|
||||||
|
|
@ -44,7 +46,9 @@ private:
|
||||||
|
|
||||||
viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||||
|
|
||||||
|
if (matrices.view != currentMatrix) {
|
||||||
updated = true;
|
updated = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
enum CameraType { lookat, firstperson };
|
enum CameraType { lookat, firstperson };
|
||||||
|
|
@ -57,7 +61,7 @@ public:
|
||||||
float rotationSpeed = 1.0f;
|
float rotationSpeed = 1.0f;
|
||||||
float movementSpeed = 1.0f;
|
float movementSpeed = 1.0f;
|
||||||
|
|
||||||
bool updated = false;
|
bool updated = true;
|
||||||
bool flipY = false;
|
bool flipY = false;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
|
@ -89,6 +93,7 @@ public:
|
||||||
|
|
||||||
void setPerspective(float fov, float aspect, float znear, float zfar)
|
void setPerspective(float fov, float aspect, float znear, float zfar)
|
||||||
{
|
{
|
||||||
|
glm::mat4 currentMatrix = matrices.perspective;
|
||||||
this->fov = fov;
|
this->fov = fov;
|
||||||
this->znear = znear;
|
this->znear = znear;
|
||||||
this->zfar = zfar;
|
this->zfar = zfar;
|
||||||
|
|
@ -96,14 +101,21 @@ public:
|
||||||
if (flipY) {
|
if (flipY) {
|
||||||
matrices.perspective[1][1] *= -1.0f;
|
matrices.perspective[1][1] *= -1.0f;
|
||||||
}
|
}
|
||||||
|
if (matrices.view != currentMatrix) {
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void updateAspectRatio(float aspect)
|
void updateAspectRatio(float aspect)
|
||||||
{
|
{
|
||||||
|
glm::mat4 currentMatrix = matrices.perspective;
|
||||||
matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar);
|
matrices.perspective = glm::perspective(glm::radians(fov), aspect, znear, zfar);
|
||||||
if (flipY) {
|
if (flipY) {
|
||||||
matrices.perspective[1][1] *= -1.0f;
|
matrices.perspective[1][1] *= -1.0f;
|
||||||
}
|
}
|
||||||
|
if (matrices.view != currentMatrix) {
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPosition(glm::vec3 position)
|
void setPosition(glm::vec3 position)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue