group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Camera Class Reference

First-person camera managing view and projection matrices. More...

#include <Camera.hpp>

Public Member Functions

 Camera ()
 Construct with default eye position, 60 degree FOV, and Quake-unit near/far.
void setAspect (float width, float height)
 Update aspect ratio from viewport dimensions and recompute projection.
void setFov (float fovyDegrees)
 Set vertical field of view in degrees and recompute projection.
void setZNear (float zNear)
 Set the near clip plane distance (Quake units) and recompute projection.
void setZFar (float zFar)
 Set the far clip plane distance (Quake units) and recompute projection.
void setEye (glm::vec3 eye)
 Set camera world-space position and recompute view matrix.
void setTarget (float pitch, float yaw, float roll)
 Set view direction from pitch, yaw, and roll (all radians).
void setUp (glm::vec3 up)
 Override the up direction explicitly.
void computeViewMatrix ()
 Recompute the view matrix from current eye, target, and up.
void computeProjectionMatrix ()
 Recompute the projection matrix from current FOV, aspect, near, far.
const glm::mat4 & getViewMatrix () const
const glm::mat4 & getProjectionMatrix () const
const glm::vec3 & getEye () const
const glm::vec3 getRight () const
 Return the camera right vector (normalized cross of forward and up).
const glm::vec3 getForward () const
 Return the camera forward vector (normalized target - eye).
const glm::vec3 & getUp () const
glm::mat4 getViewProjection () const
 Return the combined view-projection matrix.
float getFovy () const
 Return the vertical field of view in degrees.
float getAspect () const
 Return the aspect ratio (width / height).
float getNear () const
 Return the near clip plane distance.
float getFar () const
 Return the far clip plane distance.
void applySubpixelJitter (float jitterX, float jitterY)
 Apply a sub-pixel jitter offset to the projection matrix.

Private Attributes

glm::vec3 eye_ {0.0f, 0.0f, 3.0f}
glm::vec3 target_ {0.0f, 0.0f, 0.0f}
glm::vec3 up_ {0.0f, 1.0f, 0.0f}
float fovy_ = glm::radians(60.0f)
float aspect_ = 1.0f
float zNear_ = 5.0f
 Near clip (Quake units); 5 ≈ half a foot.
float zFar_ = 15000.0f
 Far clip; covers the 4 000-unit play area with margin.
glm::mat4 view_ {1.0f}
glm::mat4 projection_ {1.0f}

Detailed Description

First-person camera managing view and projection matrices.

Constructor & Destructor Documentation

◆ Camera()

Camera::Camera ( )

Construct with default eye position, 60 degree FOV, and Quake-unit near/far.

Here is the call graph for this function:

Member Function Documentation

◆ applySubpixelJitter()

void Camera::applySubpixelJitter ( float jitterX,
float jitterY )

Apply a sub-pixel jitter offset to the projection matrix.

Used by SMAA T2x temporal supersampling. Call after setAspect()/computeProjectionMatrix() so the base projection is established first. The offset is in NDC units (already scaled by 2/resolution).

Parameters
jitterXHorizontal jitter in NDC.
jitterYVertical jitter in NDC.

◆ computeProjectionMatrix()

void Camera::computeProjectionMatrix ( )

Recompute the projection matrix from current FOV, aspect, near, far.

Note
Flips Y for Vulkan NDC convention.
Here is the caller graph for this function:

◆ computeViewMatrix()

void Camera::computeViewMatrix ( )

Recompute the view matrix from current eye, target, and up.

Here is the caller graph for this function:

◆ getAspect()

float Camera::getAspect ( ) const
inlinenodiscard

Return the aspect ratio (width / height).

Here is the caller graph for this function:

◆ getEye()

const glm::vec3 & Camera::getEye ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getFar()

float Camera::getFar ( ) const
inlinenodiscard

Return the far clip plane distance.

◆ getForward()

const glm::vec3 Camera::getForward ( ) const
nodiscard

Return the camera forward vector (normalized target - eye).

Here is the caller graph for this function:

◆ getFovy()

float Camera::getFovy ( ) const
inlinenodiscard

Return the vertical field of view in degrees.

Internally fovy_ is stored in radians (matches glm::perspective and setFov's conversion). Convert back here so the public API contract stays consistent with setFov(fovyDegrees).

Here is the caller graph for this function:

◆ getNear()

float Camera::getNear ( ) const
inlinenodiscard

Return the near clip plane distance.

Here is the caller graph for this function:

◆ getProjectionMatrix()

const glm::mat4 & Camera::getProjectionMatrix ( ) const
inlinenodiscard

◆ getRight()

const glm::vec3 Camera::getRight ( ) const
nodiscard

Return the camera right vector (normalized cross of forward and up).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUp()

const glm::vec3 & Camera::getUp ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ getViewMatrix()

const glm::mat4 & Camera::getViewMatrix ( ) const
inlinenodiscard

◆ getViewProjection()

glm::mat4 Camera::getViewProjection ( ) const
inlinenodiscard

Return the combined view-projection matrix.

◆ setAspect()

void Camera::setAspect ( float width,
float height )

Update aspect ratio from viewport dimensions and recompute projection.

Parameters
widthViewport width in pixels.
heightViewport height in pixels.
Here is the call graph for this function:

◆ setEye()

void Camera::setEye ( glm::vec3 eye)

Set camera world-space position and recompute view matrix.

Parameters
eyeNew camera position in world space.
Here is the call graph for this function:

◆ setFov()

void Camera::setFov ( float fovyDegrees)

Set vertical field of view in degrees and recompute projection.

Parameters
fovyDegreesVertical FOV in degrees.
Here is the call graph for this function:

◆ setTarget()

void Camera::setTarget ( float pitch,
float yaw,
float roll )

Set view direction from pitch, yaw, and roll (all radians).

Roll rotates the up vector around the forward axis (wallrun tilt).

Parameters
pitchVertical angle in radians (positive looks down).
yawHorizontal angle in radians (0 faces +Z).
rollRoll angle in radians for camera tilt.
Here is the call graph for this function:

◆ setUp()

void Camera::setUp ( glm::vec3 up)

Override the up direction explicitly.

Useful for non-gravity-aligned orientations.

Parameters
upNew up direction vector.
Here is the call graph for this function:

◆ setZFar()

void Camera::setZFar ( float zFar)

Set the far clip plane distance (Quake units) and recompute projection.

Parameters
zFarFar clip plane distance.
Here is the call graph for this function:

◆ setZNear()

void Camera::setZNear ( float zNear)

Set the near clip plane distance (Quake units) and recompute projection.

Parameters
zNearNear clip plane distance.
Here is the call graph for this function:

Member Data Documentation

◆ aspect_

float Camera::aspect_ = 1.0f
private

◆ eye_

glm::vec3 Camera::eye_ {0.0f, 0.0f, 3.0f}
private

◆ fovy_

float Camera::fovy_ = glm::radians(60.0f)
private

◆ projection_

glm::mat4 Camera::projection_ {1.0f}
private

◆ target_

glm::vec3 Camera::target_ {0.0f, 0.0f, 0.0f}
private

◆ up_

glm::vec3 Camera::up_ {0.0f, 1.0f, 0.0f}
private

◆ view_

glm::mat4 Camera::view_ {1.0f}
private

◆ zFar_

float Camera::zFar_ = 15000.0f
private

Far clip; covers the 4 000-unit play area with margin.

◆ zNear_

float Camera::zNear_ = 5.0f
private

Near clip (Quake units); 5 ≈ half a foot.


The documentation for this class was generated from the following files: