예제 #1
0
rgb_value_t Sphere::shade_reflective(Ray* ray, Light* light, std::list<Sphere*>* sphereList, coord_t* point, int ref_cnt){
    rgb_value_t darkness, ret_val;
    darkness.r = 0;
    darkness.g = 0;
    darkness.b = 0;

    coord_t norm_vect;
    norm_vect = subtract_coord(point, &center);
    norm_vect = normalize_vect(&norm_vect);


    coord_t reflect_dir;
    reflect_dir = subtract_coord_nopt(ray->getDirection(), mult_vect(&norm_vect, 2.0*(scalar_mult_vect_nopt(norm_vect, ray->getDirection()))));


    if (ref_cnt > 0) {
        Ray* reflectedRay = new Ray(point, &reflect_dir);
        Sphere* pointer_dummy=this;
        ret_val = reflectedRay->raytrace(sphereList, light, &pointer_dummy, ref_cnt-1);
        delete reflectedRay;
        return ret_val;
    } else {
        return darkness;
    }

}
예제 #2
0
/******************* get_alt_rms_res(residue *r, int xs, int xt) *****************/
double get_alt_rms_res(residue *r, int xs, int xt){
int ai=0;
double RMS=0;
coord_3D c;

if(xt<0){mywhine("get_alt_rms_res: target coord cannot be main set");}
if(xs<0){mywhine("get_alt_rms_res: main set source coords not written yet");}
for(ai=0;ai<r[0].na;ai++){
	c=subtract_coord(r[0].a[ai].xa[xs],r[0].a[ai].xa[xt]);
	RMS+=c.i*c.i+c.j*c.j+c.k*c.k;
	}
RMS/=r[0].na;
RMS=sqrt(RMS);
return RMS;
}
예제 #3
0
/******************* get_alt_rms_mol(molecule *m, int xs, int xt) *****************/
double get_alt_rms_mol(molecule *m, int xs, int xt){
int ai=0,ri=0,nat=0;
double RMS=0;
coord_3D c;

if(xt<0){mywhine("get_alt_rms_mol: target coord cannot be main set");}
if(xs<0){mywhine("get_alt_rms_mol: main set source coords not written yet");}

for(ri=0;ri<m[0].nr;ri++){
	nat+=m[0].r[ri].na;
	for(ai=0;ai<m[0].r[ri].na;ai++){
		c=subtract_coord(m[0].r[ri].a[ai].xa[xs],m[0].r[ri].a[ai].xa[xt]);
		RMS+=c.i*c.i+c.j*c.j+c.k*c.k;
	}}
RMS/=nat;
RMS=sqrt(RMS);
return RMS;
}
예제 #4
0
rgb_value_t Sphere::shade_glass(Ray* ray, Light* light, std::list<Sphere*>* sphereList, coord_t* point, int ref_cnt){
  rgb_value_t darkness, ret_val;
  darkness.r = 0;
  darkness.g = 0;
  darkness.b = 0;
  
  if (ref_cnt == 0) return darkness;
  
  coord_t norm_ray_dir_vect = ray->getDirection();
  norm_ray_dir_vect = normalize_vect(&norm_ray_dir_vect);
  
  coord_t norm_vect;
  norm_vect = subtract_coord(point, &center);
  norm_vect = normalize_vect(&norm_vect);
  
  bool ray_going_inside = (scalar_mult_vect(&norm_vect, &norm_ray_dir_vect)<=0.0) ? true : false;
  
  coord_t refract_dir;
 
  float r, w, k;

  if (ray_going_inside) {
    r = 1/brechzahl;
  } else {
    r = brechzahl;
  }
  
  w = -scalar_mult_vect(&norm_vect, &norm_ray_dir_vect)*r;
  k = 1.0 + (w-r)*(w+r);
  
  if (k<0.0) {
    return this->shade_reflective(ray, light, sphereList, point, ref_cnt-1);
  }
  norm_ray_dir_vect = mult_vect(&norm_ray_dir_vect, r);
  norm_vect = mult_vect(&norm_vect, (w-sqrt(k)));

  refract_dir = add_coord(&norm_ray_dir_vect, &norm_vect);
  
  Ray* refractedRay = new Ray(point, &refract_dir);
  Sphere* pointer_dummy=this;
  ret_val = refractedRay->raytrace(sphereList, light, &pointer_dummy, ref_cnt-1);
  delete refractedRay;
  return ret_val;
}
예제 #5
0
rgb_value_t Sphere::shade_non_reflective(Ray* ray, Light* light, std::list<Sphere*>* sphereList, coord_t* point){
    rgb_value_t darkness;
    darkness.r = 0;
    darkness.g = 0;
    darkness.b = 0;

    coord_t dist_ray_vect;
    float dist_ray_abs;
    coord_t dist_light_vect;
    float dist_light_abs;

    dist_ray_vect = subtract_coord_nopt(this->getCenter(), ray->getStartPoint());

    dist_ray_abs = vect_abs(&dist_ray_vect);

    dist_light_vect = subtract_coord_nopt(this->getCenter(), light->getPosition());

    dist_light_abs = vect_abs(&dist_light_vect);

    bool light_inside = (dist_light_abs<=this->getRadius()) ? true : false;
    bool ray_inside = (dist_ray_abs<=this->getRadius()) ? true : false;

    if (light_inside!=ray_inside) {
        return darkness;
    }

    if (!light_inside) {
        //std::cout << "outside" << std::endl;
        coord_t norm_vect;
        norm_vect = subtract_coord(point, &center);

        coord_t light_point_vect;

        light_point_vect = subtract_coord_nopt(*point, light->getPosition());

        float light_point_abs = vect_abs(&light_point_vect);

        float parallelism = scalar_mult_vect(&norm_vect, &light_point_vect);

        if (parallelism>0.0) return darkness;
        coord_t light_pos = light->getPosition();

        Ray* lightRay = new Ray(&light_pos, &light_point_vect);

        float buffer;

        for (std::list<Sphere*>::iterator p = (*sphereList).begin(); p!=(*sphereList).end(); p++) {
            if ((*p)!=this) {
                if ((*p)->intersectsWithRay(lightRay, &buffer)) {
                    if (buffer<light_point_abs) {
                        delete lightRay;
                        return darkness;
                    }
                }
            }
        }
        delete lightRay;

        norm_vect = normalize_vect(&norm_vect);

        light_point_vect = div_vect(&light_point_vect, -light_point_abs);

        parallelism = scalar_mult_vect(&norm_vect, &light_point_vect);

        rgb_value_t rgb_ret = this->getColour();

        rgb_ret.r *= parallelism;
        rgb_ret.g *= parallelism;
        rgb_ret.b *= parallelism;

        return rgb_ret;

    } else {
        //std::cout << "inside" << std::endl;
        coord_t norm_vect;
        norm_vect = subtract_coord(point, &center);

        coord_t light_point_vect;

        light_point_vect = subtract_coord_nopt(*point, light->getPosition());

        float light_point_abs = vect_abs(&light_point_vect);

        coord_t light_pos = light->getPosition();

        Ray* lightRay = new Ray(&light_pos, &light_point_vect);

        float buffer;

        for (std::list<Sphere*>::iterator p = (*sphereList).begin(); p!=(*sphereList).end(); p++) {
            if ((*p)!=this) {
                if ((*p)->intersectsWithRay(lightRay, &buffer)) {
                    if (buffer<light_point_abs) {
                        delete lightRay;
                        return darkness;
                    }
                }
            }
        }
        delete lightRay;
        norm_vect = normalize_vect(&norm_vect);

        light_point_vect = div_vect(&light_point_vect, light_point_abs);

        float parallelism = scalar_mult_vect(&norm_vect, &light_point_vect);
        rgb_value_t rgb_ret = this->getColour();

        rgb_ret.r *= parallelism;
        rgb_ret.g *= parallelism;
        rgb_ret.b *= parallelism;

        return rgb_ret;
    }


}
예제 #6
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);
    }
}