|
Banjo API 1.0.0-rc.2
Low-level C99 game development API
|
Topics | |
| 2D Physics | |
Macros | |
| #define | BJ_GRAVITATIONAL_CONSTANT_SI BJ_F(6.67430e-11) |
Functions | |
| static bj_real | bj_galileo_position (bj_real position, bj_real velocity, bj_real acceleration, bj_real time) |
| static bj_real | bj_galileo_velocity (bj_real velocity, bj_real acceleration, bj_real time) |
| static bj_real | bj_newton_gravitation (bj_real m1, bj_real m2, bj_real r, bj_real g) |
| static bj_real | bj_newton_plummer_gravitation (bj_real m1, bj_real m2, bj_real r, bj_real g, bj_real eps) |
Building blocks for simulating motion and forces.
This header (and its 2D sibling 2D Physics) gives you the usual physics building blocks: compute where a thing is after some time given its initial position, velocity, and acceleration; sum forces and integrate them into velocity and position; that sort of thing. None of it is full-featured "physics engine" stuff: no rigid bodies in contact, no collision response. They're the basic formulas, packaged so you don't have to write them yourself.
By default, the helpers think in SI units: metres for distance, seconds for time. So if you pass a velocity of 5, it means 5 metres per second.
You don't have to use SI though. The formulas are dimensionally consistent: as long as every input you pass to one formula uses the same unit system (so positions, velocities, and times all match), the outputs come out in those same units. If you'd rather think in pixels and frames, go ahead. Banjo won't mind.
The unit-system annotations on each function ([L], [L T^-1], [L T^-2], [T]) are dimensional shorthand:
These annotations are documentation, not type-checking: they just remind you which inputs to a formula should agree.
| #define BJ_GRAVITATIONAL_CONSTANT_SI BJ_F(6.67430e-11) |
|
inlinestatic |
Galileo’s uniformly accelerated motion: position at time t.
Uses: x(t) = x0 + v0 * t + 0.5 * a * t^2
| position | Initial position [L] |
| velocity | Initial velocity [L T^-1] |
| acceleration | Constant acceleration [L T^-2] |
| time | Elapsed time [T] |
|
inlinestatic |
Newtonian gravitation with Plummer softening: force magnitude.
||F|| = G * m1 * m2 * r / (r^2 + eps^2)^(3/2)
| m1 | Mass of first body [M] |
| m2 | Mass of second body [M] |
| r | Separation distance [L] |
| g | Gravitational constant G [L^3 M^-1 T^-2] |
| eps | Softening length ε [L] |