Overview
ThePlayer class extends Entity to implement the player character with camera control, input handling, sprinting mechanics, dynamic FOV, and frustum culling.
Location: src/entity/player.h, src/entity/player.cpp
Class Structure
Speed Constants
The player has two movement speeds defined inplayer.cpp:9-10:
Sprint Mechanics
Input Handling
Sprinting is toggled viahandle_input_sprint() at player.cpp:25-37:
- Sprint activates when Ctrl + Forward are both pressed
- Sprint automatically stops when forward movement stops
- Target speed switches between
WALKING_SPEEDandSPRINTING_SPEED
Dynamic FOV
The FOV increases when sprinting to simulate speed. Implementation atplayer.cpp:15-23:
- Base FOV from
Options::FOV - +10 degrees maximum FOV increase at full sprint speed
- Linear interpolation based on current speed
- Speed smoothly transitions in
update(), creating a gradual FOV change
Movement Update
Theupdate() method at player.cpp:47-79 handles movement logic:
- Speed smoothly interpolates to
target_speedat 20x per second - Flying doubles movement speed
- Input vector (
input.x,input.z) is rotated by player’s yaw (rotation.x) - Jumping only works when grounded in normal mode
- Flying allows direct vertical control via
input.y
Camera & Matrices
Matrix Updates
Theupdate_matrices() method at player.cpp:81-102 handles view projection with interpolation:
- Position interpolation for smooth rendering between physics ticks
- Dynamic FOV based on current speed
- Eye level at
1.6blocks above feet (eyelevel = 1.6f) step_offsetsmooths camera movement when climbing stairs- Near plane:
0.1, Far plane:500.0
Frustum Culling
Thecheck_in_frustum() method at player.cpp:104-143 performs chunk visibility tests:
- Early reject chunks beyond render distance using squared distance
- Transform all 8 chunk corners to clip space via
vp_matrix - Count corners outside each frustum plane (left/right/top/bottom/near/far)
- Reject if all 8 corners are outside the same plane
- Otherwise, chunk is potentially visible
Health System
Simple health management atplayer.cpp:39-45:
- Default health:
10.0f(max and current) - Clamped between 0 and
max_health - Currently not visualized in UI
Initialization
Constructor atplayer.cpp:12-13:
- Eye level: 1.6 blocks (standard Minecraft height)
- Initial speed: 4.3 blocks/second
- Render distance: 0.1 to 500 blocks
- Full health at spawn
- Not sprinting by default