started implementing intersection functions and the main renderer data
[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 p, r;
21 };
22
23 struct bvhnode {
24         struct aabox aabb;
25
26         struct triangle **faces;
27         int num_faces, max_faces;
28
29         struct bvhnode *sub;
30         int num_sub;
31 };
32
33 struct rayhit {
34         float t;
35         struct vertex v;
36         cgm_ray ray;
37         struct material *mtl;
38 };
39
40 int ray_triangle(cgm_ray *ray, struct triangle *tri, float tmax, struct rayhit *hit);
41 int ray_aabox_any(cgm_ray *ray, struct aabox *box, float tmax);
42 int ray_bvhnode(cgm_ray *ray, struct bvhnode *bn, float tmax, struct rayhit *hit);
43
44 #endif  /* GEOM_H_ */