user-0 提问: 光线跟踪 代码 求帮忙看一下问题

回复:
user: user-1
content: 没有光源 ？

user: user-1
content: 摄像头方向不对？ 左右手坐标系搞混了？ 坐标值没换算到0,1或-1,1范围内？ 我猜。

user: user-0
content: 最后出来的图像一片黑……我也不知道哪儿有错orz

user: user-0
content: int main(int argc,char** argv) {     unsigned char head[54]; 	int size = w*h*3;     FILE *fp1,*fp2=NULL;     fp1 = fopen("white.bmp","rb+");      if(fp1==NULL) 	{ 		printf("文件未找到\n"); 	}     fread(head,sizeof(char),54,fp1);  	for(int i =0;i<h;i++) 	{//初始化帧缓存 		for(int j=0;j<w;j++){             zbuffer[i][j] = 100000;             buffer[i][j][0] = 0;             buffer[i][j][1] = 0;             buffer[i][j][2] = 0;         }     }  	//球1设置     sphere_1.centerpos[0] = 50;     sphere_1.centerpos[1] = 0;     sphere_1.centerpos[2] = 140;     sphere_1.radius = 90;     sphere_1.B = 139;     sphere_1.G = 236;     sphere_1.R = 255;     sphere_1.n = 10;     sphere_1.ks = 0.6;     sphere_1.kt = 0.6; 	sphere_1.ka[0]=0.1; 	sphere_1.ka[1]=0.1; 	sphere_1.ka[2]=0.1; 	sphere_1.kd[0]=0; 	sphere_1.kd[1]=0; 	sphere_1.kd[2]=0.8;      //球2设置 	sphere_2.centerpos[0] = -90;     sphere_2.centerpos[1] = 0;     sphere_2.centerpos[2] = 200;     sphere_2.radius = 100;     sphere_2.B = 8;     sphere_2.G = 101;     sphere_2.R = 139;     sphere_2.n = 10;     sphere_2.ks = 0.6;     sphere_2.kt = 0.6;     sphere_2.ka[0]=0.1; 	sphere_2.ka[1]=0.1; 	sphere_2.ka[2]=0.1; 	sphere_2.kd[0]=0; 	sphere_2.kd[1]=0; 	sphere_2.kd[2]=0.8;      //平面设置     plane_1.a = 0;     plane_1.b = 0;     plane_1.c = 1;     plane_1.d = -180;     plane_1.n = 40;     plane_1.R = 0;     plane_1.G = 0;     plane_1.B = 255;     plane_1.ks = 0.9;     plane_1.kt = 0.6; 	plane_1.ka[0]=0.1; 	plane_1.ka[1]=0.1; 	plane_1.ka[2]=0.1; 	plane_1.kd[0]=0; 	plane_1.kd[1]=0; 	plane_1.kd[2]=0.8;  	//通过视点V和像素pixel的光线R，R[0]R[1]R[2]存储方向，R[3]R[4]R[5]存储发射点 	float D[3]={0,0,0};//设置视线方向 	float t1,t2,t3; 	float z;  	float* color;  	for(i = 0; i<h; i++){         for(int j = 0; j<w; j++){             D[0] = (-w/2+j-eye[0])/sqrt((float)(pow((-w/2+j-eye[0]),2)+pow((h/2-i-eye[1]),2)+pow((zv-eye[2]),2)));             D[1] = (h/2-i-eye[1])/sqrt((float)(pow((-w/2+j-eye[0]),2)+pow((h/2-i-eye[1]),2)+pow((zv-eye[2]),2)));;             D[2] = (zv-eye[2])/sqrt((float)(pow((-w/2+j-eye[0]),2)+pow((h/2-i-eye[1]),2)+pow((zv-eye[2]),2)));;             Ray.start[0] = D[0];             Ray.start[1] = D[1];             Ray.start[2] = D[2];             Ray.direction[0] = eye[0];             Ray.direction[1] = eye[1];             Ray.direction[2] = eye[2];  			t1 = intersection_sphere(sphere_1, Ray);             t2 = intersection_sphere(sphere_2,Ray);             t3 = intersection_plane(plane_1,Ray);  			if(t1!=0){                 z = eye[2]+D[2]*t1;                 if(z<zbuffer[i][j]){ 					color=RayTrace(Ray,1,1);                     buffer[i][j][0] = color[0]; 					printf("%f",color[0]);                     buffer[i][j][1] = color[1];                     buffer[i][j][2] = color[2];                     zbuffer[i][j] = z;                 }              }              if(t2!=0){                 z = eye[2]+D[2]*t2;                 if(z<zbuffer[i][j]){ 					color=RayTrace(Ray,1,1);                     buffer[i][j][0] = color[0];                     buffer[i][j][1] = color[1];                     buffer[i][j][2] = color[2];                     zbuffer[i][j] = z;                 }              }             if(t3!=0){                 z = eye[2]+D[2]*t3;                 if(z<zbuffer[i][j]){                     color=RayTrace(Ray,1,1);                     buffer[i][j][0] = color[0];                     buffer[i][j][1] = color[1];                     buffer[i][j][2] = color[2];                     zbuffer[i][j] = z;                 }             } 		} 	}  	fp2=fopen("result.bmp","wb+");     fwrite(head, sizeof(char), 54, fp2);     fseek(fp2,54,0);     fwrite(buffer,sizeof(char),size,fp2);     return 0; }