-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysics.h
More file actions
47 lines (35 loc) · 868 Bytes
/
physics.h
File metadata and controls
47 lines (35 loc) · 868 Bytes
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
#pragma once
#include <stddef.h>
#define MAX_BODIES 20
#define MAX_HANDLERS 10
struct Body {
float x, y;
float xvel, yvel;
float radius;
int type;
int collision_mask;
void *userdata;
};
typedef int (*CollisionCallback)(struct Body *a, struct Body *b, void *userdata);
struct CollisionHandler {
CollisionCallback callback;
int type_mask;
void *userdata;
};
struct SimulationSystem {
struct List *body_list;
struct CollisionHandler handlers[MAX_HANDLERS];
size_t handler_count;
};
struct SimulationSystem*
sim_new(void);
void
sim_destroy(struct SimulationSystem *sys);
int
sim_step(struct SimulationSystem *sys, float dt);
int
sim_add_body(struct SimulationSystem *sys, struct Body *body);
void
sim_remove_body(struct SimulationSystem *sys, struct Body *body);
int
sim_add_handler(struct SimulationSystem *sys, const struct CollisionHandler *c);