1 struct BIHNode
2 {
3     short split[2];
4     ushort child[2];
5 
axisBIHNode6     int axis() const { return child[0]>>14; }
childindexBIHNode7     int childindex(int which) const { return child[which]&0x3FFF; }
isleafBIHNode8     bool isleaf(int which) const { return (child[1]&(1<<(14+which)))!=0; }
9 };
10 
11 struct BIH
12 {
13     struct tri : triangle
14     {
15         float tc[6];
16         Texture *tex;
17     };
18 
19     int maxdepth;
20     int numnodes;
21     BIHNode *nodes;
22     int numtris;
23     tri *tris, *noclip;
24 
25     vec bbmin, bbmax;
26 
27     BIH(vector<tri> *tris);
28 
~BIHBIH29     ~BIH()
30     {
31         DELETEA(nodes);
32         DELETEA(tris);
33     }
34 
35     static bool triintersect(tri &t, const vec &o, const vec &ray, float maxdist, float &dist, int mode, tri *noclip);
36 
37     void build(vector<BIHNode> &buildnodes, ushort *indices, int numindices, int depth = 1);
38 
39     bool traverse(const vec &o, const vec &ray, float maxdist, float &dist, int mode);
40 };
41 
42 extern bool mmintersect(const extentity &e, const vec &o, const vec &ray, float maxdist, int mode, float &dist);
43 
44