EAGL.Examples.LearnOpenGL.GettingStarted.CameraExercise1 (eagl v0.8.0)
View SourceLearnOpenGL 7.5 - Camera Exercise 1: True FPS Camera
This exercise implements a true FPS (First-Person Shooter) camera where the player cannot fly and is constrained to the XZ plane. This addresses some of the camera control issues from previous examples and provides a more natural ground-based navigation experience.
Original Exercise Context
This corresponds to the LearnOpenGL Camera Exercise 1 which challenges developers to:
"Transform the camera class in such a way that it becomes a true fps camera where
you cannot fly; you can only look around while staying on the xz
plane."
FPS Camera Constraints
Movement Restrictions
- Y-Position Locked: Camera Y-position remains constant (cannot fly up/down)
- Ground-Based Movement: All movement is constrained to the XZ plane
- Horizontal Strafe: Left/right movement follows camera orientation but stays level
- Forward/Backward: Movement follows camera's horizontal direction only
Look Controls
- Horizontal Look: Full 360° horizontal rotation (yaw)
- Vertical Look: Pitch is still functional for looking up/down
- Pitch Constraints: Maintains ±89° pitch limits to prevent camera flipping
Technical Implementation
Movement Processing
# Standard camera movement (7.4)
camera = Camera.process_keyboard(camera, :forward, delta_time) # Can move up/down
# FPS constrained movement (7.5)
camera = process_fps_movement(camera, :forward, delta_time) # Y locked
Key Differences from 7.4
- Y-Position Preservation: Forward/backward movement doesn't change Y coordinate
- Horizontal Strafe: Side movement is calculated in XZ plane only
- Ground Alignment: Camera feels more like walking than flying
Controls
- W/A/S/D: Move forward/left/backward/right (ground-based)
- Mouse Movement: Look around (first-person view, pitch/yaw)
- Scroll Wheel: Zoom in/out (field of view)
- ENTER: Exit (when run with enter_to_exit: true)
Educational Value
This exercise demonstrates:
- Constraint Application: How to apply movement restrictions to existing camera systems
- Vector Manipulation: Working with horizontal-only movement vectors
- Game Design: Understanding the difference between "fly" camera and "FPS" camera
- Y-Axis Control: Maintaining consistent ground level in 3D navigation
Comparison: Flying vs FPS Camera
Flying Camera (7.4):
- Can move in all directions (X, Y, Z)
- Forward movement follows exact camera direction
- Suitable for free-form 3D navigation
FPS Camera (7.5):
- Movement constrained to ground plane (XZ only)
- Forward movement ignores vertical camera angle
- More natural for ground-based games
This exercise bridges the gap between abstract 3D navigation and practical game camera systems.