Ejemplo n.º 1
0
void		sphere_texturing(t_obj *obj, t_3d_pos *ray,
				 double alpha, t_mat *mat)
{
  double	x;
  double	y;
  int		height;
  int		width;
  t_3d_pos	hit;

  x = alpha;
  if (obj->sphe.texture != NULL)
    {
      hit = find_hit(alpha, &ray[0], &ray[1]);
      height = (obj->sphe.texture->clipable.clip_height) * obj->sphe.y_repeat;
      width = (obj->sphe.texture->clipable.clip_width) * obj->sphe.x_repeat;
      x = width * (0.5 - (atan2(hit.z - CZ, hit.x - CX) / M_PI));
      y = height * (0.5 - (asin((hit.y - CY) / obj->sphe.rad) / M_PI));
      mat->color.full = get_texture_color(obj->sphe.texture, x, y);
    }
}
Ejemplo n.º 2
0
int add_hit(struct hitlist *hl, long label)
{
  struct hit_entry *he;

  he = find_hit(hl, label);
  
  if (he)
    {
      /* found in list, increase counter */
      he->freq++;

      /* keep list in order, higher frequencies are in the beginning. */
      while (he->prev)
	if (he->prev->freq < he->freq)
	  he = hit_swapwprev(hl, he);
	else
	  break;
    }
  else
    {
      he = malloc(sizeof(struct hit_entry));
      if (he == NULL)
	{
	  ERROR(ERR_NOMEM);
	  return 0;
	}
      /* add to end of list */
      he->next = NULL;
      he->prev = hl->tail;
      he->label = label;
      he->freq = 1;
      hl->tail = he;
      if (he->prev)
	he->prev->next = he;
      else
	hl->head = he;
      hl->entries++;
    }

  return he->freq;
}