示例#1
0
文件: bhtree.c 项目: bencelder/bhsim
Particle particle_add(Particle p1, Particle p2){
    // add the masses, find the center of mass
    Particle p3;
    p3.mass = p1.mass + p2.mass;

    double temp1[] = {0.,0.};
    double temp2[] = {0.,0.};
    vec_mult( p1.mass, p1.pos, temp1);
    vec_mult( p2.mass, p2.pos, temp2);

    vec_add( temp1, temp2, p3.pos );
    vec_mult( 1./p3.mass, p3.pos, p3.pos );
    
    return p3;
}
示例#2
0
文件: auxi.c 项目: solmir/projet42
t_vec		*vector_proj_vector(t_vec *v1, t_vec *v2) // project vector 1 in vector 2
{
	t_vec	*ret;

	ret = vec_mult(v2, dot_prod(v1, v2) / dot_prod(v2, v2));
	return (ret);
}
示例#3
0
文件: calc2.c 项目: gabfou/RT
inline t_vec		vector_proj_vector(const t_vec v1, const t_vec v2)
{
	t_vec	ret;

	ret = vec_mult(v2, dot_prod(v1, v2) / dot_prod(v2, v2));
	return (ret);
}
示例#4
0
文件: fdgl.hpp 项目: EQ4/lad
/** Hooke's law */
inline Vector
spring_force(const Vector& a, const Vector& b, double length, double k)
{
	const Vector vec          = vec_sub(b, a);
	const double mag          = vec_mag(vec);
	const double displacement = length - mag;
	return vec_mult(vec, k * displacement * 0.5 / mag);
}
示例#5
0
文件: fdgl.hpp 项目: EQ4/lad
/** Constant tide force, does not vary with distance. */
inline Vector
tide_force(const Vector& a, const Vector& b, double power)
{
	static const double G   = 0.0000000000667;
	const Vector        vec = vec_sub(a, b);
	const double        mag = vec_mag(vec);
	return vec_mult(vec, G * power / mag);
}
示例#6
0
文件: ga_shading.c 项目: fvdsn/gally
/* diffuse shading */
static void ga_shade_diffuse(vec_t *color, const ga_material_t *mat,const vec_t *lcolor, const vec_t *ldir, const vec_t *norm, float factor){
	float fact = vec_dot(*norm,*ldir);
	if(fact > 0.0f){
		*color = vec_add(*color,
			vec_scale(fact*factor*mat->diff_factor
				,vec_mult(mat->diff_color,*lcolor)));
	}
}
void foo(float *p0, float *v1, float *v2, int N)
{
   init(v1, v2, N);
   #pragma omp target data map(to: v1[0:N], v2[:N]) map(from: p0[0:N])
   {
      vec_mult(p0, v1, v2, N);
   }
   output(p0, N);
}
示例#8
0
文件: ga_shading.c 项目: fvdsn/gally
/* Computes the phong hilight */
static void ga_shade_phong(vec_t *color, const ga_material_t *mat,const vec_t *lcolor, const vec_t *ldir, const vec_t *dir, const vec_t *norm, float factor){
	vec_t r;
	float fact;
	float power;
	r = vec_sub(
		vec_scale(2.0f,vec_scale(vec_dot(*norm,*ldir),*norm)),
		*ldir);	
	if((fact = vec_dot(r,vec_neg(*dir))) > 0.0f){
		power = powf(fact,mat->spec_power)*mat->spec_factor;
		*color = vec_add(*color, vec_scale( power*factor,
				vec_mult(mat->spec_color,*lcolor)));
	}
}
示例#9
0
文件: target-4.c 项目: 0day-ci/gcc
int main ()
{
  double p1[N], p2[N];
  double v1[N], v2[N];

  init (v1, v2);

  vec_mult_ref (p1, v1, v2);
  vec_mult (p2, v1, v2);

  check (p1, p2);

  return 0;
}
示例#10
0
文件: e.50.5.c 项目: AlexMioMio/gcc
int main ()
{
  float p1[N], p2[N];
  float v1[N], v2[N];

  init (v1, v2);

  vec_mult_ref (p1, v1, v2);
  vec_mult (p2, v1, v2);

  check (p1, p2);

  return 0;
}
示例#11
0
int main ()
{
  float *p1 = (float *) malloc (N * sizeof (float));
  float *p2 = (float *) malloc (N * sizeof (float));

  vec_mult_ref (p1, N);
  vec_mult (p2, N);

  check (p1, p2, N);

  free (p1);
  free (p2);

  return 0;
}
示例#12
0
文件: opticator.c 项目: gabfou/RT
double			get_schlick(t_pd *pd, t_inter *inter)
{
	double	ro;
	double	cosi;
	double	cost;

	ro = carre(AIR_INCI - GLASS_INCI / AIR_INCI + GLASS_INCI);
	cosi = dot_prod(vec_mult(pd->dir, -1), inter->norm);
	cost = fabs(1 - (carre(AIR_INCI / GLASS_INCI) * (1 - carre(cosi))));
	if (AIR_INCI <= GLASS_INCI)
		return (ro + (1 - ro) * pow(1 - cosi, 5));
	else if (AIR_INCI > GLASS_INCI)
		return (ro + (1 - ro) * pow(1 - cost, 5));
	else
		return (1);
}
示例#13
0
int main ()
{
  int *p = (int *) malloc (MAX * sizeof (int));
  int *p1 = (int *) malloc (MAX * sizeof (int));
  int *v1 = (int *) malloc (MAX * sizeof (int));
  int *v2 = (int *) malloc (MAX * sizeof (int));

  vec_mult_ref (p, v1, v2, MAX);
  vec_mult (p1, v1, v2, MAX);

  check (p, p1, MAX);

  free (p);
  free (p1);
  free (v1);
  free (v2);

  return 0;
}
示例#14
0
文件: fdgl.hpp 项目: EQ4/lad
/** Repelling charge force, ala Coulomb's law. */
inline Vector
repel_force(const Region& a, const Region& b)
{
	static const double MIN_DIST = 1.0;

	Vector vec;
	double dist = rect_distance(
		&vec,
		a.pos.x - (a.area.x / 2.0), a.pos.y - (a.area.y / 2.0),
		a.pos.x + (a.area.x / 2.0), a.pos.y + (a.area.y / 2.0),
		b.pos.x - (b.area.x / 2.0), b.pos.y - (b.area.y / 2.0),
		b.pos.x + (b.area.x / 2.0), b.pos.y + (b.area.y / 2.0));

	if (dist <= MIN_DIST) {
		dist = MIN_DIST;
		vec  = vec_sub(a.pos, b.pos);
	}
	return vec_mult(vec, (CHARGE_KE * 0.5 / (vec_mag(vec) * dist * dist)));
}
示例#15
0
int main(int argc, char *argv[])
{
  double t_start, t_end, t_start_OMP, t_end_OMP;

  DATA_TYPE* A;
  DATA_TYPE* B;  
  DATA_TYPE* C;  
  DATA_TYPE* C_OMP;
	
  A = (DATA_TYPE*)malloc(N*sizeof(DATA_TYPE));
  B = (DATA_TYPE*)malloc(N*sizeof(DATA_TYPE));
  C = (DATA_TYPE*)malloc(N*sizeof(DATA_TYPE));
  C_OMP = (DATA_TYPE*)malloc(N*sizeof(DATA_TYPE));

  fprintf(stdout, ">> Vector multiplication. Target Data Construct. <<\n");

  //initialize the arrays
  init(A, B);

  t_start_OMP = rtclock();
  vec_mult_OMP(A, B, C_OMP);
  t_end_OMP = rtclock();
  fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end_OMP - t_start_OMP);//);

  //initialize the arrays
  init(A, B);

  t_start = rtclock();
  vec_mult(A, B, C);
  t_end = rtclock();
  fprintf(stdout, "CPU Runtime: %0.6lfs\n", t_end - t_start);//);
	
  compareResults(C, C_OMP);

  free(A);
  free(B);
  free(C);
  free(C_OMP);
	
  return 0;
}
示例#16
0
文件: e.51.7.c 项目: AlexMioMio/gcc
int main ()
{
  short *p1 = (short *) malloc (MAX * sizeof (short));
  short *p2 = (short *) malloc (MAX * sizeof (short));
  short *v1 = (short *) malloc (MAX * sizeof (short));
  short *v2 = (short *) malloc (MAX * sizeof (short));

  init (v1, v2, MAX);

  vec_mult_ref (p1, v1, v2, MAX);
  vec_mult (p2, v1, v2, MAX);

  check (p1, p2, MAX);

  free (p1);
  free (p2);
  free (v1);
  free (v2);

  return 0;
}
示例#17
0
文件: ga_shading.c 项目: fvdsn/gally
/* Computes metallic reflection */
static void ga_shade_reflect(vec_t *color,const ga_scene_t *s, const ga_material_t *mat,const vec_t *pos, const vec_t *dir, const vec_t *norm, float importance, int max_rec){
	vec_t r,d1,d2,dr;
	vec_t rcolor;
	int sample = mat->soft_ref_sample;
	int i;
	r = vec_sub(*dir,vec_scale(2.0f*vec_dot(*norm,*dir),*norm));
	vec_fperp(&r,&d1,&d2);
	if(sample <= 0){
		sample = 1;
	}
	i = sample;
	while(i--){
		dr = r;
		vec_ffadd(&dr,mat->soft_ref_angle*(2.0f*random()*RAND_NORM) -1.0f,&d1);
		vec_ffadd(&dr,mat->soft_ref_angle*(2.0f*random()*RAND_NORM) -1.0f,&d2);
		vec_fnorm(&dr);
		rcolor = vec_add(rcolor,
				vec_scale(mat->ref_factor,vec_mult(mat->ref_color,
				ga_ray_trace(s,*pos,dr,importance,max_rec -1, NULL))));
	}
	*color = vec_add(*color,vec_scale(1.0f/sample,rcolor));
}
示例#18
0
void tracer_build(raytracer *tracer){
	int ne,i,j;
	const int pairs[6][2]={{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}};

	float3 *nodes;
	int *elems,ebase;
	int e1,e0;
	float Rn2;

	if(tracer->d || tracer->m || tracer->n || tracer->mesh==NULL) return;

        if(tracer->mesh->node==NULL||tracer->mesh->elem==NULL||
	   tracer->mesh->facenb==NULL||tracer->mesh->med==NULL)
                MESH_ERROR("mesh is missing");

	ne=tracer->mesh->ne;
	nodes=tracer->mesh->node;
	elems=(int *)(tracer->mesh->elem); // convert int4* to int*
	if(tracer->method==rtPlucker){
		int ea,eb,ec;
		float3 vecAB={0.f},vecAC={0.f};

		tracer->d=(float3*)calloc(sizeof(float3),ne*6); // 6 edges/elem
		tracer->m=(float3*)calloc(sizeof(float3),ne*6); // 6 edges/elem
		tracer->n=(float3*)calloc(sizeof(float3),ne*4); // 4 face norms
		for(i=0;i<ne;i++){
			ebase=i<<2;
			for(j=0;j<6;j++){
				e1=elems[ebase+pairs[j][1]]-1;
				e0=elems[ebase+pairs[j][0]]-1;
				vec_diff(&nodes[e0],&nodes[e1],tracer->d+i*6+j);
				vec_cross(&nodes[e0],&nodes[e1],tracer->m+i*6+j);
			}
			for(j=0;j<4;j++){
                                ea=elems[ebase+out[j][0]]-1;
                                eb=elems[ebase+out[j][1]]-1;
				ec=elems[ebase+out[j][2]]-1;
                                vec_diff(&nodes[ea],&nodes[eb],&vecAB);
                                vec_diff(&nodes[ea],&nodes[ec],&vecAC);
				vec_cross(&vecAB,&vecAC,tracer->n+ebase+j);
				Rn2=1.f/sqrt(vec_dot(tracer->n+ebase+j,tracer->n+ebase+j));
				vec_mult(tracer->n+ebase+j,Rn2,tracer->n+ebase+j);
			}
		}
	}else if(tracer->method==rtHavel || tracer->method==rtBadouel){
		int ea,eb,ec;
		float3 vecAB={0.f},vecAC={0.f};

		tracer->d=NULL;
		tracer->m=(float3*)calloc(sizeof(float3),ne*12);
                for(i=0;i<ne;i++){
                        ebase=i<<2;
			for(j=0;j<4;j++){
				float3 *vecN=tracer->m+3*(ebase+j);

                                ea=elems[ebase+out[j][0]]-1;
                                eb=elems[ebase+out[j][1]]-1;
				ec=elems[ebase+out[j][2]]-1;
                                vec_diff(&nodes[ea],&nodes[eb],&vecAB);
                                vec_diff(&nodes[ea],&nodes[ec],&vecAC);
				vec_cross(&vecAB,&vecAC,vecN); /*N is defined as ACxAB in Jiri's code, but not the paper*/
                                vec_cross(&vecAC,vecN,vecN+1);
                                vec_cross(vecN,&vecAB,vecN+2);

				Rn2=1.f/sqrt(vec_dot(vecN,vecN));

				vec_mult(vecN,Rn2,vecN);
				
				Rn2*=Rn2;
				vec_mult(vecN+1,Rn2,vecN+1);
                                vec_mult(vecN+2,Rn2,vecN+2);
#ifdef MMC_USE_SSE
				vecN->w    = vec_dot(vecN,  &nodes[ea]);
				(vecN+1)->w=-vec_dot(vecN+1,&nodes[ea]);
                                (vecN+2)->w=-vec_dot(vecN+2,&nodes[ea]);
#endif
			}
                }
	}else if(tracer->method==rtBLBadouel){
		int ea,eb,ec;
		float3 vecAB={0.f},vecAC={0.f},vN={0.f};

		tracer->d=NULL;
		tracer->n=(float3*)calloc(sizeof(float3),ne*4);
                for(i=0;i<ne;i++){
                        ebase=i<<2;
			float *vecN=&(tracer->n[ebase].x);
			for(j=0;j<4;j++){
                                ea=elems[ebase+out[j][0]]-1;
                                eb=elems[ebase+out[j][1]]-1;
				ec=elems[ebase+out[j][2]]-1;
                                vec_diff(&nodes[ea],&nodes[eb],&vecAB);
                                vec_diff(&nodes[ea],&nodes[ec],&vecAC);

				vec_cross(&vecAB,&vecAC,&vN); /*N is defined as ACxAB in Jiri's code, but not the paper*/

				Rn2=1.f/sqrt(vec_dot(&vN,&vN));
				vec_mult(&vN,Rn2,&vN);

				vecN[j]=vN.x;
				vecN[j+4]=vN.y;
				vecN[j+8]=vN.z;
#ifdef MMC_USE_SSE
				vecN[j+12]    = vec_dot(&vN, &nodes[ea]);
#endif
			}
                }
	}
}
示例#19
0
color_t shootRay(ray_t ray, intersect_t *intersect, int recursionCount) {
  rayIntersectionTest(ray, intersect);
  if (intersect->t > 0) { // We hit something
    color_t color;
    GeomType geomType = intersect->geomType;
    void *geomObject = intersect->object;
    bool reflective = false;

    // Check the material
    if (geomType == GeomTypeTriangle) {
      triangle_t *temp = (triangle_t *)geomObject;
      color = temp->material.color;
      reflective = temp->material.reflective;
    }
    else if (geomType == GeomTypeSphere) {
      sphere_t *temp = (sphere_t *)geomObject;
      color = temp->material.color;
      reflective = temp->material.reflective;
    } else if (geomType == GeomTypeLight) {
      return rgb(255, 255, 255);
    }

    // Get a normal where we intersected
    vec_t normal;
    if (geomType == GeomTypeTriangle) {
      triangle_t *temp = (triangle_t *)geomObject;
      normal = temp->normal;
    }
    else if (geomType == GeomTypeSphere) {
      sphere_t *temp = (sphere_t *)geomObject;
      normal = sphere_normal_at_point(*temp, intersect->point);
    }

    if (reflective && recursionCount < 10) {
      // First find the reflected ray
      vec_t r = vec_sub(ray.direction, vec_mult(normal, 2 * vec_dot(normal, ray.direction)));
      point_t start = point_offset(intersect->point, vec_mult(r, 0.0001));
      ray_t reflectedRay = ray_new(start, r);
      // Shoot out a new ray and take its color
      color = shootRay(reflectedRay, intersect, recursionCount + 1);
    } else if (!reflective) {
      point_t sPos = intersect->point;
      ray_t sRay;
      float totalDiffuse = 0;
      for (int m = 0; m < numLights; m++) {
        if (lights[m].size == 0) {
          sRay = ray_to_light(lights[m], sPos);
          sRay.point = point_offset(sRay.point, vec_mult(sRay.direction, 0.0001));
          rayIntersectionNonLightTest(sRay, intersect);

          if (intersect->t <= 0) { // We did't hit anything, diffuse like normal
            totalDiffuse += fabsf(vec_dot(sRay.direction, normal));
          } // Otherwise, we're in shadow
        } else {
          float lightRays = 100 * lights[m].size;
          float lightDiffuse = 0;
          for (int l = 0; l < lightRays; l++) {
            sRay = ray_to_light(lights[m], sPos);
            sRay.point = point_offset(sRay.point, vec_mult(sRay.direction, 0.0001));
            rayIntersectionNonLightTest(sRay, intersect);

            if (intersect->t <= 0) {  // We didn't hit anything, diffuse like normal
              lightDiffuse += fabsf(vec_dot(sRay.direction, normal));
            } // Otherwise, we're in shadow
          }

          totalDiffuse += lightDiffuse / lightRays;
        }
      }

      totalDiffuse /= numLights;  // We want the total intensity of lights to be the
                                  // same no matter how many we have

      if (totalDiffuse < 0.2) totalDiffuse = 0.2;
      if (totalDiffuse > 1) totalDiffuse = 1;
      color.r *= totalDiffuse;
      color.g *= totalDiffuse;
      color.b *= totalDiffuse;
    }

    return color;
  }
  // No intersection, color black
  return rgb(0, 0, 0);
}
示例#20
0
文件: ga_shading.c 项目: fvdsn/gally
/* flat shading (doesn't depend on normal) */
static void ga_shade_flat(vec_t *color, const ga_material_t *mat, const vec_t *lcolor,float factor){
	*color = vec_add(*color,vec_scale(mat->flat_factor*factor,vec_mult(mat->flat_color,*lcolor)));
}