Esempio n. 1
0
t_obj	*inter2(t_scene *scene, t_vector3f d, t_vector3f o)
{
	float		t;
	float		t2;
	t_objl		*l;
	t_obj		*obj;
	t_vector3f	tmp[2];

	l = scene->objl;
	t = -1;
	obj = NULL;
	while (l)
	{
		tmp[0] = get_transforms(o, inv3(l->obj->pos), conjugate4(l->obj->rot));
		tmp[1] = get_transforms(d, rgb(0, 0, 0), conjugate4(l->obj->rot));
		t2 = scene->tab_type[l->obj->type](tmp[0], *l->obj, tmp[1]);
		if (t2 > 0 && (t2 < t || t == -1))
		{
			t = t2;
			obj = l->obj;
		}
		l = l->next;
	}
	if (obj && t > 0)
		return (obj);
	return (NULL);
}
Esempio n. 2
0
t_obj	*get_inter(t_obj *obj, float t, t_vector3f *inter, t_vector3f ray_o)
{
	if (obj && t > 0)
	{
		*inter = mul3f(obj->cam->ray, t);
		*inter = get_transforms(*inter, new_vector3f(0, 0, 0), obj->rot);
		*inter = get_transforms(*inter, ray_o, new_quaternion4f(0, 0, 0, 1));
		return (obj);
	}
	return (NULL);
}
Esempio n. 3
0
    void NeighborSearch<Scalar>::clear_initial_sub_idx()
    {
      _F_;
      if(neighborhood_type != H2D_DG_GO_DOWN)
        return;
      // Obtain the transformations sequence.
      Hermes::vector<unsigned int> transformations = get_transforms(original_central_el_transform);
      // Test for active element.
      if(transformations.empty())
        return;

      for(unsigned int i = 0; i < n_neighbors; i++)
      {
        // Find the index where the additional subelement mapping (on top of the initial one from assembling) starts.
        unsigned int j = 0;
        // Note that we do not have to test if central_transformations is empty or how long it is, because it has to be
        // longer than transformations (and that is tested).
        // Also the function compatible_transformations() does not have to be used, as now the array central_transformations
        // has been adjusted so that it contains the array transformations.
        while(central_transformations.get(i)->transf[j] == transformations[j])
          if(++j > transformations.size() - 1)
            break;
        central_transformations.get(i)->strip_initial_transformations(j);
      }
    }
Esempio n. 4
0
    void NeighborSearch<Scalar>::set_active_edge_multimesh(const int& edge)
    {
      _F_;
      Hermes::vector<unsigned int> transformations = get_transforms(original_central_el_transform);
      // Inter-element edge.
      if(is_inter_edge(edge, transformations))
      {
        set_active_edge(edge);
        update_according_to_sub_idx(transformations);
      }
      // Intra-element edge.
      else
      {
        neighb_el = central_el;

        neighbor_transformations.add(new Transformations(transformations), 0);

        neighbor_edge.local_num_of_edge = active_edge = edge;
        NeighborEdgeInfo local_edge_info;
        local_edge_info.local_num_of_edge = neighbor_edge.local_num_of_edge;
        // The "opposite" view of the same edge has the same orientation.
        local_edge_info.orientation = 0;
        neighbor_edges.push_back(local_edge_info);

        n_neighbors = 1;
        neighbors.push_back(neighb_el);
        neighborhood_type = H2D_DG_NO_TRANSF;
      }
      return;
    }
