예제 #1
0
파일: ray.cpp 프로젝트: Xenexes/raytracer
bool Ray::getClosestSphere(std::list<Sphere*>* sphereList, Sphere** closestSphere, coord_t* closestSpherePoint, Sphere** ignoreSphere) {
    bool hit_buffer = false;
    float t_buffer, t_min;
    for (std::list<Sphere*>::iterator p = (*sphereList).begin(); p!=(*sphereList).end(); p++) {
        if ((*p)!=(*ignoreSphere)) {
            if ((*p)->intersectsWithRay(this, &t_buffer)) {
                if (hit_buffer==false) {
                    t_min = t_buffer;
                    hit_buffer = true;
                    *closestSphere = *p;
                }
                else if (t_buffer < t_min) {
                    t_min = t_buffer;
                    *closestSphere = *p;
                }
            }
        }

    }
    if (hit_buffer==true) {
        *closestSpherePoint = point_on_straight(&start_point, &direction, t_min);
        return true;
    }
    else {
        return false;
    }

}
예제 #2
0
void Camera::makeSnapShot(std::list<Sphere*>* sphereList, Light* light, int ref_max, bool show) {

    coord_t ray_dir_temp, ray_dir, ray_dir_projection_help, focal_point;
    
    focal_point = point_on_straight(&optical_center, &direction, -focal_length);
    
    rgb_value_t pixel_temp;

    Sphere* dummy_pointer = NULL;

    Ray privateRay(&focal_point, &focal_point);
    omp_set_num_threads(2);
    #pragma omp parallel for firstprivate(privateRay, ray_dir_temp, ray_dir, pixel_temp, ray_dir_projection_help) schedule(static,1)
    for (int i=0; i<sensor_height_px; i++) {
        for (int j=0; j<sensor_width_px; j++) {
            //initial Koordinatenursprung
            ray_dir.y = j*px_width -sensor_width_physical/2;
            ray_dir.z = i*px_height -sensor_height_physical/2;
            ray_dir.x = 0.0;
            //rotation um y achse
            ray_dir_projection_help = direction;
            ray_dir_projection_help.y= 0.0;
            ray_dir_projection_help = normalize_vect(&ray_dir_projection_help);
            if (ray_dir_projection_help.x < 0.0) ray_dir_projection_help.x=-ray_dir_projection_help.x;
            ray_dir_temp.x = -ray_dir.z*ray_dir_projection_help.z;
            ray_dir_temp.y = ray_dir.y;
            ray_dir_temp.z = ray_dir.z*ray_dir_projection_help.x;
            //rotation um z achse
            ray_dir_projection_help = direction;
            ray_dir_projection_help.z= 0.0;
            ray_dir_projection_help = normalize_vect(&ray_dir_projection_help);
            ray_dir.x = ray_dir_temp.x*ray_dir_projection_help.x - ray_dir_temp.y*ray_dir_projection_help.y;
            ray_dir.y = ray_dir_temp.x*ray_dir_projection_help.y + ray_dir_temp.y*ray_dir_projection_help.x;
            ray_dir.z = ray_dir_temp.z;
            //ray_dir = ray_dir_temp;
            //translation to optical center

            ray_dir = add_coord(&ray_dir, &optical_center);

            ray_dir = subtract_coord(&ray_dir, &focal_point);

            privateRay.setStartPoint(&optical_center);
            privateRay.setDirection(&ray_dir);

            pixel_temp = privateRay.raytrace(sphereList, light, &dummy_pointer, ref_max);

            image_matrix->at<Vec3b>(i,j)[2] = pixel_temp.r;
            image_matrix->at<Vec3b>(i,j)[1] = pixel_temp.g;
            image_matrix->at<Vec3b>(i,j)[0] = pixel_temp.b;


        }
    }
    if (show) {
        namedWindow( "Raytrace", CV_WINDOW_AUTOSIZE );
        imshow("Raytrace", *image_matrix);
	std::cout << "BLA" << std::endl;
        cvWaitKey(0);
    } else {
        //imwrite("raytrace.jpg", image_matrix);
    }
}