ccdemos/textures.cc
branchpyrit
changeset 72 7c3f38dff082
parent 60 a23b5089b9c3
child 75 20dee9819b17
equal deleted inserted replaced
71:4fedf7290929 72:7c3f38dff082
     2 #include "octree.h"
     2 #include "octree.h"
     3 
     3 
     4 #include "image.h"
     4 #include "image.h"
     5 #include "common_sdl.h"
     5 #include "common_sdl.h"
     6 
     6 
     7 Camera cam;
     7 Camera cam(Vector3(0.,6.,6.), Vector3(0.,2.,-7.), Vector3(0.,0.,-1.));
     8 Light light(Vector3(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9));
     8 Light light(Vector3(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9));
     9 
     9 
    10 Float lx, ly, lz, cf;
    10 Float lx, ly, lz, cf;
    11 
    11 
    12 
    12 
   147 	if (ly != 0.0)
   147 	if (ly != 0.0)
   148 		light.pos.y += ly;
   148 		light.pos.y += ly;
   149 	if (lz != 0.0)
   149 	if (lz != 0.0)
   150 		light.pos.z += lz;
   150 		light.pos.z += lz;
   151 	if (cf != 0.0)
   151 	if (cf != 0.0)
   152 		cam.f += cf;
   152 		cam.F += cf;
   153 }
   153 }
   154 
   154 
   155 void key_callback(int key, int down)
   155 void key_callback(int key, int down)
   156 {
   156 {
   157 	switch (key)
   157 	switch (key)
   187 int main(int argc, char **argv)
   187 int main(int argc, char **argv)
   188 {
   188 {
   189 	Raytracer rt;
   189 	Raytracer rt;
   190 
   190 
   191 	Octree top;
   191 	Octree top;
       
   192 	rt.setCamera(&cam);
   192 	rt.setTop(&top);
   193 	rt.setTop(&top);
   193 
   194 
   194 	rt.addlight(&light);
   195 	rt.addLight(&light);
   195 	light.castShadows(false);
   196 	light.castShadows(false);
   196 
   197 
   197 	Material mat0a(Colour(0.7, 0.7, 0.7));
   198 	Material mat0a(Colour(0.7, 0.7, 0.7));
   198 	mat0a. setReflectivity(0.0);
   199 	mat0a. setReflectivity(0.0);
   199 	Box box(Vector3(-12.0, -1.2, -20.0), Vector3(12.0, -1.0, 0.0), &mat0a);
   200 	Box box(Vector3(-12.0, -1.2, -20.0), Vector3(12.0, -1.0, 0.0), &mat0a);
   200 	rt.addshape(&box);
   201 	rt.addShape(&box);
   201 
   202 
   202 	Material mat0b(Colour(0.1, 0.7, 0.8));
   203 	Material mat0b(Colour(0.1, 0.7, 0.8));
   203 	mat0b.setReflectivity(0.7);
   204 	mat0b.setReflectivity(0.7);
   204 	Box box2(Vector3(-12.0, -1.2, -10.0), Vector3(12.0, 10.0, -10.2), &mat0b);
   205 	Box box2(Vector3(-12.0, -1.2, -10.0), Vector3(12.0, 10.0, -10.2), &mat0b);
   205 	rt.addshape(&box2);
   206 	rt.addShape(&box2);
   206 
   207 
   207 	// spheres
   208 	// spheres
   208 	Material mat1(Colour(1.0, 1.0, 1.0));
   209 	Material mat1(Colour(1.0, 1.0, 1.0));
   209 	mat1.texture = new PlanarMapTexture(Vector3(4.0, 2.0, -7.0));
   210 	mat1.texture = new PlanarMapTexture(Vector3(-4.5, 2.0, -7.0));
   210 	Sphere sphere1(Vector3(4.0, 2.0, -7.0), 1.0, &mat1);
   211 	Sphere sphere1(Vector3(-4.5, 2.0, -7.0), 1.0, &mat1);
   211 	rt.addshape(&sphere1);
   212 	rt.addShape(&sphere1);
   212 
   213 
   213 	Material mat2(Colour(1.0, 1.0, 1.0));
   214 	Material mat2(Colour(1.0, 1.0, 1.0));
   214 	mat2.texture = new CubicMapTexture(Vector3(1.0, 2.0, -7.0));
   215 	mat2.texture = new CubicMapTexture(Vector3(-1.5, 2.0, -7.0));
   215 	Sphere sphere2(Vector3(1.0, 2.0, -7.0), 1.0, &mat2);
   216 	Sphere sphere2(Vector3(-1.5, 2.0, -7.0), 1.0, &mat2);
   216 	rt.addshape(&sphere2);
   217 	rt.addShape(&sphere2);
   217 
   218 
   218 	Material mat3(Colour(1.0, 1.0, 1.0));
   219 	Material mat3(Colour(1.0, 1.0, 1.0));
   219 	mat3.texture = new CylinderMapTexture(Vector3(-2.0, 2.0, -7.0));
   220 	mat3.texture = new CylinderMapTexture(Vector3(1.5, 2.0, -7.0));
   220 	Sphere sphere3(Vector3(-2.0, 2.0, -7.0), 1.0, &mat3);
   221 	Sphere sphere3(Vector3(1.5, 2.0, -7.0), 1.0, &mat3);
   221 	rt.addshape(&sphere3);
   222 	rt.addShape(&sphere3);
   222 
   223 
   223 	Material mat4(Colour(1.0, 1.0, 1.0));
   224 	Material mat4(Colour(1.0, 1.0, 1.0));
   224 	mat4.texture = new SphereMapTexture(Vector3(-5.0, 2.0, -7.0));
   225 	mat4.texture = new SphereMapTexture(Vector3(4.5, 2.0, -7.0));
   225 	Sphere sphere4(Vector3(-5.0, 2.0, -7.0), 1.0, &mat4);
   226 	Sphere sphere4(Vector3(4.5, 2.0, -7.0), 1.0, &mat4);
   226 	rt.addshape(&sphere4);
   227 	rt.addShape(&sphere4);
   227 
   228 
   228 	// cubes
   229 	// cubes
   229 	Material mat5(Colour(1.0, 1.0, 1.0));
   230 	Material mat5(Colour(1.0, 1.0, 1.0));
   230 	mat5.texture = new PlanarMapTexture(Vector3(4.0, 0.0, -7.0));
   231 	mat5.texture = new PlanarMapTexture(Vector3(-4.5, 0.0, -7.0));
   231 	Box cube1(Vector3(4.0, 0.0, -7.0)-1.0, Vector3(4.0, 0.0, -7.0)+1.0, &mat5);
   232 	Box cube1(Vector3(-4.5, 0.0, -7.0)-1.0, Vector3(-4.5, 0.0, -7.0)+1.0, &mat5);
   232 	rt.addshape(&cube1);
   233 	rt.addShape(&cube1);
   233 
   234 
   234 	Material mat6(Colour(1.0, 1.0, 1.0));
   235 	Material mat6(Colour(1.0, 1.0, 1.0));
   235 	mat6.texture = new CubicMapTexture(Vector3(1.0, 0.0, -7.0));
   236 	mat6.texture = new CubicMapTexture(Vector3(-1.5, 0.0, -7.0));
   236 	Box cube2(Vector3(1.0, 0.0, -7.0)-1.0, Vector3(1.0, 0.0, -7.0)+1.0, &mat6);
   237 	Box cube2(Vector3(-1.5, 0.0, -7.0)-1.0, Vector3(-1.5, 0.0, -7.0)+1.0, &mat6);
   237 	rt.addshape(&cube2);
   238 	rt.addShape(&cube2);
   238 
   239 
   239 	Material mat7(Colour(1.0, 1.0, 1.0));
   240 	Material mat7(Colour(1.0, 1.0, 1.0));
   240 	mat7.texture = new CylinderMapTexture(Vector3(-2.0, 0.0, -7.0));
   241 	mat7.texture = new CylinderMapTexture(Vector3(1.5, 0.0, -7.0));
   241 	Box cube3(Vector3(-2.0, 0.0, -7.0)-1.0, Vector3(-2.0, 0.0, -7.0)+1.0, &mat7);
   242 	Box cube3(Vector3(1.5, 0.0, -7.0)-1.0, Vector3(1.5, 0.0, -7.0)+1.0, &mat7);
   242 	rt.addshape(&cube3);
   243 	rt.addShape(&cube3);
   243 
   244 
   244 	Material mat8(Colour(1.0, 1.0, 1.0));
   245 	Material mat8(Colour(1.0, 1.0, 1.0));
   245 	mat8.texture = new SphereMapTexture(Vector3(-5.0, 0.0, -7.0));
   246 	mat8.texture = new SphereMapTexture(Vector3(4.5, 0.0, -7.0));
   246 	Box cube4(Vector3(-5.0, 0.0, -7.0)-1.0, Vector3(-5.0, 0.0, -7.0)+1.0, &mat8);
   247 	Box cube4(Vector3(4.5, 0.0, -7.0)-1.0, Vector3(4.5, 0.0, -7.0)+1.0, &mat8);
   247 	rt.addshape(&cube4);
   248 	rt.addShape(&cube4);
   248 
   249 
   249 	mat1.setReflectivity(0);
   250 	mat1.setReflectivity(0);
   250 	mat2.setReflectivity(0);
   251 	mat2.setReflectivity(0);
   251 	mat3.setReflectivity(0);
   252 	mat3.setReflectivity(0);
   252 	mat4.setReflectivity(0);
   253 	mat4.setReflectivity(0);
   254 	mat6.setReflectivity(0);
   255 	mat6.setReflectivity(0);
   255 	mat7.setReflectivity(0);
   256 	mat7.setReflectivity(0);
   256 	mat8.setReflectivity(0);
   257 	mat8.setReflectivity(0);
   257 
   258 
   258 	top.optimize();
   259 	top.optimize();
   259 
       
   260 	cam.setEye(Vector3(-0.530505, 11.0964, 11.2208));
       
   261 	cam.p = Vector3(-4.18144e-08, -0.461779, -0.886995);
       
   262 	cam.u = Vector3(-1, 0, 6.3393e-11);
       
   263 	cam.v = Vector3(3.19387e-08, 0.886995, -0.461779);
       
   264 	rt.setCamera(&cam);
       
   265 
   260 
   266 	w = 1024;
   261 	w = 1024;
   267 	h = 600;
   262 	h = 600;
   268 
   263 
   269 	/* run interactive mode */
   264 	/* run interactive mode */