示例#1
0
// vec_out = vec_in*new_norm/norm(vec_in)
void
xyz_normalize_to( xyz_t * vec_out, const double new_norm, const xyz_t * const vec_in)
{
  xyz_scale( vec_out, new_norm/(xyz_norm(vec_in) + 1e-12), vec_in );
}
示例#2
0
文件: ray.c 项目: mlisnic/ray-tracer
/* ray_position: interpreting direction as velocity, calculate position
    * of ray r after time t. 
     */
xyz ray_position(ray r, double t)
{
    return xyz_add(r.origin, xyz_scale(t, r.dir));
}
示例#3
0
// vec *= scale_factor
void
xyz_scale_self( xyz_t * vec, double scale_factor)
{
  xyz_scale(vec, scale_factor, vec);
}
示例#4
0
int main()
{
  /* xyz */
  printf(" *** testing xyz *** \n");
  xyz v = xyz_expr(1,2,3);
  xyz add = xyz_add(v,v);
  xyz vv = xyz_expr(5,5,5);
  xyz sub = xyz_sub(v,vv);
  xyz n = xyz_neg(sub);
  xyz sc = xyz_scale(1.5,v);
  xyz sc2 = xyz_scale(-3.33,n);
  double dt = xyz_dot(v,sc);
  double mag = xyz_mag(v);
  xyz z = xyz_expr(0,0,0);
  xyz zn = xyz_norm(z);
  xyz vn = xyz_norm(v);
  
  printf("xyz_expr(1,2,3) =>\t%s\n",xyz_tos(v));
  printf("(1,2,3)+(1,2,3) =>\t%s\n",xyz_tos(add));
  printf("(1,2,3)-(5,5,5) =>\t%s\n",xyz_tos(sub));
  printf("-(-4,-3,-2) =>\t%s\n",xyz_tos(n));
  printf("scale (1,2,3) by 1.5 =>\t%s\n",xyz_tos(sc));
  printf("scale (4,3,2) by -3.33 =>\t%s\n",xyz_tos(sc2));
  printf("(1,2,3)*(1.5,3,4.5) =>\t%.2lf\n",dt);
  printf("magnitude of (1,2,3) =>\t%.2lf\n",mag);
  printf("norm (0,0,0) =>\t%s\n",xyz_tos(zn));
  printf("norm (1,2,3) =>\t%s\n",xyz_tos(vn));
  printf(" *****\n");

  /* color */
  printf(" *** testing color *** \n");
  color c = color_expr(1,0.5,0);
  color cc = color_expr(0.75,0,0.25);
  color mod = color_modulate(c,cc);
  color scc = color_scale(1.5, cc);
  color addc = color_add(c,cc);

  printf("color_expr(1,0.5,0) =>\t%s\n",color_tos(c));
  printf("(1,0.5,0)*(0.75,0,0.25) =>\t%s\n",color_tos(mod));
  printf("scale (0.75,0,0.25) by 1.5 =>\t%s\n",color_tos(scc));
  printf("(1,0.5,0)+(0.75,0,0.25) =>\t%s\n",color_tos(addc));
  printf("(0.75,0,0.25) on [0,255] =>");
  color_show_bytes(stdout,cc);
  printf(" *****\n");

  /* ray */
  printf(" *** testing ray *** \n");
  ray testray = {v,vv};
  printf("ray from (1,2,3) to (5,5,5) =>\t%s\n",ray_tos(testray));
  printf(" *****\n");

  /* sphere */
  printf(" *** testing sphere *** \n");
  sphere testsph = sphere_expr(v, 3.2, get_sc, c);
  printf("sphere at (1,2,3) with radius 3.2:\n");
  sphere_show(stdout,testsph);
  printf("\n *****\n");

  /* poster */
  printf(" *** testing poster *** \n");
  poster testpst = poster_expr(v, 4, 5.25, get_sc, c);
  printf("poster at (1,2,3) with width 4 and height 5.25:\n");
  poster_show(stdout,testpst);
  printf("\n *****\n");

  /* object */
  printf(" *** testing object *** \n");
  object objs = {SPHERE,{.s = testsph},NULL};