Banjo API 1.0.0-rc.2
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
117 bj_real m1,
118 bj_real m2,
119 bj_real r,
120 bj_real g
121) {
122 return g * (m1 * m2) / (r * r);
123}
124
139 bj_real m1,
140 bj_real m2,
141 bj_real r,
142 bj_real g,
143 bj_real eps
144) {
145 const bj_real r2 = r * r;
146 const bj_real e2 = eps * eps;
147 const bj_real denom = bj_pow(r2 + e2, BJ_F(1.5));
148 return (denom > BJ_FZERO) ? (g * m1 * m2 * r) / denom : BJ_FZERO;
149}
150
151
153
154#endif
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
Definition api.h:241
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:89
#define bj_pow
Power.
Definition math.h:244
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:78
float bj_real
Selected real type for float configuration.
Definition math.h:76
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:116
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:138
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.