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