-
Notifications
You must be signed in to change notification settings - Fork 1
/
physics.h
51 lines (40 loc) · 1.15 KB
/
physics.h
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
#ifndef _PHYSICS_H_
#define _PHYSICS_H_
#include "linear.h"
enum solid_type {
SOLID_TYPE_CUBE,
SOLID_TYPE_CYLINDER,
SOLID_TYPE_MAX
};
#define SOLID_MAX_PARAMS 5
#define SOLID_DENSITY_DEFAULT (1.0 / (0.1 * 0.1 * 0.1)) /* 1Kg/dm3 */
struct solid {
enum solid_type type;
mat4 t_abs; /* matrix transformation to absolute/model coordinates */
vec3 cm_abs; /* center of mass, absolute/model coordinates */
float density;
float volume;
float mass;
mat3 inertia; /* inertia matrix, relative coordinates */
vec3 cm; /* center of mass, relative coordinates */
union {
struct {
float dx;
float dy;
float dz;
} cube;
float params[SOLID_MAX_PARAMS];
};
};
struct solid_type_properties {
void (*mass)(struct solid *s);
void (*volume)(struct solid *s);
void (*center_of_mass)(struct solid *s);
void (*inertia_matrix)(struct solid *s);
};
void solid_volume(struct solid *s);
void solid_mass(struct solid *s);
void solid_center_of_mass_abs(struct solid *s, vec3 *cm);
void solid_inertia_matrix_abs(struct solid *s, vec3 *p, mat3 *inertia);
void solid_init(struct solid *s, enum solid_type type, float density, float params[]);
#endif /* _PHYSICS_H_ */