first pass at bvh construction (SAH), untested
[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 rayhit {
24         float t;
25         struct vertex v;
26         cgm_ray ray;
27         struct material *mtl;
28 };
29
30 int ray_triangle(cgm_ray *ray, struct triangle *tri, float tmax, struct rayhit *hit);
31 int ray_aabox_any(cgm_ray *ray, struct aabox *box, float tmax);
32
33 void aabox_init(struct aabox *box);
34 void aabox_addface(struct aabox *box, struct triangle *tri);
35 void aabox_union(struct aabox *res, struct aabox *a, struct aabox *b);
36 float aabox_surf_area(struct aabox *box);
37 float surf_area(float dx, float dy, float dz);
38
39 #endif  /* GEOM_H_ */