Banjo API 1.1.0-alpha
Low-level C99 game development API
Loading...
Searching...
No Matches
physics.h
Go to the documentation of this file.
1#ifndef BJ_PHYSICS_H
2#define BJ_PHYSICS_H
3
4#include <banjo/math.h>
5#include <banjo/vec.h>
6
49
59#define BJ_GRAVITATIONAL_CONSTANT_SI BJ_F(6.67430e-11)
60
61
76 bj_real position,
77 bj_real velocity,
78 bj_real acceleration,
79 bj_real time
80) {
81 return BJ_F(0.5) * acceleration * time * time + velocity * time + position;
82}
83
97 bj_real velocity,
98 bj_real acceleration,
99 bj_real time
100) {
101 return acceleration * time + velocity;
102}
103
121 bj_real m1,
122 bj_real m2,
123 bj_real r,
124 bj_real g
125) {
126 return g * (m1 * m2) / (r * r);
127}
128
143 bj_real m1,
144 bj_real m2,
145 bj_real r,
146 bj_real g,
147 bj_real eps
148) {
149 const bj_real r2 = r * r;
150 const bj_real e2 = eps * eps;
151 const bj_real denom = bj_pow(r2 + e2, BJ_F(1.5));
152 return (denom > BJ_FZERO) ? (g * m1 * m2 * r) / denom : BJ_FZERO;
153}
154
155
157
158#endif
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
Definition api.h:248
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:93
#define bj_pow
Power.
Definition math.h:248
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:82
float bj_real
Selected real type for float configuration.
Definition math.h:80
static bj_real bj_newton_gravitation(bj_real m1, bj_real m2, bj_real r, bj_real g)
Newton’s law of universal gravitation: force magnitude.
Definition physics.h:120
static bj_real bj_newton_plummer_gravitation(bj_real m1, bj_real m2, bj_real r, bj_real g, bj_real eps)
Newtonian gravitation with Plummer softening: force magnitude.
Definition physics.h:142
static bj_real bj_galileo_velocity(bj_real velocity, bj_real acceleration, bj_real time)
Galileo’s uniformly accelerated motion: velocity at time t.
Definition physics.h:96
static bj_real bj_galileo_position(bj_real position, bj_real velocity, bj_real acceleration, bj_real time)
Galileo’s uniformly accelerated motion: position at time t.
Definition physics.h:75
C99 math shim with bj_real precision type and scalar utilities.
Fixed-size vector types (2D, 3D, 4D) and inline operations.