gKit2 light
bvh.h
1 
2 #ifndef _BVH_H
3 #define BVH_H
4 
5 #include "vec.h"
6 #include "color.h"
7 #include "ray.h"
8 #include "bbox.h"
9 
11 struct Triangle
12 {
13  Triangle( ) : a(), b(), c() {}
14  Triangle( const Point& _a, const Point& _b, const Point& _c ) : a(_a), b(_b), c(_c) {}
15 
16  Point a;
17  Point b;
18  Point c;
19 };
20 
21 bool intersect( const Triangle& triangle, const Ray& ray, const float hitmax, float &t );
22 bool intersect( const BBox& box, const Ray& ray, const float hitmax, float &tmin, float& tmax );
23 
25 struct BVHNode
26 {
27  BVHNode( ) : left(nullptr), right(nullptr), triangle(nullptr), box() {}
28 
29  BVHNode *left;
30  BVHNode *right;
31  Triangle *triangle;
32  BBox box;
33 };
34 
35 BVHNode *create_node( const BBox& box, BVHNode *left, BVHNode *right );
36 BVHNode *create_leaf( const BBox& box, Point *triangle );
37 
39 struct BVH
40 {
41  BVH( ) : triangles(), root(nullptr), box() {}
42 
43  std::vector<Triangle> triangles;
44  BVHNode *root;
45  BBox box;
46 };
47 
48 BVH make_bvh( const std::vector<vec3>& positions );
49 
50 extern unsigned long int box_n;
51 extern unsigned long int tri_n;
52 
53 bool intersect( const BVH& bvh, const Ray& ray, const float tmax, Hit& hit );
54 
55 #endif
representation d'un triangle.
Definition: bvh.h:11
Definition: bbox.h:10
representation du bvh.
Definition: bvh.h:39
representation d'un point d'intersection.
Definition: ray.h:33
representation d'un rayon.
Definition: ray.h:12
representation d'un noeud du bvh.
Definition: bvh.h:25
representation d'un point 3d.
Definition: vec.h:19