src/raytracer.cc
branchpyrit
changeset 15 a0a3e334744f
parent 14 fc18ac4833f2
child 16 20bceb605f48
equal deleted inserted replaced
14:fc18ac4833f2 15:a0a3e334744f
    97 
    97 
    98 	if (nearest_shape == NULL) {
    98 	if (nearest_shape == NULL) {
    99 		return bg_colour;
    99 		return bg_colour;
   100 	} else {
   100 	} else {
   101 		Colour acc = Colour();
   101 		Colour acc = Colour();
   102 		Vector3 P = ray.a + ray.dir * nearest_distance; // point of intersection
   102 		Vector3 P = ray.o + ray.dir * nearest_distance; // point of intersection
   103 		Vector3 normal = nearest_shape->normal(P);
   103 		Vector3 normal = nearest_shape->normal(P);
   104 		acc = PhongShader_ambient(*nearest_shape->material, P);
   104 		acc = PhongShader_ambient(*nearest_shape->material, P);
   105 
   105 
   106 		vector<Light*>::iterator light;
   106 		vector<Light*>::iterator light;
   107 		for (light = lights.begin(); light != lights.end(); light++) {
   107 		for (light = lights.begin(); light != lights.end(); light++) {
   209 	float dx = -2*startx/w, dy = -2*starty/h;
   209 	float dx = -2*startx/w, dy = -2*starty/h;
   210 	float vy;
   210 	float vy;
   211 	RenderrowData *d;
   211 	RenderrowData *d;
   212 
   212 
   213 	printf("* building kd-tree\n");
   213 	printf("* building kd-tree\n");
   214 	//cout << endl;
       
   215 	top->optimize();
   214 	top->optimize();
   216 	//static_cast<KdTree*>(top)->save(cout);
       
   217 	//cout << endl;
       
   218 
   215 
   219 	//srand(time(NULL));
   216 	//srand(time(NULL));
   220 
   217 
   221 	// eye - viewing point
   218 	/* eye - viewing point */
   222 	Vector3 eye(0, 0, -5);
   219 	Vector3 eye(0, 0, -5);
   223 
   220 
   224 	// for each pixel...
       
   225 	vy = starty;
   221 	vy = starty;
   226 
   222 
   227 #ifdef PTHREADS
   223 #ifdef PTHREADS
   228 	int num_threads = 4;
   224 	int num_threads = 4;
   229 	printf("* pthreads enabled, using %d threads\n", num_threads);
   225 	printf("* pthreads enabled, using %d threads\n", num_threads);
   231 	for (int t = 0; t < num_threads; t++)
   227 	for (int t = 0; t < num_threads; t++)
   232 		threads[t] = pthread_self();
   228 		threads[t] = pthread_self();
   233 	int t = 0;
   229 	int t = 0;
   234 #endif
   230 #endif
   235 
   231 
       
   232 	/* for each pixel... */
   236 	printf("* rendering row   0 (  0%% done)");
   233 	printf("* rendering row   0 (  0%% done)");
   237 	for (int y = 0; y < h; y++) {
   234 	for (int y = 0; y < h; y++) {
   238 		d = (RenderrowData*) malloc(sizeof(RenderrowData));
   235 		d = (RenderrowData*) malloc(sizeof(RenderrowData));
   239 		d->rt = this;
   236 		d->rt = this;
   240 		d->w = w;
   237 		d->w = w;