|
1 #include "raytracer.h" |
|
2 #include "image.h" |
|
3 |
|
4 int main() |
|
5 { |
|
6 Raytracer rt; |
|
7 Light light1(Vector3(0.0, 5.0, 5.0), Colour(0.7, 0.3, 0.6)); |
|
8 rt.addlight(&light1); |
|
9 |
|
10 Light light2(Vector3(-2.0, 10.0, 2.0), Colour(0.4, 0.6, 0.3)); |
|
11 rt.addlight(&light2); |
|
12 |
|
13 Material mat0(Colour(0.7, 0.7, 0.7)); |
|
14 |
|
15 Box box(Vector3(-20.0, -1.2, -20.0), Vector3(20.0, -1.0, 20.0), &mat0); |
|
16 rt.addshape(&box); |
|
17 |
|
18 Material mat1(Colour(1.0, 0.0, 0.0)); |
|
19 Sphere bigsphere(Vector3(3.0, 2.0, 7.0), 3.0, &mat1); |
|
20 rt.addshape(&bigsphere); |
|
21 |
|
22 Material mat2(Colour(0.0, 1.0, 0.0)); |
|
23 Sphere smallsphere(Vector3(-5.5, 1.5, 8.0), 2.0, &mat2); |
|
24 rt.addshape(&smallsphere); |
|
25 |
|
26 Material mat3(Colour(0.0, 0.0, 1.0)); |
|
27 Sphere tinysphere(Vector3(-1.2, 0.0, 2.0), 0.5, &mat3); |
|
28 rt.addshape(&tinysphere); |
|
29 |
|
30 int w = 800; |
|
31 int h = 600; |
|
32 float *fdata = rt.render(w, h); |
|
33 |
|
34 struct image *img; |
|
35 new_image(&img, w, h, 3); |
|
36 |
|
37 float *fd = fdata; |
|
38 for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { |
|
39 if (*fd > 1.0) |
|
40 *cd = 255; |
|
41 else |
|
42 *cd = (unsigned char)(*fd * 255.0); |
|
43 } |
|
44 free(fdata); |
|
45 save_png("spheres_shadow.png", img); |
|
46 destroy_image(&img); |
|
47 } |