DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
bih.h
Go to the documentation of this file.
1
2// This code written in 2010 by Ashley Rose Hale (LadyHavoc) (darkplacesengine gmail com), and placed into public domain.
3
4// Based on information in http://zach.in.tu-clausthal.de/papers/vrst02.html (in particular vrst02_boxtree.pdf)
5
6#ifndef BIH_H
7#define BIH_H
8
9#define BIH_MAXUNORDEREDCHILDREN 8
10
11typedef enum biherror_e
12{
13 BIHERROR_OK, // no error, be happy
14 BIHERROR_OUT_OF_NODES // could not produce complete hierarchy, maxnodes too low (should be roughly half of numleafs)
17
18typedef enum bih_nodetype_e
19{
24}
26
27typedef enum bih_leaftype_e
28{
34
35typedef struct bih_node_s
36{
37 bih_nodetype_t type; // = BIH_SPLITX and similar values
38 // TODO: store just one float for distance, and have BIH_SPLITMINX and BIH_SPLITMAXX distinctions, to reduce memory footprint and traversal time, as described in the paper (vrst02_boxtree.pdf)
39 // TODO: move bounds data to parent node and remove it from leafs?
40 float mins[3];
41 float maxs[3];
42 union {
43 struct{
44 // node indexes of children (always > this node's index)
45 int front;
46 int back;
47 // interval of children
48 float frontmin; // children[0]
49 float backmax; // children[1]
50 };
51 // BIH_UNORDERED uses this for a list of leafindex (all >= 0), -1 = end of list
53 };
54}
56
57typedef struct bih_leaf_s
58{
59 bih_leaftype_t type; // = BIH_BRUSH And similar values
60 float mins[3];
61 float maxs[3];
62 // data past this point is generic and entirely up to the caller...
65 int itemindex; // triangle or brush index
66}
68
69typedef struct bih_s
70{
71 // permanent fields
72 // leafs are constructed by caller before calling BIH_Build
75 // nodes are constructed by BIH_Build
78 int rootnode; // 0 if numnodes > 0, -1 otherwise
79 // bounds calculated by BIH_Build
80 float mins[3];
81 float maxs[3];
82
83 // fields used only during BIH_Build:
85 int error; // set to a value if an error occurs in building (such as numnodes == maxnodes)
88}
89bih_t;
90
91int BIH_Build(bih_t *bih, int numleafs, bih_leaf_t *leafs, int maxnodes, bih_node_t *nodes, int *temp_leafsort, int *temp_leafsortscratch);
92
93int BIH_GetTriangleListForBox(const bih_t *bih, int maxtriangles, int *trianglelist_idx, int *trianglelist_surf, const float *mins, const float *maxs);
94
95#endif
bih_leaftype_t
Definition bih.h:28
@ BIH_COLLISIONTRIANGLE
Definition bih.h:30
@ BIH_RENDERTRIANGLE
Definition bih.h:31
@ BIH_BRUSH
Definition bih.h:29
biherror_t
Definition bih.h:12
@ BIHERROR_OUT_OF_NODES
Definition bih.h:14
@ BIHERROR_OK
Definition bih.h:13
int BIH_GetTriangleListForBox(const bih_t *bih, int maxtriangles, int *trianglelist_idx, int *trianglelist_surf, const float *mins, const float *maxs)
Definition bih.c:211
#define BIH_MAXUNORDEREDCHILDREN
Definition bih.h:9
int BIH_Build(bih_t *bih, int numleafs, bih_leaf_t *leafs, int maxnodes, bih_node_t *nodes, int *temp_leafsort, int *temp_leafsortscratch)
Definition bih.c:133
bih_nodetype_t
Definition bih.h:19
@ BIH_SPLITZ
Definition bih.h:22
@ BIH_UNORDERED
Definition bih.h:23
@ BIH_SPLITY
Definition bih.h:21
@ BIH_SPLITX
Definition bih.h:20
vector mins
vector maxs
int textureindex
Definition bih.h:63
bih_leaftype_t type
Definition bih.h:59
int surfaceindex
Definition bih.h:64
int itemindex
Definition bih.h:65
float backmax
Definition bih.h:49
int front
Definition bih.h:45
bih_nodetype_t type
Definition bih.h:37
int back
Definition bih.h:46
float frontmin
Definition bih.h:48
Definition bih.h:70
bih_node_t * nodes
Definition bih.h:77
int maxnodes
Definition bih.h:84
bih_leaf_t * leafs
Definition bih.h:74
int error
Definition bih.h:85
int numnodes
Definition bih.h:76
int * leafsortscratch
Definition bih.h:87
int rootnode
Definition bih.h:78
int numleafs
Definition bih.h:73
int * leafsort
Definition bih.h:86