group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Camera.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <glm/glm.hpp>
7
9class Camera
10{
11public:
13 Camera();
14
18 void setAspect(float width, float height);
21 void setFov(float fovyDegrees);
24 void setZNear(float zNear);
27 void setZFar(float zFar);
28
31 void setEye(glm::vec3 eye);
37 void setTarget(float pitch, float yaw, float roll);
41 void setUp(glm::vec3 up);
42
44 void computeViewMatrix();
48
49 [[nodiscard]] const glm::mat4& getViewMatrix() const { return view_; }
50 [[nodiscard]] const glm::mat4& getProjectionMatrix() const { return projection_; }
51 [[nodiscard]] const glm::vec3& getEye() const { return eye_; }
53 [[nodiscard]] const glm::vec3 getRight() const;
55 [[nodiscard]] const glm::vec3 getForward() const;
56 [[nodiscard]] const glm::vec3& getUp() const { return up_; }
58 [[nodiscard]] glm::mat4 getViewProjection() const { return projection_ * view_; }
64 [[nodiscard]] float getFovy() const { return glm::degrees(fovy_); }
66 [[nodiscard]] float getAspect() const { return aspect_; }
68 [[nodiscard]] float getNear() const { return zNear_; }
70 [[nodiscard]] float getFar() const { return zFar_; }
71
80 void applySubpixelJitter(float jitterX, float jitterY);
81
82private:
83 glm::vec3 eye_{0.0f, 0.0f, 3.0f};
84 glm::vec3 target_{0.0f, 0.0f, 0.0f};
85 glm::vec3 up_{0.0f, 1.0f, 0.0f};
86
87 // Near/far are sized for Quake units.
88 float fovy_ = glm::radians(60.0f);
89 float aspect_ = 1.0f;
90 float zNear_ = 5.0f;
91 float zFar_ = 15000.0f;
92
93 glm::mat4 view_{1.0f};
94 glm::mat4 projection_{1.0f};
95};
Camera()
Construct with default eye position, 60 degree FOV, and Quake-unit near/far.
Definition Camera.cpp:10
void setUp(glm::vec3 up)
Override the up direction explicitly.
Definition Camera.cpp:72
void computeViewMatrix()
Recompute the view matrix from current eye, target, and up.
Definition Camera.cpp:78
glm::mat4 projection_
Definition Camera.hpp:94
glm::mat4 getViewProjection() const
Return the combined view-projection matrix.
Definition Camera.hpp:58
glm::vec3 up_
Definition Camera.hpp:85
const glm::vec3 getRight() const
Return the camera right vector (normalized cross of forward and up).
Definition Camera.cpp:100
float zNear_
Near clip (Quake units); 5 ≈ half a foot.
Definition Camera.hpp:90
float aspect_
Definition Camera.hpp:89
const glm::vec3 & getUp() const
Definition Camera.hpp:56
glm::mat4 view_
Definition Camera.hpp:93
void setZNear(float zNear)
Set the near clip plane distance (Quake units) and recompute projection.
Definition Camera.cpp:28
float zFar_
Far clip; covers the 4 000-unit play area with margin.
Definition Camera.hpp:91
float getFar() const
Return the far clip plane distance.
Definition Camera.hpp:70
glm::vec3 target_
Definition Camera.hpp:84
void setAspect(float width, float height)
Update aspect ratio from viewport dimensions and recompute projection.
Definition Camera.cpp:16
glm::vec3 eye_
Definition Camera.hpp:83
void applySubpixelJitter(float jitterX, float jitterY)
Apply a sub-pixel jitter offset to the projection matrix.
Definition Camera.cpp:89
void setTarget(float pitch, float yaw, float roll)
Set view direction from pitch, yaw, and roll (all radians).
Definition Camera.cpp:46
const glm::mat4 & getProjectionMatrix() const
Definition Camera.hpp:50
void setEye(glm::vec3 eye)
Set camera world-space position and recompute view matrix.
Definition Camera.cpp:40
void setZFar(float zFar)
Set the far clip plane distance (Quake units) and recompute projection.
Definition Camera.cpp:34
void setFov(float fovyDegrees)
Set vertical field of view in degrees and recompute projection.
Definition Camera.cpp:22
const glm::mat4 & getViewMatrix() const
Definition Camera.hpp:49
void computeProjectionMatrix()
Recompute the projection matrix from current FOV, aspect, near, far.
Definition Camera.cpp:83
float getNear() const
Return the near clip plane distance.
Definition Camera.hpp:68
const glm::vec3 getForward() const
Return the camera forward vector (normalized target - eye).
Definition Camera.cpp:95
float getFovy() const
Return the vertical field of view in degrees.
Definition Camera.hpp:64
const glm::vec3 & getEye() const
Definition Camera.hpp:51
float fovy_
Definition Camera.hpp:88
float getAspect() const
Return the aspect ratio (width / height).
Definition Camera.hpp:66