2 #include "image.h" |
2 #include "image.h" |
3 |
3 |
4 int main() |
4 int main() |
5 { |
5 { |
6 Raytracer rt; |
6 Raytracer rt; |
7 rt.setThreads(1); |
7 rt.setThreads(2); |
|
8 |
|
9 KdTree top; |
|
10 rt.setTop(&top); |
8 |
11 |
9 Light light1(Vector3(0.0, 5.0, -5.0), Colour(0.7, 0.3, 0.6)); |
12 Light light1(Vector3(0.0, 5.0, -5.0), Colour(0.7, 0.3, 0.6)); |
10 rt.addlight(&light1); |
13 rt.addlight(&light1); |
11 |
14 |
12 Light light2(Vector3(-2.0, 10.0, -2.0), Colour(0.4, 0.6, 0.3)); |
15 Light light2(Vector3(-2.0, 10.0, -2.0), Colour(0.4, 0.6, 0.3)); |
27 |
30 |
28 Material mat3(Colour(0.0, 0.0, 1.0)); |
31 Material mat3(Colour(0.0, 0.0, 1.0)); |
29 Sphere tinysphere(Vector3(-1.2, 0.0, -2.0), 0.5, &mat3); |
32 Sphere tinysphere(Vector3(-1.2, 0.0, -2.0), 0.5, &mat3); |
30 rt.addshape(&tinysphere); |
33 rt.addshape(&tinysphere); |
31 |
34 |
|
35 top.optimize(); |
|
36 |
32 Camera cam; |
37 Camera cam; |
33 cam.setEye(Vector3(0,0,15)); |
38 cam.setEye(Vector3(0,0,15)); |
34 rt.setCamera(&cam); |
39 rt.setCamera(&cam); |
35 |
40 |
36 int w = 800; |
41 int w = 800; |
37 int h = 600; |
42 int h = 600; |
38 float *fdata = (float *) malloc(w*h*3*sizeof(float)); |
43 Float *fdata = (Float *) malloc(w*h*3*sizeof(Float)); |
39 rt.render(w, h, fdata); |
44 rt.render(w, h, fdata); |
40 |
45 |
41 struct image *img; |
46 struct image *img; |
42 new_image(&img, w, h, 3); |
47 new_image(&img, w, h, 3); |
43 |
48 |
44 float *fd = fdata; |
49 Float *fd = fdata; |
45 for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { |
50 for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { |
46 if (*fd > 1.0) |
51 if (*fd > 1.0) |
47 *cd = 255; |
52 *cd = 255; |
48 else |
53 else |
49 *cd = (unsigned char)(*fd * 255.0); |
54 *cd = (unsigned char)(*fd * 255.0); |