-
Notifications
You must be signed in to change notification settings - Fork 0
/
bhtree.h
57 lines (49 loc) · 1.12 KB
/
bhtree.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
52
53
54
55
56
57
#ifndef _BHTREE_H_
#define _BHTREE_H_
#include "physics.h"
#include <stddef.h>
typedef struct bhtree_node
{
char is_object;
double total_mass;
vec3d_t center_of_mass;
struct bhtree_node* fne;
struct bhtree_node* fnw;
struct bhtree_node* fsw;
struct bhtree_node* fse;
struct bhtree_node* bne;
struct bhtree_node* bnw;
struct bhtree_node* bsw;
struct bhtree_node* bse;
} bhtree_node_t;
typedef struct bhtree_object
{
char is_object;
union
{
struct
{
double total_mass;
vec3d_t center_of_mass;
vec3d_t velocity;
};
object_t obj;
};
} bhtree_object_t;
typedef struct
{
bhtree_node_t* root;
double root_size;
size_t count;
bhtree_node_t* container_pool;
bhtree_object_t* object_pool;
size_t cpool_used;
size_t opool_used;
} bhtree_t;
bhtree_t bhtree(size_t max_n, double initial_size);
bhtree_node_t* bhtree_push(bhtree_t* tree, object_t obj);
void bhtree_update_com(bhtree_t* tree);
void bhtree_free(bhtree_t* tree);
vec3d_t bhtree_calc_gravity_vector(bhtree_t* tree, bhtree_object_t* node, double threshold_angle);
void bhtree_time_step(bhtree_t* tree, double dt, double threshold_angle);
#endif