removed clang-format and clang_complete files from the repo
[dosdemo] / src / scr / rt.h
1 #ifndef RT_H_
2 #define RT_H_
3
4 #include "image.h"
5 #include "cgmath/cgmath.h"
6
7 struct rtmaterial {
8         cgm_vec3 kd, ks;
9         float shin;
10         struct image *tex;
11 };
12
13 enum rt_obj_type { RT_SPH, RT_PLANE };
14
15 #define OBJ_COMMON      \
16         enum rt_obj_type type; \
17         struct rtmaterial mtl
18
19 struct rtany {
20         OBJ_COMMON;
21 };
22
23 struct rtsphere {
24         OBJ_COMMON;
25         cgm_vec3 p;
26         float r;
27 };
28
29 struct rtplane {
30         OBJ_COMMON;
31         cgm_vec3 n;
32         float d;
33 };
34
35 union rtobject {
36         enum rt_obj_type type;
37         struct rtany x;
38         struct rtsphere s;
39         struct rtplane p;
40 };
41
42 struct rtlight {
43         cgm_vec3 p, color;
44 };
45
46 struct rayhit {
47         float t;
48         cgm_vec3 p, n;
49         float u, v;
50         cgm_ray *ray;
51         union rtobject *obj;
52 };
53
54 struct rtscene {
55         union rtobject **obj;
56         int num_obj;
57         struct rtlight **lt;
58         int num_lt;
59 };
60
61 /* scene management */
62 void rt_init(struct rtscene *scn);
63 void rt_destroy(struct rtscene *scn);
64
65 void rt_color(float r, float g, float b);
66 void rt_specular(float r, float g, float b);
67 void rt_shininess(float s);
68
69 union rtobject *rt_add_sphere(struct rtscene *scn, float x, float y, float z, float r);
70 union rtobject *rt_add_plane(struct rtscene *scn, float nx, float ny, float nz, float d);
71 struct rtlight *rt_add_light(struct rtscene *scn, float x, float y, float z);
72
73 /* returns 0 for no hit */
74 int ray_trace(cgm_ray *ray, struct rtscene *scn, int lvl, cgm_vec3 *color);
75
76 int ray_object(cgm_ray *ray, union rtobject *obj, float maxt, struct rayhit *hit);
77 int ray_scene(cgm_ray *ray, struct rtscene *scn, float maxt, struct rayhit *hit);
78 int ray_sphere(cgm_ray *ray, struct rtsphere *sph, float maxt, struct rayhit *hit);
79 int ray_plane(cgm_ray *ray, struct rtplane *plane, float maxt, struct rayhit *hit);
80
81 #endif  /* RT_H_ */