Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
Physics
Collaboration diagram for Physics:

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)

Detailed Description

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.

What units do these functions use?

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:

  • L = length (metres, pixels, parsecs, whatever you've chosen).
  • T = time (seconds, frames, ticks).
  • [L T^-1] = length per time = a velocity.
  • [L T^-2] = length per time per time = an acceleration.

These annotations are documentation, not type-checking: they just remind you which inputs to a formula should agree.

Macro Definition Documentation

◆ BJ_GRAVITATIONAL_CONSTANT_SI

#define BJ_GRAVITATIONAL_CONSTANT_SI   BJ_F(6.67430e-11)

Newtonian constant of gravitation in SI units.

Defines the physical constant G = 6.67430 × 10⁻¹¹ m³·kg⁻¹·s⁻², expressed in the active bj_real precision type.

Note
Use only when working in SI units (meters, kilograms, seconds).

Definition at line 59 of file physics.h.

Function Documentation

◆ bj_galileo_position()

bj_real bj_galileo_position ( bj_real position,
bj_real velocity,
bj_real acceleration,
bj_real time )
inlinestatic

Galileo’s uniformly accelerated motion: position at time t.

Uses: x(t) = x0 + v0 * t + 0.5 * a * t^2

Parameters
positionInitial position [L]
velocityInitial velocity [L T^-1]
accelerationConstant acceleration [L T^-2]
timeElapsed time [T]
Returns
Position at time t, in [L].

Definition at line 75 of file physics.h.

◆ bj_galileo_velocity()

bj_real bj_galileo_velocity ( bj_real velocity,
bj_real acceleration,
bj_real time )
inlinestatic

Galileo’s uniformly accelerated motion: velocity at time t.

Uses: v(t) = v0 + a * t

Parameters
velocityInitial velocity [L T^-1]
accelerationConstant acceleration [L T^-2]
timeElapsed time [T]
Returns
Velocity at time t, in [L T^-1].

Definition at line 96 of file physics.h.

◆ bj_newton_gravitation()

bj_real bj_newton_gravitation ( bj_real m1,
bj_real m2,
bj_real r,
bj_real g )
inlinestatic

Newton’s law of universal gravitation: force magnitude.

F = G * m1 * m2 / r^2

Parameters
m1Mass of first body [M]
m2Mass of second body [M]
rSeparation distance [L]
gGravitational constant G [L^3 M^-1 T^-2]
Returns
Force magnitude [M L T^-2].

Definition at line 116 of file physics.h.

◆ bj_newton_plummer_gravitation()

bj_real bj_newton_plummer_gravitation ( bj_real m1,
bj_real m2,
bj_real r,
bj_real g,
bj_real eps )
inlinestatic

Newtonian gravitation with Plummer softening: force magnitude.

||F|| = G * m1 * m2 * r / (r^2 + eps^2)^(3/2)

Parameters
m1Mass of first body [M]
m2Mass of second body [M]
rSeparation distance [L]
gGravitational constant G [L^3 M^-1 T^-2]
epsSoftening length ε [L]
Returns
Softened force magnitude [M L T^-2].

Definition at line 138 of file physics.h.