rtv1/src/add_plane.c

48 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_plane.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/07 21:42:30 by gbrochar #+# #+# */
/* Updated: 2019/02/21 17:11:26 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
void init_plane(t_plane *plane, t_color *c)
{
plane->o = vec(0, 0, 0);
plane->d = vec(0, 1, 0);
*c = color(255, 255, 255);
}
int add_plane(char **data, t_env *e)
{
int i;
t_plane *plane;
t_color c;
i = 0;
ft_putendl("Adding plane");
if (!(plane = (t_plane *)ft_memalloc(sizeof(t_plane))))
return (FAILURE);
init_plane(plane, &c);
while (data[i] && i < 10)
++i;
if (i > 3)
plane->o = vec(ft_atof(data[1]), ft_atof(data[2]), ft_atof(data[3]));
if (i > 6)
{
plane->d = vec(ft_atof(data[4]), ft_atof(data[5]), ft_atof(data[6]));
if (FAILURE == check_direction(plane->d))
return (FAILURE);
normalize(&plane->d);
}
if (i > 9)
c = color(ft_atoi(data[7]), ft_atoi(data[8]), ft_atoi(data[9]));
return (add_obj_node(e, (void *)plane, PLANE, c));
}