50784a4bcc0281252dafa93fa43357d3ab1a5688
[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 *next;
30         struct bvhnode *sub;
31         int num_sub;
32 };
33
34 struct rayhit {
35         float t;
36         struct vertex v;
37         cgm_ray ray;
38         struct material *mtl;
39 };
40
41 void free_bvh_tree(struct bvhnode *tree);
42
43 int ray_triangle(cgm_ray *ray, struct triangle *tri, float tmax, struct rayhit *hit);
44 int ray_aabox_any(cgm_ray *ray, struct aabox *box, float tmax);
45 int ray_bvhnode(cgm_ray *ray, struct bvhnode *bn, float tmax, struct rayhit *hit);
46
47 #endif  /* GEOM_H_ */