Esempio n. 5
0
void	add_cam(t_obj **obj, t_vector3f ray_d, t_vector3f ray_o)
{
	t_camera		*cam;
	t_quaternion	q;

	cam = NULL;
	q = conjugate4((*obj)->rot);
	if (!(*obj)->cam)
	{
		if (!(cam = (t_camera *)ft_memalloc(sizeof(t_camera))))
			return ;
		cam->pos = get_transforms(ray_o, inv3((*obj)->pos), q);
		cam->ray = get_transforms(ray_d, new_vector3f(0, 0, 0), q);
		(*obj)->cam = cam;
	}
	else
	{
		(*obj)->cam->pos = get_transforms(ray_o, inv3((*obj)->pos), q);
		(*obj)->cam->ray = get_transforms(ray_d, new_vector3f(0, 0, 0), q);
	}
}
Esempio n. 6
0
    void NeighborSearch<Scalar>::clear_initial_sub_idx()
    {
      if(neighborhood_type != H2D_DG_GO_DOWN)
        return;
      // Obtain the transformations sequence.
      Hermes::vector<unsigned int> transformations = get_transforms(original_central_el_transform);

      Hermes::vector<unsigned int> updated_transformations;
      for(int i = 0; i < transformations.size(); i++)
      {
        if(! ((active_edge == 0 && transformations[i] == 4) || (active_edge == 1 && transformations[i] == 7) || (active_edge == 2 && transformations[i] == 5) || (active_edge == 3 && transformations[i] == 6)) )
        {
          if(active_edge == 0 && transformations[i] == 6)
            updated_transformations.push_back(0);
          else if(active_edge == 0 && transformations[i] == 7)
            updated_transformations.push_back(1);
          else if(active_edge == 1 && transformations[i] == 4)
            updated_transformations.push_back(1);
          else if(active_edge == 1 && transformations[i] == 5)
            updated_transformations.push_back(2);
          else if(active_edge == 2 && transformations[i] == 6)
            updated_transformations.push_back(3);
          else if(active_edge == 2 && transformations[i] == 7)
            updated_transformations.push_back(2);
          else if(active_edge == 3 && transformations[i] == 4)
            updated_transformations.push_back(0);
          else if(active_edge == 3 && transformations[i] == 5)
            updated_transformations.push_back(3);
          else
            updated_transformations.push_back(transformations[i]);
        }
      }

      // Test for active element.
      if(updated_transformations.size() == 0)
        return;

      for(unsigned int i = 0; i < n_neighbors; i++)
      {
        // Find the index where the additional subelement mapping (on top of the initial one from assembling) starts.
        unsigned int j = 0;
        // Note that we do not have to test if central_transformations is empty or how long it is, because it has to be
        // longer than transformations (and that is tested).
        // Also the function compatible_transformations() does not have to be used, as now the array central_transformations
        // has been adjusted so that it contains the array transformations.
        while(central_transformations.get(i)->transf[j] == updated_transformations[j])
          if(++j > updated_transformations.size() - 1)
            break;
        if(j > central_transformations.get(i)->num_levels)
          j = central_transformations.get(i)->num_levels;

        for(unsigned int level = central_transformations.get(i)->num_levels; level < updated_transformations.size(); level++)
        {
          if(!neighbor_transformations.present(i))
            neighbor_transformations.add(new Transformations, i);

          Transformations* neighbor_transforms = neighbor_transformations.get(i);

          // Triangles.
          if(central_el->get_mode() == HERMES_MODE_TRIANGLE)
            if((active_edge == 0 && updated_transformations[level] == 0) ||
              (active_edge == 1 && updated_transformations[level] == 1) ||
              (active_edge == 2 && updated_transformations[level] == 2))
              neighbor_transforms->transf[neighbor_transforms->num_levels++] = (!neighbor_edge.orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 3);
            else
              neighbor_transforms->transf[neighbor_transforms->num_levels++] = (neighbor_edge.orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 3);
          // Quads.
          else
            if((active_edge == 0 && (updated_transformations[level] == 0 || updated_transformations[level] == 6)) ||
              (active_edge == 1 && (updated_transformations[level] == 1 || updated_transformations[level] == 4)) ||
              (active_edge == 2 && (updated_transformations[level] == 2 || updated_transformations[level] == 7)) ||
              (active_edge == 3 && (updated_transformations[level] == 3 || updated_transformations[level] == 5)))
              neighbor_transforms->transf[neighbor_transforms->num_levels++] = (!neighbor_edge.orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 4);
            else if((active_edge == 0 && (updated_transformations[level] == 1 || updated_transformations[level] == 7)) ||
              (active_edge == 1 && (updated_transformations[level] == 2 || updated_transformations[level] == 5)) ||
              (active_edge == 2 && (updated_transformations[level] == 3 || updated_transformations[level] == 6)) ||
              (active_edge == 3 && (updated_transformations[level] == 0 || updated_transformations[level] == 4)))
              neighbor_transforms->transf[neighbor_transforms->num_levels++] = (neighbor_edge.orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 4);
        }

        central_transformations.get(i)->strip_initial_transformations(j);
      }
    }