/* * ============================================================ * FILE: physics.h * * PURPOSE: Public interface for generic physical motion: a `Body` that * falls, moves, lands on floors, slides along walls and bumps its * head on ceilings. It knows nothing about players or controllers, * so enemies and objects can reuse it later. * * FITS IN: player.c owns a Body, sets its horizontal velocity from input, * then calls physics_step() once per tick. physics.c asks world.h * about floors, ceilings, overlapping boxes and the bounds. * * INTERFACE: Use these exact names: * * typedef struct Body { * Vec3 pos; position of the body's FEET (bottom center), meters * Vec3 vel; velocity, meters/second * bool on_ground; true if the body ended the last step standing on * something (the ground or a platform top) * float half_width; collision box half-size in x and z, meters * float height; collision box height above the feet, meters * } Body; * * void physics_step(Body *b, float dt); * * Include and "math3d.h". * * CONVENTIONS: Include guard: PHYSICS_H. The collision shape is an axis-aligned * box that does not rotate (a spinning box would snag on walls). * * NOT IN SCOPE: Rigid bodies, rotation, mass, forces/impulses API, collision * between bodies. * * DONE WHEN: player.c can move, land, and collide using only Body + physics_step. * ============================================================ */ #ifndef PHYSICS_H #define PHYSICS_H #include #include "math3d.h" typedef struct Body { Vec3 pos; /* position of the body's FEET (bottom center), meters */ Vec3 vel; /* velocity, meters/second */ bool on_ground; /* true if the body ended the last step standing on something */ float half_width; /* collision box half-size in x and z, meters */ float height; /* collision box height above the feet, meters */ } Body; void physics_step(Body *b, float dt); #endif /* PHYSICS_H */