ccdemos/spheres_shadow.cc
branchpyrit
changeset 92 9af5c039b678
parent 91 9d66d323c354
child 100 c005054bf4c1
equal deleted inserted replaced
91:9d66d323c354 92:9af5c039b678
     2 #include "octree.h"
     2 #include "octree.h"
     3 
     3 
     4 #include "common_sdl.h"
     4 #include "common_sdl.h"
     5 
     5 
     6 Camera cam;
     6 Camera cam;
     7 Light light(Vector(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9));
     7 Light light(Vector(-2.0f, 10.0f, -2.0f), Colour(0.9f, 0.9f, 0.9f));
     8 
     8 
     9 Float lx, ly, lz, cf;
     9 Float lx, ly, lz, cf;
    10 
    10 
    11 void update_callback(Float*)
    11 void update_callback(Float*)
    12 {
    12 {
    13 	if (lx != 0.0)
    13 	if (lx != 0.0f)
    14 		light.pos.x += lx;
    14 		light.pos.x += lx;
    15 	if (ly != 0.0)
    15 	if (ly != 0.0f)
    16 		light.pos.y += ly;
    16 		light.pos.y += ly;
    17 	if (lz != 0.0)
    17 	if (lz != 0.0f)
    18 		light.pos.z += lz;
    18 		light.pos.z += lz;
    19 	if (cf != 0.0)
    19 	if (cf != 0.0f)
    20 		cam.F += cf;
    20 		cam.setF(cam.getF() + cf);
    21 }
    21 }
    22 
    22 
    23 void key_callback(int key, int down)
    23 void key_callback(int key, int down)
    24 {
    24 {
    25 	switch (key)
    25 	switch (key)
    26 	{
    26 	{
    27 		case SDLK_r:
    27 		case SDLK_r:
    28 			lx = -0.1 * down;
    28 			lx = -0.1f * down;
    29 			break;
    29 			break;
    30 		case SDLK_t:
    30 		case SDLK_t:
    31 			lx = +0.1 * down;
    31 			lx = +0.1f * down;
    32 			break;
    32 			break;
    33 		case SDLK_f:
    33 		case SDLK_f:
    34 			ly = -0.1 * down;
    34 			ly = -0.1f * down;
    35 			break;
    35 			break;
    36 		case SDLK_g:
    36 		case SDLK_g:
    37 			ly = +0.1 * down;
    37 			ly = +0.1f * down;
    38 			break;
    38 			break;
    39 		case SDLK_v:
    39 		case SDLK_v:
    40 			lz = -0.1 * down;
    40 			lz = -0.1f * down;
    41 			break;
    41 			break;
    42 		case SDLK_b:
    42 		case SDLK_b:
    43 			lz = +0.1 * down;
    43 			lz = +0.1f * down;
    44 			break;
    44 			break;
    45 
    45 
    46 		case SDLK_z:
    46 		case SDLK_z:
    47 			cf = -0.02 * down;
    47 			cf = -0.02f * down;
    48 			break;
    48 			break;
    49 		case SDLK_x:
    49 		case SDLK_x:
    50 			cf = +0.02 * down;
    50 			cf = +0.02f * down;
    51 			break;
    51 			break;
    52 	}
    52 	}
    53 }
    53 }
    54 
    54 
    55 int main(int argc, char **argv)
    55 int main(int argc, char **argv)
    89 	Sphere tinysphere(Vector(-1.2, 0.0, -2.0), 0.7, &mat3);
    89 	Sphere tinysphere(Vector(-1.2, 0.0, -2.0), 0.7, &mat3);
    90 	rt.addShape(&tinysphere);
    90 	rt.addShape(&tinysphere);
    91 
    91 
    92 	top.optimize();
    92 	top.optimize();
    93 
    93 
    94 	cam.setEye(Vector(-2.28908, 4.30992, 12.3051));
    94 	cam.setEye(Vector(-2.28908f, 4.30992f, 12.3051f));
    95 	cam.p = Vector(0.0988566, -0.139543, -0.985269);
    95 	cam.setp(Vector(0.0988566f, -0.139543f, -0.985269f));
    96 	cam.u = Vector(-0.995004, 0, -0.0998334);
    96 	cam.setu(Vector(-0.995004f, 0.0f, -0.0998334f));
    97 	cam.v = Vector(0.0139311, 0.990216, -0.138846);
    97 	cam.setv(Vector(0.0139311f, 0.990216f, -0.138846f));
    98 	rt.setCamera(&cam);
    98 	rt.setCamera(&cam);
    99 
    99 
   100 	w = 800;
   100 	w = 800;
   101 	h = 600;
   101 	h = 600;
   102 
   102 
   111 		sampler.setOversample(2);
   111 		sampler.setOversample(2);
   112 		rt.setSampler(&sampler);
   112 		rt.setSampler(&sampler);
   113 		rt.render();
   113 		rt.render();
   114 		sampler.getPixmap().writePNG("spheres_shadow.png");
   114 		sampler.getPixmap().writePNG("spheres_shadow.png");
   115 	}
   115 	}
       
   116 
       
   117 	return 0;
   116 }
   118 }