fixed missing last tile, and changed bvh node to binary
[cyberay] / src / geom.h
1 #ifndef GEOM_H_
2 #define GEOM_H_
3
4 #include <cgmath/cgmath.h>
5 #include "rt.h"
6
7 struct vertex {
8         cgm_vec3 pos;
9         cgm_vec3 norm;
10         cgm_vec2 tex;
11 };
12
13 struct triangle {
14         struct vertex v[3];
15         cgm_vec3 norm;
16         struct material *mtl;
17 };
18
19 struct aabox {
20         cgm_vec3 vmin, vmax;
21 };
22
23 struct bvhnode {
24         struct aabox aabb;
25
26         struct triangle *faces;
27         int num_faces;
28
29         struct bvhnode *left, *right;
30 };
31
32 struct rayhit {
33         float t;
34         struct vertex v;
35         cgm_ray ray;
36         struct material *mtl;
37 };
38
39 void free_bvh_tree(struct bvhnode *tree);
40
41 int ray_triangle(cgm_ray *ray, struct triangle *tri, float tmax, struct rayhit *hit);
42 int ray_aabox_any(cgm_ray *ray, struct aabox *box, float tmax);
43 int ray_bvhnode(cgm_ray *ray, struct bvhnode *bn, float tmax, struct rayhit *hit);
44
45 #endif  /* GEOM_H_ */