diff options
Diffstat (limited to 'platformer/src/camera.c')
| -rw-r--r-- | platformer/src/camera.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/platformer/src/camera.c b/platformer/src/camera.c new file mode 100644 index 0000000..00f8d4a --- /dev/null +++ b/platformer/src/camera.c @@ -0,0 +1,51 @@ +/* + * ============================================================ + * FILE: camera.c + * + * PURPOSE: A player-controlled third-person orbit camera, in the spirit of + * SM64's "Lakitu" camera but much simpler. A good camera matters as + * much for movement feel as the movement code itself. + * + * FITS IN: Implements camera.h. Reads Input.look (controls.h) and the + * player's position (passed in by main.c). Produces matrices for + * render.c and a yaw for player.c. + * + * IMPLEMENT: + * - camera_init(c, follow_point): + * target = follow_point + (0, CAMERA_TARGET_HEIGHT, 0) (snap, no smoothing) + * yaw = 0 (camera sits on +Z looking toward -Z) + * pitch = CAMERA_PITCH_DEFAULT + * distance = CAMERA_DISTANCE + * compute position. + * + * - camera_update(c, in, follow_point, dt): + * 1. Orbit: yaw += in->look.x * CAMERA_YAW_SPEED * dt + * pitch += in->look.y * CAMERA_PITCH_SPEED * dt + * Clamp pitch to [CAMERA_PITCH_MIN, CAMERA_PITCH_MAX], wrap yaw with + * wrap_angle(). Check the sign by feel: pushing the right stick RIGHT + * should swing the camera so the view turns right (the camera moves + * left around the player). Flip the sign if it feels backwards and + * leave a comment. + * 2. Follow: move target toward (follow_point + target height) with + * frame-rate-independent exponential smoothing: + * t = 1 - expf(-CAMERA_FOLLOW_RATE * dt) + * target = vec3_lerp(target, desired, t) + * Comment WHY: a camera that snaps rigidly to the player looks jittery, + * and a little lag lets you see the motion. + * 3. Recompute position with the YAW CONVENTION in camera.h. + * + * - camera_yaw(): return c->yaw. + * - camera_view(): mat4_look_at(position, target, (0,1,0)). + * - camera_projection(c, aspect): mat4_perspective(CAMERA_FOV_DEG converted to + * radians, aspect, CAMERA_NEAR, CAMERA_FAR). + * + * CONVENTIONS: Radians internally; FOV converted once from degrees. + * + * NOT IN SCOPE: Camera collision, auto-recenter, shake, look-ahead. + * (Good candidates for later tuning, not for now.) + * + * DONE WHEN: The right stick orbits smoothly all the way around the player, + * pitch stops at its limits, and the camera trails the running + * player slightly without jitter. + * ============================================================ + */ |
