mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-06 17:13:51 +00:00
fix(camera): NaN/range guards on Camera setters
setPosition/setRotation/setAspectRatio/setFov now reject: - NaN/inf inputs (would produce NaN view/proj matrix → frozen GPU on some drivers, garbage frustum culling everywhere) - aspectRatio <= 0 (degenerate perspective) - fov <= 0 or >= 180 (degenerate perspective) Camera is constructed and set from many code paths; pushing the guards into the setters means none of them need to remember.
This commit is contained in:
parent
39f4a433ff
commit
500ad2e711
1 changed files with 21 additions and 4 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <cmath>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering {
|
||||
|
|
@ -15,10 +16,26 @@ class Camera {
|
|||
public:
|
||||
Camera();
|
||||
|
||||
void setPosition(const glm::vec3& pos) { position = pos; updateViewMatrix(); }
|
||||
void setRotation(float yaw, float pitch) { this->yaw = yaw; this->pitch = pitch; updateViewMatrix(); }
|
||||
void setAspectRatio(float aspect) { aspectRatio = aspect; updateProjectionMatrix(); }
|
||||
void setFov(float fov) { this->fov = fov; updateProjectionMatrix(); }
|
||||
void setPosition(const glm::vec3& pos) {
|
||||
// Reject NaN/inf — would produce a NaN view matrix and freeze the
|
||||
// GPU in some drivers, or produce garbage frustum culling.
|
||||
if (!std::isfinite(pos.x) || !std::isfinite(pos.y) || !std::isfinite(pos.z)) return;
|
||||
position = pos; updateViewMatrix();
|
||||
}
|
||||
void setRotation(float yaw, float pitch) {
|
||||
if (!std::isfinite(yaw) || !std::isfinite(pitch)) return;
|
||||
this->yaw = yaw; this->pitch = pitch; updateViewMatrix();
|
||||
}
|
||||
void setAspectRatio(float aspect) {
|
||||
// glm::perspective with aspect <= 0 produces NaN in the projection.
|
||||
if (!std::isfinite(aspect) || aspect <= 0.0f) return;
|
||||
aspectRatio = aspect; updateProjectionMatrix();
|
||||
}
|
||||
void setFov(float fov) {
|
||||
// glm::perspective(0) is degenerate; >180 wraps the trig.
|
||||
if (!std::isfinite(fov) || fov <= 0.0f || fov >= 180.0f) return;
|
||||
this->fov = fov; updateProjectionMatrix();
|
||||
}
|
||||
|
||||
const glm::vec3& getPosition() const { return position; }
|
||||
const glm::mat4& getViewMatrix() const { return viewMatrix; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue