Banjo API 0.0.1
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
29
39#define BJ_GRAVITATIONAL_CONSTANT_SI BJ_F(6.67430e-11)
40
41
56 bj_real position,
57 bj_real velocity,
58 bj_real acceleration,
59 bj_real time
60) {
61 return BJ_F(0.5) * acceleration * time * time + velocity * time + position;
62}
63
77 bj_real velocity,
78 bj_real acceleration,
79 bj_real time
80) {
81 return acceleration * time + velocity;
82}
83
97 bj_real m1,
98 bj_real m2,
99 bj_real r,
100 bj_real g
101) {
102 return g * (m1 * m2) / (r * r);
103}
104
119 bj_real m1,
120 bj_real m2,
121 bj_real r,
122 bj_real g,
123 bj_real eps
124) {
125 const bj_real r2 = r * r;
126 const bj_real e2 = eps * eps;
127 const bj_real denom = bj_pow(r2 + e2, BJ_F(1.5));
128 return (denom > BJ_FZERO) ? (g * m1 * m2 * r) / denom : BJ_FZERO;
129}
130
131
133
134#endif
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
Definition api.h:260
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:64
#define bj_pow
Power.
Definition math.h:219
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:53
float bj_real
Selected real type for float configuration.
Definition math.h:51
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:96
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:118
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:76
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:55
C99 math shim with bj_real precision type and scalar utilities.
vector manipulation API