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
8#define NUM_FRUSTUM_PLANES 6
9
11{
12 glm::vec4 left;
13 glm::vec4 right;
14 glm::vec4 bottom;
15 glm::vec4 top;
16 glm::vec4 near;
17 glm::vec4 far;
18};
19
22{
23public:
25 NewCamera();
26
30 void setAspect(float width, float height);
31
34 void setFov(float fovyDegrees);
35
38 void setZNear(float zNear);
39
42 void setZFar(float zFar);
43
46 void setEye(glm::vec3 eye);
47
55 void setTarget(float pitch, float yaw, float roll);
56
59 void setUp(glm::vec3 up);
60
63
64 static FrustumPlanes gribbHartmannFrustumPlanes(const glm::mat4 &viewProjectionMat);
65
67 [[nodiscard]] glm::mat4 getViewProjectionMatrix() const { return view_projection_; }
69 [[nodiscard]] glm::mat4 getViewMatrix() const { return view_; }
70 [[nodiscard]] glm::mat4 getProjectionMatrix() const { return projection_; }
71
73 [[nodiscard]] glm::mat4 getViewProjection() const { return view_projection_; }
74
75 [[nodiscard]] const glm::vec3& getEye() const { return eye_; }
76 [[nodiscard]] glm::vec3 getForward() const;
77 [[nodiscard]] glm::vec3 getRight() const;
78 [[nodiscard]] const glm::vec3& getUp() const { return up_; }
79
80private:
81 glm::vec3 eye_{0.0f, 0.0f, 3.0f};
82 glm::vec3 target_{0.0f, 0.0f, 0.0f};
83 glm::vec3 up_{0.0f, 1.0f, 0.0f};
84
85 // Near/far are sized for Quake units.
86 float fovy_ = glm::radians(60.0f);
87 float aspect_ = 1.0f;
88 float zNear_ = 1.0f;
89 float zFar_ = 15000.0f;
90
91 glm::mat4 view_{1.0f};
92 glm::mat4 projection_{1.0f};
93 glm::mat4 view_projection_{1.0f};
94
96};
glm::mat4 view_projection_
Definition Camera.hpp:93
glm::vec3 up_
Definition Camera.hpp:83
float fovy_
Definition Camera.hpp:86
float zFar_
Far clip; covers the 4 000-unit play area with margin.
Definition Camera.hpp:89
void setEye(glm::vec3 eye)
Set the camera eye position in world space (modifies view matrix).
Definition Camera.cpp:36
float zNear_
Near clip (Quake units); 1 ≈ a tenth of a foot (close enough for the FP viewmodel).
Definition Camera.hpp:88
const glm::vec3 & getUp() const
Definition Camera.hpp:78
void setZFar(float zFar)
Set the far clip plane distance.
Definition Camera.cpp:31
glm::vec3 target_
Definition Camera.hpp:82
void setUp(glm::vec3 up)
Explicitly set the camera up direction, overriding setTarget's up vector.
Definition Camera.cpp:76
void computeViewProjectionMatrix()
Recompute the combined view-projection matrix from current parameters.
Definition Camera.cpp:81
glm::mat4 getViewProjectionMatrix() const
Return the combined view-projection matrix.
Definition Camera.hpp:67
NewCamera()
Construct a NewCamera with default perspective and position.
Definition Camera.cpp:11
glm::vec3 eye_
Definition Camera.hpp:81
const glm::vec3 & getEye() const
Definition Camera.hpp:75
void setAspect(float width, float height)
Set the aspect ratio from pixel dimensions (modifies projection matrix).
Definition Camera.cpp:16
void setFov(float fovyDegrees)
Set the vertical field of view in degrees.
Definition Camera.cpp:21
glm::vec3 getRight() const
Definition Camera.cpp:116
FrustumPlanes viewProjectionFrustumPlanes_
Definition Camera.hpp:95
void setZNear(float zNear)
Set the near clip plane distance.
Definition Camera.cpp:26
FrustumPlanes getViewProjectionFrustumPlane() const
Definition Camera.hpp:68
glm::mat4 getViewProjection() const
Alias for getViewProjectionMatrix() — kept short for callsite ergonomics.
Definition Camera.hpp:73
glm::mat4 view_
Definition Camera.hpp:91
glm::mat4 getViewMatrix() const
Definition Camera.hpp:69
glm::mat4 getProjectionMatrix() const
Definition Camera.hpp:70
static FrustumPlanes gribbHartmannFrustumPlanes(const glm::mat4 &viewProjectionMat)
Definition Camera.cpp:92
glm::mat4 projection_
Definition Camera.hpp:92
float aspect_
Definition Camera.hpp:87
glm::vec3 getForward() const
Definition Camera.cpp:111
void setTarget(float pitch, float yaw, float roll)
Set the view direction from pitch, yaw, and roll (all in radians).
Definition Camera.cpp:41
Definition Camera.hpp:11
glm::vec4 left
Definition Camera.hpp:12
glm::vec4 far
Definition Camera.hpp:17
glm::vec4 near
Definition Camera.hpp:16
glm::vec4 right
Definition Camera.hpp:13
glm::vec4 bottom
Definition Camera.hpp:14
glm::vec4 top
Definition Camera.hpp:15