1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#ifndef physics_hpp
#define physics_hpp
#include "asset.hpp"
#include "maths.hpp"
#include <tuple>
struct Arena;
struct Line_Renderer;
struct World;
struct Manifold {
static constexpr int max_contacts = 16;
v3f contacts[max_contacts];
int contact_count;
v3f normal;
};
struct Rigidbody;
struct Int_Collider {
Rigidbody* rb;
Int_Collider* next;
int vert_count;
int face_count;
v3f* verts;
v3f* faces;
bool collide(const Int_Collider& other) const;
};
struct Collider : Asset {
struct Face {
v3f normal;
int vert_count;
uint16_t* verts;
};
int face_count;
int vert_count;
Face* faces;
v3f* verts;
m3f moment;
void debug_render(
Line_Renderer& lr,
const m4f& t,
const v3f& c
);
Int_Collider* transform(const m4f& m, Arena* a) const;
};
struct Rigidbody {
v3f prev_pos, pos;
v3f vel, avel;
v3f force;
v3f torque;
v4f prev_rot, rot;
float inv_mass;
Collider* col;
int colliding;
void init(Collider* c, const v3f& p, const v4f& r, float mass);
void set_pos(const v3f& p);
void set_rot(const v4f& r);
void set_mass(float m);
void add_force(const v3f& f);
void add_force(const v3f& f, const v3f& p);
void add_impulse(const v3f& f);
void add_impulse(const v3f& f, const v3f& p);
void add_torque(const v3f& t);
};
Collider* make_box(Arena* a, const v3f& size);
void physics_update(World& w, Arena* a, float ts);
void physics_debug(World& w, Line_Renderer& lr);
#endif
|