$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
camera.h File Reference

First-person camera module with realistic physics and head-bobbing. More...

#include <cglm/cglm.h>
Include dependency graph for camera.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Camera
 Represents a 3D camera with orientation, movement, and physical properties. More...
 

Macros

#define DEFAULT_CAMERA_SPEED   15.0F
 
#define DEFAULT_CAMERA_SENSITIVITY   0.15F
 
#define DEFAULT_CAMERA_ZOOM   60.0F
 
#define DEFAULT_ZOOM_SPEED   1.0F
 
#define DEFAULT_SCROLL_SENSITIVITY   50.0F
 
#define DEFAULT_MAX_PITCH   89.0F
 
#define DEFAULT_MIN_PITCH   -89.0F
 
#define DEFAULT_MAX_ALPHA   1.0F
 
#define DEFAULT_ACCELERATION   10.0F
 
#define DEFAULT_FRICTION   0.85F
 
#define DEFAULT_ROTATION_SMOOTHING   0.18F
 
#define DEFAULT_BOBBING_FREQUENCY   2.2F
 
#define DEFAULT_BOBBING_AMPLITUDE   0.0004F
 
#define DEFAULT_MIN_VELOCITY_FOR_BOBBING    0.5F
 
#define DEFAULT_BOBBING_RESET_SPEED   0.95F
 
#define DEFAULT_MIN_VELOCITY   0.01F
 
#define DEFAULT_TARGET_FPS   60
 
#define DEFAULT_FIXED_TIMESTEP    (1.0F / DEFAULT_TARGET_FPS)
 
#define DEFAULT_MOUSE_SMOOTHING_FACTOR   0.1F
 

Functions

void camera_init (Camera *cam, float distance, float yaw, float pitch)
 Initializes the camera with default values. More...
 
void camera_update_vectors (Camera *cam)
 Recalculates front, right, and up vectors from yaw and pitch. More...
 
void camera_process_mouse (Camera *cam, float xoffset, float yoffset)
 Processes mouse movement to update target orientation. More...
 
void camera_get_view_matrix (Camera *cam, mat4 view)
 Generates the 4x4 view matrix for this camera. More...
 
void camera_process_scroll (Camera *cam, float yoffset)
 Processes mouse scroll events to apply physical impulse. More...
 
void camera_fixed_update (Camera *cam)
 Performs one fixed-step physics update. More...
 

Detailed Description

First-person camera module with realistic physics and head-bobbing.

Macro Definition Documentation

◆ DEFAULT_ACCELERATION

#define DEFAULT_ACCELERATION   10.0F

Physical push strength.

◆ DEFAULT_BOBBING_AMPLITUDE

#define DEFAULT_BOBBING_AMPLITUDE   0.0004F

Height of head-bob.

◆ DEFAULT_BOBBING_FREQUENCY

#define DEFAULT_BOBBING_FREQUENCY   2.2F

Waves per meter.

◆ DEFAULT_BOBBING_RESET_SPEED

#define DEFAULT_BOBBING_RESET_SPEED   0.95F

Decay of bobbing offset.

◆ DEFAULT_CAMERA_SENSITIVITY

#define DEFAULT_CAMERA_SENSITIVITY   0.15F

Mouse scaling.

◆ DEFAULT_CAMERA_SPEED

#define DEFAULT_CAMERA_SPEED   15.0F

Units per second.

◆ DEFAULT_CAMERA_ZOOM

#define DEFAULT_CAMERA_ZOOM   60.0F

Default FOV.

◆ DEFAULT_FIXED_TIMESTEP

#define DEFAULT_FIXED_TIMESTEP    (1.0F / DEFAULT_TARGET_FPS)

Simulation step.

◆ DEFAULT_FRICTION

#define DEFAULT_FRICTION   0.85F

Velocity decay per frame.

◆ DEFAULT_MAX_ALPHA

#define DEFAULT_MAX_ALPHA   1.0F

Unused.

◆ DEFAULT_MAX_PITCH

#define DEFAULT_MAX_PITCH   89.0F

Upward look limit.

◆ DEFAULT_MIN_PITCH

#define DEFAULT_MIN_PITCH   -89.0F

Downward look limit.

◆ DEFAULT_MIN_VELOCITY

#define DEFAULT_MIN_VELOCITY   0.01F

Cutoff for full stop.

◆ DEFAULT_MIN_VELOCITY_FOR_BOBBING

#define DEFAULT_MIN_VELOCITY_FOR_BOBBING    0.5F

threshold to trigger bobbing.

◆ DEFAULT_MOUSE_SMOOTHING_FACTOR

#define DEFAULT_MOUSE_SMOOTHING_FACTOR   0.1F

Input lag simulation.

◆ DEFAULT_ROTATION_SMOOTHING

#define DEFAULT_ROTATION_SMOOTHING   0.18F

Orientation lerp factor.

◆ DEFAULT_SCROLL_SENSITIVITY

#define DEFAULT_SCROLL_SENSITIVITY   50.0F

Scroll impulsiveness.

◆ DEFAULT_TARGET_FPS

#define DEFAULT_TARGET_FPS   60

Reference for fixed updates.

◆ DEFAULT_ZOOM_SPEED

#define DEFAULT_ZOOM_SPEED   1.0F

FOV adjustment rate.

Function Documentation

◆ camera_fixed_update()

void camera_fixed_update ( Camera cam)

Performs one fixed-step physics update.

Handles momentum, friction, and head-bobbing calculations.

Parameters
camPointer to the camera instance.

◆ camera_get_view_matrix()

void camera_get_view_matrix ( Camera cam,
mat4  view 
)

Generates the 4x4 view matrix for this camera.

Parameters
camPointer to the camera instance.
[out]viewMatrix to populate.

◆ camera_init()

void camera_init ( Camera cam,
float  distance,
float  yaw,
float  pitch 
)

Initializes the camera with default values.

Parameters
camPointer to the camera instance.
distanceInitial forward offset (legacy).
yawInitial horizontal rotation.
pitchInitial vertical rotation.
Here is the call graph for this function:

◆ camera_process_mouse()

void camera_process_mouse ( Camera cam,
float  xoffset,
float  yoffset 
)

Processes mouse movement to update target orientation.

Parameters
camPointer to the camera instance.
xoffsetRelative horizontal mouse movement.
yoffsetRelative vertical mouse movement.

◆ camera_process_scroll()

void camera_process_scroll ( Camera cam,
float  yoffset 
)

Processes mouse scroll events to apply physical impulse.

Parameters
camPointer to the camera instance.
yoffsetScroll amount along the y-axis.

◆ camera_update_vectors()

void camera_update_vectors ( Camera cam)

Recalculates front, right, and up vectors from yaw and pitch.

Parameters
camPointer to the camera instance.
Note
Updates cam->front, cam->right, and cam->up.