ccdemos/realtime_dragon.cc
branchpyrit
changeset 80 907929fa9b59
parent 72 7c3f38dff082
child 91 9d66d323c354
equal deleted inserted replaced
79:062b1c4143f7 80:907929fa9b59
     1 #include "raytracer.h"
     1 #include "raytracer.h"
     2 #include "kdtree.h"
     2 #include "kdtree.h"
       
     3 #include "serialize.h"
     3 
     4 
     4 #include "common_sdl.h"
     5 #include "common_sdl.h"
     5 #include "common_ply.h"
     6 #include "common_ply.h"
     6 
     7 
     7 int main(int argc, char **argv)
     8 int main(int argc, char **argv)
    10 	KdTree top;
    11 	KdTree top;
    11 	Camera cam;
    12 	Camera cam;
    12 
    13 
    13 	rt.setMaxDepth(0);
    14 	rt.setMaxDepth(0);
    14 	rt.setTop(&top);
    15 	rt.setTop(&top);
       
    16 	rt.setCamera(&cam);
       
    17 	cam.setEye(Vector3(0,0,10));
    15 
    18 
    16 	Light light1(Vector3(-5.0, 2.0, 8.0), Colour(0.9, 0.3, 0.6));
    19 	Light light1(Vector3(-5.0, 2.0, 8.0), Colour(0.9, 0.3, 0.6));
    17 	light1.castShadows(false);
    20 	light1.castShadows(false);
    18 	rt.addLight(&light1);
    21 	rt.addLight(&light1);
    19 
    22 
    21 	//light2.castShadows(false);
    24 	//light2.castShadows(false);
    22 	//rt.addlight(&light2);
    25 	//rt.addlight(&light2);
    23 
    26 
    24 	Material mat(Colour(0.9, 0.9, 0.9));
    27 	Material mat(Colour(0.9, 0.9, 0.9));
    25 	mat.setSmooth(true);
    28 	mat.setSmooth(true);
    26 	load_ply(rt, "../models/ply/dragon/dragon_vrip.ply", &mat, Vector3(-29,29,-29), Vector3(0,-3.6,0));
    29 	LinearColourMap cmap(Colour(0.5, 0.0, 0.0), Colour(1.0, 1.0, 0.5));
       
    30 	//LinearColourMap cmap(Colour(1.0, 0.2, 0.0), Colour(0.3, 0.9, 0.2));
       
    31 	mat.setTexture(new CloudTexture(10, &cmap));
    27 
    32 
    28 	rt.setCamera(&cam);
    33 	ifstream fin("realtime_dragon.kdtreedump");
    29 	cam.setEye(Vector3(0,0,10));
    34 	if (!fin)
       
    35 	{
       
    36 		load_ply(rt, "../models/ply/dragon/dragon_vrip.ply",
       
    37 			&mat, Vector3(-29,29,-29), Vector3(0,-3.6,0));
       
    38 		top.optimize();
       
    39 	}
       
    40 	else
       
    41 		top.load(fin, &mat);
    30 
    42 
    31 	top.optimize();
    43 	for (int i = 1; i < argc; i++)
       
    44 	{
       
    45 		if (strcmp(argv[1], "-dump") == 0)
       
    46 		{
       
    47 			resetSerializer();
       
    48 			ofstream fout("realtime_dragon.kdtreedump");
       
    49 			fout << top << endl;
       
    50 			fout.close();
       
    51 		}
    32 
    52 
    33 	if (argc == 2 && strcmp(argv[1], "-buildonly") == 0)
    53 		if (strcmp(argv[1], "-buildonly") == 0)
    34 		return 0;
    54 			return 0;
       
    55 	}
    35 
    56 
    36 	loop_sdl(rt, cam);
    57 	loop_sdl(rt, cam);
    37 }
    58 }