First-person camera module with realistic physics and head-bobbing.
More...
#include <cglm/cglm.h>
#include <stdbool.h>
Go to the source code of this file.
|
| struct | Camera |
| | Represents a 3D camera with orientation, movement, and physical properties. More...
|
| |
First-person camera module with realistic physics and head-bobbing.
◆ DEFAULT_ACCELERATION
| #define DEFAULT_ACCELERATION 10.0F |
◆ DEFAULT_BOBBING_AMPLITUDE
| #define DEFAULT_BOBBING_AMPLITUDE 0.0004F |
◆ DEFAULT_BOBBING_FREQUENCY
| #define DEFAULT_BOBBING_FREQUENCY 2.2F |
◆ DEFAULT_BOBBING_RESET_SPEED
| #define DEFAULT_BOBBING_RESET_SPEED 0.95F |
◆ DEFAULT_CAMERA_SENSITIVITY
| #define DEFAULT_CAMERA_SENSITIVITY 0.15F |
◆ DEFAULT_CAMERA_SPEED
| #define DEFAULT_CAMERA_SPEED 15.0F |
◆ DEFAULT_CAMERA_ZOOM
| #define DEFAULT_CAMERA_ZOOM 60.0F |
◆ DEFAULT_FIXED_TIMESTEP
◆ DEFAULT_FRICTION
| #define DEFAULT_FRICTION 0.85F |
Velocity decay per frame.
◆ DEFAULT_MAX_ALPHA
| #define DEFAULT_MAX_ALPHA 1.0F |
◆ DEFAULT_MAX_PITCH
| #define DEFAULT_MAX_PITCH 89.0F |
◆ DEFAULT_MIN_PITCH
| #define DEFAULT_MIN_PITCH -89.0F |
◆ DEFAULT_MIN_VELOCITY
| #define DEFAULT_MIN_VELOCITY 0.01F |
◆ 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 |
◆ DEFAULT_ROTATION_SMOOTHING
| #define DEFAULT_ROTATION_SMOOTHING 0.18F |
◆ DEFAULT_SCROLL_SENSITIVITY
| #define DEFAULT_SCROLL_SENSITIVITY 50.0F |
◆ DEFAULT_TARGET_FPS
| #define DEFAULT_TARGET_FPS 60 |
Reference for fixed updates.
◆ DEFAULT_ZOOM_SPEED
| #define DEFAULT_ZOOM_SPEED 1.0F |
◆ camera_build_keyboard_input()
| void camera_build_keyboard_input |
( |
Camera * |
cam | ) |
|
Converts boolean keyboard flags into move_input.
Writes cam->move_input from cam->move_forward/backward/left/right/up/down. Values are binary (0 or ±1). Call before gamepad overlay and camera_fixed_update each physics step.
- Parameters
-
| cam | Pointer to the camera instance. |
◆ camera_fixed_update()
| void camera_fixed_update |
( |
Camera * |
cam | ) |
|
Performs one fixed-step physics update.
Reads move_input to build target_velocity, then applies momentum, friction, and head-bobbing. move_input must be set before calling (via camera_build_keyboard_input and/or gamepad overlay).
- Parameters
-
| cam | Pointer 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
-
| cam | Pointer to the camera instance. |
| [out] | view | Matrix to populate. |
◆ camera_init()
| void camera_init |
( |
Camera * |
cam, |
|
|
float |
distance, |
|
|
float |
yaw, |
|
|
float |
pitch |
|
) |
| |
Initializes the camera with default values.
- Parameters
-
| cam | Pointer to the camera instance. |
| distance | Initial forward offset (legacy). |
| yaw | Initial horizontal rotation. |
| pitch | Initial vertical rotation. |
◆ camera_process_mouse()
| void camera_process_mouse |
( |
Camera * |
cam, |
|
|
float |
xoffset, |
|
|
float |
yoffset |
|
) |
| |
Processes mouse movement to update target orientation.
- Parameters
-
| cam | Pointer to the camera instance. |
| xoffset | Relative horizontal mouse movement. |
| yoffset | Relative vertical mouse movement. |
◆ camera_process_scroll()
| void camera_process_scroll |
( |
Camera * |
cam, |
|
|
float |
yoffset |
|
) |
| |
Processes mouse scroll events to apply physical impulse.
- Parameters
-
| cam | Pointer to the camera instance. |
| yoffset | Scroll 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
-
| cam | Pointer to the camera instance. |
- Note
- Updates cam->front, cam->right, and cam->up.