author | Radek Brich <radek.brich@devl.cz> |
Mon, 19 May 2008 22:59:04 +0200 | |
branch | pyrit |
changeset 98 | 64638385798a |
parent 93 | 96d65f841791 |
child 100 | c005054bf4c1 |
permissions | -rw-r--r-- |
42 | 1 |
#include "raytracer.h" |
91 | 2 |
#include "kdtree.h" |
42 | 3 |
|
4 |
#include "common_sdl.h" |
|
5 |
||
93 | 6 |
Camera cam(Vector(0.0f,6.0f,6.0f), Vector(0.0f,2.0f,-7.0f), Vector(0.0f,0.0f,-1.0f)); |
7 |
Light light(Vector(-2.0f, 10.0f, -2.0f), Colour(0.9f, 0.9f, 0.9f)); |
|
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: |
|
93 | 28 |
lx = -0.1f * down; |
42 | 29 |
break; |
30 |
case SDLK_t: |
|
93 | 31 |
lx = +0.1f * down; |
42 | 32 |
break; |
33 |
case SDLK_f: |
|
93 | 34 |
ly = -0.1f * down; |
42 | 35 |
break; |
36 |
case SDLK_g: |
|
93 | 37 |
ly = +0.1f * down; |
42 | 38 |
break; |
39 |
case SDLK_v: |
|
93 | 40 |
lz = -0.1f * down; |
42 | 41 |
break; |
42 |
case SDLK_b: |
|
93 | 43 |
lz = +0.1f * down; |
42 | 44 |
break; |
45 |
||
46 |
case SDLK_z: |
|
93 | 47 |
cf = -0.02f * down; |
42 | 48 |
break; |
49 |
case SDLK_x: |
|
93 | 50 |
cf = +0.02f * down; |
42 | 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 |
||
93 | 66 |
const Colour c_white(1, 1, 1); |
67 |
const Colour c_black(0, 0, 0); |
|
68 |
||
69 |
Material mat0a(Colour(0.7f, 0.7f, 0.7f)); |
|
70 |
mat0a.setReflectivity(0.0f); |
|
71 |
Box box(Vector(-12.0f, -1.2f, -20.0f), Vector(12.0f, -1.0f, 0.0f), &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
|
72 |
rt.addShape(&box); |
42 | 73 |
|
93 | 74 |
Material mat0b(Colour(0.1f, 0.7f, 0.8f)); |
75 |
mat0b.setReflectivity(0.7f); |
|
76 |
Box box2(Vector(-12.0f, -1.2f, -10.0f), Vector(12.0f, 10.0f, -10.2f), &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
|
77 |
rt.addShape(&box2); |
42 | 78 |
|
93 | 79 |
Float bounds[] = {0.3f, 0.6f, 1.1f}; |
80 |
Colour colours[] = {c_black, c_white, c_black}; |
|
79
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
81 |
BoundColourMap cmap(bounds, colours); |
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
82 |
|
42 | 83 |
// spheres |
93 | 84 |
Material mat1(c_white); |
85 |
mat1.texture = new CheckersTexture(new PlanarMap(Vector(-4.5f, 2.0f, -7.0f), 0.48f), &cmap); |
|
86 |
Sphere sphere1(Vector(-4.5f, 2.0f, -7.0f), 1, &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
|
87 |
rt.addShape(&sphere1); |
42 | 88 |
|
93 | 89 |
Material mat2(c_white); |
90 |
mat2.texture = new CheckersTexture(new CubicMap(Vector(-1.5f, 2.0f, -7.0f), 0.48f), &cmap); |
|
91 |
Sphere sphere2(Vector(-1.5f, 2.0f, -7.0f), 1, &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
|
92 |
rt.addShape(&sphere2); |
42 | 93 |
|
93 | 94 |
Material mat3(c_white); |
95 |
mat3.texture = new CheckersTexture(new CylinderMap(Vector(1.5f, 2.0f, -7.0f), 0.48f), &cmap); |
|
96 |
Sphere sphere3(Vector(1.5f, 2.0f, -7.0f), 1, &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
|
97 |
rt.addShape(&sphere3); |
42 | 98 |
|
93 | 99 |
Material mat4(c_white); |
100 |
mat4.texture = new CheckersTexture(new SphereMap(Vector(4.5f, 2.0f, -7.0f), 0.48f), &cmap); |
|
101 |
Sphere sphere4(Vector(4.5f, 2.0f, -7.0f), 1, &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
|
102 |
rt.addShape(&sphere4); |
42 | 103 |
|
104 |
// cubes |
|
93 | 105 |
Material mat5(c_white); |
106 |
const Vector cube1_base(-4.5f, 0.0f, -7.0f); |
|
107 |
mat5.texture = new CheckersTexture(new PlanarMap(cube1_base, 0.48f), &cmap); |
|
108 |
Box cube1(cube1_base - 1.0f, cube1_base + 1.0f, &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
|
109 |
rt.addShape(&cube1); |
42 | 110 |
|
93 | 111 |
Material mat6(c_white); |
112 |
const Vector cube2_base(-1.5f, 0.0f, -7.0f); |
|
113 |
mat6.texture = new CheckersTexture(new CubicMap(cube2_base, 0.48f), &cmap); |
|
114 |
Box cube2(cube2_base - 1.0f, cube2_base + 1.0f, &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
|
115 |
rt.addShape(&cube2); |
42 | 116 |
|
93 | 117 |
Material mat7(c_white); |
118 |
const Vector cube3_base(1.5f, 0.0f, -7.0f); |
|
119 |
mat7.texture = new CheckersTexture(new CylinderMap(cube3_base, 0.48f), &cmap); |
|
120 |
Box cube3(cube3_base - 1.0f, cube3_base + 1.0f, &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
|
121 |
rt.addShape(&cube3); |
42 | 122 |
|
93 | 123 |
Material mat8(c_white); |
124 |
const Vector cube4_base(4.5f, 0.0f, -7.0f); |
|
125 |
mat8.texture = new CheckersTexture(new SphereMap(cube4_base, 0.48f), &cmap); |
|
126 |
Box cube4(cube4_base - 1.0f, cube4_base + 1.0f, &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
|
127 |
rt.addShape(&cube4); |
42 | 128 |
|
129 |
mat1.setReflectivity(0); |
|
130 |
mat2.setReflectivity(0); |
|
131 |
mat3.setReflectivity(0); |
|
132 |
mat4.setReflectivity(0); |
|
133 |
mat5.setReflectivity(0); |
|
134 |
mat6.setReflectivity(0); |
|
135 |
mat7.setReflectivity(0); |
|
136 |
mat8.setReflectivity(0); |
|
137 |
||
138 |
top.optimize(); |
|
139 |
||
140 |
w = 1024; |
|
141 |
h = 600; |
|
142 |
||
143 |
/* run interactive mode */ |
|
144 |
loop_sdl(rt, cam, update_callback, key_callback); |
|
145 |
||
146 |
/* render image */ |
|
147 |
if (argc == 2 && !strcmp(argv[1], "-r")) |
|
148 |
{ |
|
149 |
pyrit_verbosity = 2; |
|
93 | 150 |
rt.ambientOcclusion(300, 5.0f, 0.5f); |
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
|
151 |
DefaultSampler sampler(w, h); |
48
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
152 |
sampler.setOversample(2); |
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
153 |
sampler.setSubsample(1); |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
154 |
rt.setSampler(&sampler); |
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
155 |
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
|
156 |
sampler.getPixmap().writePNG("textures.png"); |
42 | 157 |
} |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
158 |
|
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
159 |
return 0; |
42 | 160 |
} |