summaryrefslogtreecommitdiff
path: root/platformer/src/camera.h
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2026-09-24 00:06:00 -0400
committerSchark <jordan@schark.online>2026-09-24 00:06:00 -0400
commit5d078ec17b27afd159f8b9a8c1298fcac15d695d (patch)
tree59c2d29d64933e849f17bb50d34ea71b88c13602 /platformer/src/camera.h
parent23ef8bc20310bdfad52b07a3f1e4e61c98896841 (diff)
downloadgamedev-5d078ec17b27afd159f8b9a8c1298fcac15d695d.tar.gz
gamedev-5d078ec17b27afd159f8b9a8c1298fcac15d695d.zip
Fix recentering, default button
Diffstat (limited to '')
-rw-r--r--platformer/src/camera.h57
1 files changed, 39 insertions, 18 deletions
diff --git a/platformer/src/camera.h b/platformer/src/camera.h
index cdceaec..84897d7 100644
--- a/platformer/src/camera.h
+++ b/platformer/src/camera.h
@@ -2,9 +2,10 @@
* ============================================================
* FILE: camera.h
*
- * PURPOSE: Public interface for the third-person orbit camera: it sits
- * on a sphere around the player and the right stick moves it
- * around that sphere.
+ * PURPOSE: Public interface for the third-person "framing" camera: it
+ * orbits the player (right stick), and instead of pinning the player
+ * to the center of the screen it lets them wander inside a screen-
+ * space zone, SM64-style. Off-center framing is intentional.
*
* FITS IN: main.c calls camera_update() each tick AFTER player_update().
* player_update() receives camera_yaw() so "stick up" means "away
@@ -13,17 +14,29 @@
* INTERFACE: Use these exact names:
*
* typedef struct Camera {
- * Vec3 target; the smoothed point we look at (near the player)
- * float yaw; orbit angle around the target, radians
- * float pitch; angle above horizontal, radians
- * float distance; meters from target
- * Vec3 position; derived eye position (recomputed in camera_update)
+ * Vec3 target; derived look-at point, `distance` ahead of the eye
+ * float yaw; orbit angle around the player, radians
+ * float pitch; angle above horizontal, radians
+ * float distance; resting distance from eye to player, meters
+ * Vec3 position; derived eye position (recomputed in camera_update)
+ * Vec2 framing; where the player sits on screen, in NDC:
+ * (0,0) = center, +x = right, +y = up, edges = +-1
+ * float depth; current eye-to-player distance along the view
+ * direction; eases toward `distance` (follow lag)
+ * Vec3 subject; the point we frame (player feet + target height)
+ * as of last tick, to detect whether they moved
+ * bool recentering; true during the recenter glide
+ * float recenter_yaw; where the glide is headed: behind the player
* } Camera;
*
* void camera_init(Camera *c, Vec3 follow_point);
- * void camera_update(Camera *c, const Input *in, Vec3 follow_point, float dt);
+ * void camera_update(Camera *c, const Input *in, Vec3 follow_point,
+ * float follow_facing, float aspect, float dt);
* follow_point = the player's feet position; the camera adds
- * CAMERA_TARGET_HEIGHT itself.
+ * CAMERA_TARGET_HEIGHT itself. follow_facing = the player's
+ * facing_yaw, used by recenter to swing behind them. aspect =
+ * framebuffer width/height, needed because the framing zone is
+ * defined in screen space.
* float camera_yaw(const Camera *c);
* Mat4 camera_view(const Camera *c);
* Mat4 camera_projection(const Camera *c, float aspect);
@@ -36,12 +49,12 @@
* forward (toward target) = (-sin(yaw), 0, -cos(yaw))
* right = ( cos(yaw), 0, -sin(yaw))
*
- * Include "math3d.h" and "controls.h".
+ * Include <stdbool.h>, "math3d.h" and "controls.h".
*
* CONVENTIONS: Include guard: CAMERA_H.
*
* NOT IN SCOPE: Collision with geometry, automatic "behind the player"
- * recentering, cutscene/fixed cameras, zoom levels.
+ * rotation, cutscene/fixed cameras, zoom levels.
*
* DONE WHEN: player.c and render.c can be written against this header alone.
* ============================================================
@@ -49,19 +62,27 @@
#ifndef CAMERA_H
#define CAMERA_H
+#include <stdbool.h>
+
#include "controls.h"
#include "math3d.h"
typedef struct Camera {
- Vec3 target; /* the smoothed point we look at (near the player) */
- float yaw; /* orbit angle around the target, radians */
- float pitch; /* angle above horizontal, radians */
- float distance; /* meters from target */
- Vec3 position; /* derived eye position (recomputed in camera_update) */
+ Vec3 target; /* derived look-at point, `distance` ahead of the eye */
+ float yaw; /* orbit angle around the player, radians */
+ float pitch; /* angle above horizontal, radians */
+ float distance; /* resting distance from eye to player, meters */
+ Vec3 position; /* derived eye position (recomputed in camera_update) */
+ Vec2 framing; /* player's screen position in NDC: (0,0) = center, edges = +-1 */
+ float depth; /* current eye-to-player distance along the view; eases to `distance` */
+ Vec3 subject; /* last tick's framed point (feet + target height) */
+ bool recentering; /* gliding to "centered, behind the player" */
+ float recenter_yaw; /* the yaw that glide is headed for */
} Camera;
void camera_init(Camera *c, Vec3 follow_point);
-void camera_update(Camera *c, const Input *in, Vec3 follow_point, float dt);
+void camera_update(Camera *c, const Input *in, Vec3 follow_point, float follow_facing,
+ float aspect, float dt);
float camera_yaw(const Camera *c);
Mat4 camera_view(const Camera *c);
Mat4 camera_projection(const Camera *c, float aspect);