예제 #1
0
double			inter_cone(t_mesh *mesh, t_ray *ray, t_ray *m_ray)
{
	t_cone		*con;
	t_vector	pos;
	t_vector	dir;
	double		abc[3];
	double		d;

	pos = transform_pos(mesh->result, &ray->pos);
	dir = transform_dir(mesh->result, &ray->dir);
	con = &mesh->prim.cone;
	abc[0] = pow(dir.x, 2) + pow(dir.y, 2)
				- pow(dir.z, 2) * pow(tan(con->coeff), 2);
	abc[1] = (2 * (dir.x * pos.x + dir.y * pos.y))
				- (2 * dir.z * pos.z * pow(tan(con->coeff), 2));
	abc[2] = pow(pos.x, 2) + pow(pos.y, 2)
				- (pow(pos.z, 2) * pow(tan(con->coeff), 2));
	d = determinant(abc[0], abc[1], abc[2]);
	if (d >= 0.0001)
	{
		m_ray->pos = pos;
		m_ray->dir = dir;
		return (d);
	}
	return (-1);
}
예제 #2
0
파일: pawd.c 프로젝트: enukane/netbsd-src
/* getawd() is a substitute for getwd() which transforms the path */
static char *
getawd(char *path, size_t l)
{
#ifdef HAVE_GETCWD
  char *wd = getcwd(path, MAXPATHLEN);
#else /* not HAVE_GETCWD */
  char *wd = getwd(path);
#endif /* not HAVE_GETCWD */

  if (wd == NULL) {
    return NULL;
  }
  xstrlcpy(path, transform_dir(wd), l);
  return path;
}
예제 #3
0
double			inter_plan(t_mesh *mesh, t_ray *ray, t_ray *m_ray)
{
	t_plan		*plan;
	t_vector	pos;
	t_vector	dir;
	double		d;

	pos = transform_pos(mesh->result, &ray->pos);
	dir = transform_dir(mesh->result, &ray->dir);
	plan = &mesh->prim.plan;
	d = -(dot(plan->normal, pos))
		/ dot(plan->normal, dir);
	if (d >= 0.0001)
	{
		m_ray->pos = pos;
		m_ray->dir = dir;
		return (d);
	}
	return (-1);
}
예제 #4
0
파일: pawd.c 프로젝트: enukane/netbsd-src
int
main(int argc, char *argv[])
{
  char tmp_buf[MAXPATHLEN], *wd;

  if (argc == 1) {
    wd = getawd(tmp_buf, sizeof(tmp_buf));
    if (wd == NULL) {
      fprintf(stderr, "pawd: %s\n", tmp_buf);
      exit(1);
    } else {
      fprintf(stdout, "%s\n", wd);
    }
  } else {
    while (--argc) {
      wd = transform_dir(*++argv);
      fprintf(stdout, "%s\n", wd);
    }
  }
  exit(0);
}
예제 #5
0
double			inter_cylinder(t_mesh *mesh, t_ray *ray, t_ray *m_ray)
{
	t_cylinder	*cyl;
	t_vector	pos;
	t_vector	dir;
	double		abc[3];
	double		d;

	pos = transform_pos(mesh->result, &ray->pos);
	dir = transform_dir(mesh->result, &ray->dir);
	cyl = &mesh->prim.cylinder;
	abc[0] = pow(dir.x, 2) + pow(dir.y, 2);
	abc[1] = 2 * (dir.x * pos.x + dir.y * pos.y);
	abc[2] = pow(pos.x, 2) + pow(pos.y, 2) - pow(cyl->radius, 2);
	d = determinant(abc[0], abc[1], abc[2]);
	if (d >= 0.0001)
	{
		m_ray->pos = pos;
		m_ray->dir = dir;
		return (d);
	}
	return (-1);
}
예제 #6
0
double			inter_sphere(t_mesh *mesh, t_ray *ray, t_ray *m_ray)
{
	t_sphere	*sphere;
	t_vector	pos;
	t_vector	dir;
	double		abc[3];
	double		d;

	pos = transform_pos(mesh->result, &ray->pos);
	dir = transform_dir(mesh->result, &ray->dir);
	sphere = &mesh->prim.sphere;
	abc[0] = square_length(dir);
	abc[1] = 2 * dot(dir, pos);
	abc[2] = square_length(pos) - pow(sphere->radius, 2);
	d = determinant(abc[0], abc[1], abc[2]);
	if (d >= 0.0001)
	{
		m_ray->pos = pos;
		m_ray->dir = dir;
		return (d);
	}
	return (-1);
}