EAGL.Examples.LearnOpenGL.GettingStarted.CameraMouseZoom (eagl v0.7.0)

View Source

LearnOpenGL 7.3 - Camera (Mouse + Zoom)

This example demonstrates advanced camera control using mouse input for look around and scroll wheel for zoom control. The camera responds to mouse movement for controlling the look direction (yaw and pitch) and scroll wheel for field of view.

Original C++ Source

This example is based on the original LearnOpenGL C++ tutorial: https://github.com/JoeyDeVries/LearnOpenGL/tree/master/src/1.getting_started/7.3.camera_mouse_zoom

Framework Adaptation Notes

This example introduces advanced interactive camera control:

  • Mouse look around using yaw and pitch rotation
  • Scroll wheel zoom control via field of view adjustment
  • Mouse sensitivity configuration
  • Pitch constraints to prevent camera flipping
  • Smooth camera control with frame-rate independent movement

Controls

  • Mouse Movement: Look around (yaw and pitch)
  • Scroll Wheel: Zoom in/out (field of view)
  • ENTER: Exit (when run with enter_to_exit: true)

Mathematical Background

Mouse Look Implementation

  • Yaw: Horizontal rotation around the world Y-axis
  • Pitch: Vertical rotation around the camera's right vector
  • Constraints: Pitch clamped to [-89°, 89°] to prevent gimbal lock

Camera Front Vector Calculation

front.x = cos(yaw) * cos(pitch)
front.y = sin(pitch)
front.z = sin(yaw) * cos(pitch)

Field of View Zoom

  • Narrow FOV (< 45°) = zoomed in
  • Wide FOV (> 45°) = zoomed out
  • Clamped to [1°, 45°] for practical range

Known Limitations (Pedagogically Intentional)

This example uses a simplified mouse look implementation that may feel like "rotating the world coordinate system" rather than natural first-person camera control. This behavior is intentionally preserved from the original C++ tutorial to demonstrate basic mouse input concepts and their limitations.

These limitations motivate the need for better camera abstractions, which are addressed in LearnOpenGL 7.4 Camera Class. The progression from simple (7.3) to sophisticated (7.4) camera control is an important part of the learning journey.

If you're looking for natural first-person camera feel, continue to example 7.4.

Summary

Functions

run_example(opts \\ [])