author | Radek Brich <radek.brich@devl.cz> |
Mon, 05 May 2008 15:31:14 +0200 | |
branch | pyrit |
changeset 92 | 9af5c039b678 |
parent 91 | 9d66d323c354 |
child 93 | 96d65f841791 |
permissions | -rw-r--r-- |
42 | 1 |
#include "raytracer.h" |
91 | 2 |
#include "kdtree.h" |
42 | 3 |
|
4 |
#include "common_sdl.h" |
|
5 |
||
91 | 6 |
Camera cam(Vector(0.,6.,6.), Vector(0.,2.,-7.), Vector(0.,0.,-1.)); |
7 |
Light light(Vector(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9)); |
|
42 | 8 |
|
9 |
Float lx, ly, lz, cf; |
|
10 |
||
81
9dbb9c8c115b
add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents:
79
diff
changeset
|
11 |
void update_callback(Float*) |
42 | 12 |
{ |
13 |
if (lx != 0.0) |
|
14 |
light.pos.x += lx; |
|
15 |
if (ly != 0.0) |
|
16 |
light.pos.y += ly; |
|
17 |
if (lz != 0.0) |
|
18 |
light.pos.z += lz; |
|
19 |
if (cf != 0.0) |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
20 |
cam.setF(cam.getF() + cf); |
42 | 21 |
} |
22 |
||
23 |
void key_callback(int key, int down) |
|
24 |
{ |
|
25 |
switch (key) |
|
26 |
{ |
|
27 |
case SDLK_r: |
|
28 |
lx = -0.1 * down; |
|
29 |
break; |
|
30 |
case SDLK_t: |
|
31 |
lx = +0.1 * down; |
|
32 |
break; |
|
33 |
case SDLK_f: |
|
34 |
ly = -0.1 * down; |
|
35 |
break; |
|
36 |
case SDLK_g: |
|
37 |
ly = +0.1 * down; |
|
38 |
break; |
|
39 |
case SDLK_v: |
|
40 |
lz = -0.1 * down; |
|
41 |
break; |
|
42 |
case SDLK_b: |
|
43 |
lz = +0.1 * down; |
|
44 |
break; |
|
45 |
||
46 |
case SDLK_z: |
|
47 |
cf = -0.02 * down; |
|
48 |
break; |
|
49 |
case SDLK_x: |
|
50 |
cf = +0.02 * down; |
|
51 |
break; |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
int main(int argc, char **argv) |
|
56 |
{ |
|
57 |
Raytracer rt; |
|
58 |
||
91 | 59 |
KdTree top; |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
60 |
rt.setCamera(&cam); |
42 | 61 |
rt.setTop(&top); |
62 |
||
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
63 |
rt.addLight(&light); |
42 | 64 |
light.castShadows(false); |
65 |
||
66 |
Material mat0a(Colour(0.7, 0.7, 0.7)); |
|
79
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
67 |
mat0a.setReflectivity(0.0); |
91 | 68 |
Box box(Vector(-12.0, -1.2, -20.0), Vector(12.0, -1.0, 0.0), &mat0a); |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
69 |
rt.addShape(&box); |
42 | 70 |
|
71 |
Material mat0b(Colour(0.1, 0.7, 0.8)); |
|
72 |
mat0b.setReflectivity(0.7); |
|
91 | 73 |
Box box2(Vector(-12.0, -1.2, -10.0), Vector(12.0, 10.0, -10.2), &mat0b); |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
74 |
rt.addShape(&box2); |
42 | 75 |
|
79
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
76 |
Float bounds[] = {0.3, 0.6, 1.1}; |
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
77 |
Colour colours[] = {Colour(0,0,0), Colour(1,1,1), Colour(0,0,0)}; |
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
78 |
BoundColourMap cmap(bounds, colours); |
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
79 |
|
42 | 80 |
// spheres |
81 |
Material mat1(Colour(1.0, 1.0, 1.0)); |
|
91 | 82 |
mat1.texture = new CheckersTexture(new PlanarMap(Vector(-4.5, 2.0, -7.0), 0.48), &cmap); |
83 |
Sphere sphere1(Vector(-4.5, 2.0, -7.0), 1.0, &mat1); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
84 |
rt.addShape(&sphere1); |
42 | 85 |
|
86 |
Material mat2(Colour(1.0, 1.0, 1.0)); |
|
91 | 87 |
mat2.texture = new CheckersTexture(new CubicMap(Vector(-1.5, 2.0, -7.0), 0.48), &cmap); |
88 |
Sphere sphere2(Vector(-1.5, 2.0, -7.0), 1.0, &mat2); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
89 |
rt.addShape(&sphere2); |
42 | 90 |
|
91 |
Material mat3(Colour(1.0, 1.0, 1.0)); |
|
91 | 92 |
mat3.texture = new CheckersTexture(new CylinderMap(Vector(1.5, 2.0, -7.0), 0.48), &cmap); |
93 |
Sphere sphere3(Vector(1.5, 2.0, -7.0), 1.0, &mat3); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
94 |
rt.addShape(&sphere3); |
42 | 95 |
|
96 |
Material mat4(Colour(1.0, 1.0, 1.0)); |
|
91 | 97 |
mat4.texture = new CheckersTexture(new SphereMap(Vector(4.5, 2.0, -7.0), 0.48), &cmap); |
98 |
Sphere sphere4(Vector(4.5, 2.0, -7.0), 1.0, &mat4); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
99 |
rt.addShape(&sphere4); |
42 | 100 |
|
101 |
// cubes |
|
102 |
Material mat5(Colour(1.0, 1.0, 1.0)); |
|
91 | 103 |
mat5.texture = new CheckersTexture(new PlanarMap(Vector(-4.5, 0.0, -7.0), 0.48), &cmap); |
104 |
Box cube1(Vector(-4.5, 0.0, -7.0)-1.0, Vector(-4.5, 0.0, -7.0)+1.0, &mat5); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
105 |
rt.addShape(&cube1); |
42 | 106 |
|
107 |
Material mat6(Colour(1.0, 1.0, 1.0)); |
|
91 | 108 |
mat6.texture = new CheckersTexture(new CubicMap(Vector(-1.5, 0.0, -7.0), 0.48), &cmap); |
109 |
Box cube2(Vector(-1.5, 0.0, -7.0)-1.0, Vector(-1.5, 0.0, -7.0)+1.0, &mat6); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
110 |
rt.addShape(&cube2); |
42 | 111 |
|
112 |
Material mat7(Colour(1.0, 1.0, 1.0)); |
|
91 | 113 |
mat7.texture = new CheckersTexture(new CylinderMap(Vector(1.5, 0.0, -7.0), 0.48), &cmap); |
114 |
Box cube3(Vector(1.5, 0.0, -7.0)-1.0, Vector(1.5, 0.0, -7.0)+1.0, &mat7); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
115 |
rt.addShape(&cube3); |
42 | 116 |
|
117 |
Material mat8(Colour(1.0, 1.0, 1.0)); |
|
91 | 118 |
mat8.texture = new CheckersTexture(new SphereMap(Vector(4.5, 0.0, -7.0), 0.48), &cmap); |
119 |
Box cube4(Vector(4.5, 0.0, -7.0)-1.0, Vector(4.5, 0.0, -7.0)+1.0, &mat8); |
|
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
60
diff
changeset
|
120 |
rt.addShape(&cube4); |
42 | 121 |
|
122 |
mat1.setReflectivity(0); |
|
123 |
mat2.setReflectivity(0); |
|
124 |
mat3.setReflectivity(0); |
|
125 |
mat4.setReflectivity(0); |
|
126 |
mat5.setReflectivity(0); |
|
127 |
mat6.setReflectivity(0); |
|
128 |
mat7.setReflectivity(0); |
|
129 |
mat8.setReflectivity(0); |
|
130 |
||
131 |
top.optimize(); |
|
132 |
||
133 |
w = 1024; |
|
134 |
h = 600; |
|
135 |
||
136 |
/* run interactive mode */ |
|
137 |
loop_sdl(rt, cam, update_callback, key_callback); |
|
138 |
||
139 |
/* render image */ |
|
140 |
if (argc == 2 && !strcmp(argv[1], "-r")) |
|
141 |
{ |
|
142 |
pyrit_verbosity = 2; |
|
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
143 |
rt.ambientOcclusion(300, 5.0, 0.5); |
88
f7edb3b90816
merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
144 |
DefaultSampler sampler(w, h); |
48
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
145 |
sampler.setOversample(2); |
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
146 |
sampler.setSubsample(1); |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
147 |
rt.setSampler(&sampler); |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
148 |
rt.render(); |
88
f7edb3b90816
merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents:
81
diff
changeset
|
149 |
sampler.getPixmap().writePNG("textures.png"); |
42 | 150 |
} |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
151 |
|
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
152 |
return 0; |
42 | 153 |
} |