color gradient done

This commit is contained in:
Gregory 2017-03-12 15:18:37 +02:00
parent 2d243b3d57
commit 516477ded7
4 changed files with 11 additions and 12 deletions

View file

@ -59,9 +59,9 @@ t_color choose_color(t_line *line, t_swap *s, t_FDF *FDF)
void first_color(t_pnt *pnt, float z, t_map *map) void first_color(t_pnt *pnt, float z, t_map *map)
{ {
if (z == map->z_min) if (z == 0)
pnt->color = int_to_color(COLOR1); pnt->color = int_to_color(COLOR1);
if (z == map->z_max) if (z == map->z_max - map->z_min)
pnt->color = int_to_color(COLOR2); pnt->color = int_to_color(COLOR2);
else else
pnt->color = color_lerp( pnt->color = color_lerp(

View file

@ -2,27 +2,26 @@
void pnt_init(t_map *map) void pnt_init(t_map *map)
{ {
t_pnt **arr_pnt;
t_list *lst_map; t_list *lst_map;
int i; int i;
int j; int j;
float z; float z;
lst_map = map->lst_map; lst_map = map->lst_map;
arr_pnt = malloc(sizeof(t_pnt *) * (map->y_max + 1)); map->arr_pnt = malloc(sizeof(t_pnt *) * (map->y_max + 1));
i = 0; i = 0;
while (i <= map->y_max) while (i <= map->y_max && lst_map)
{ {
map->arr_pnt[i] = malloc(sizeof(t_pnt) * (map->x_max + 1));
j = 0; j = 0;
arr_pnt[i] = malloc(sizeof(t_pnt) * (map->x_max + 1));
while (j <= map->x_max) while (j <= map->x_max)
{ {
z = ((t_vec *)(lst_map->content))->z; z = ((t_vec *)(lst_map->content))->z - map->z_min;
arr_pnt[i][j].z = z; map->arr_pnt[i][j].z = z;
first_color(&arr_pnt[i][j], z, map); first_color(&map->arr_pnt[i][j], z, map);
lst_map = lst_map->next; lst_map = lst_map->next;
j++; j++;
} }
i++; i++;
} }
map->arr_pnt = arr_pnt;
} }

View file

@ -167,7 +167,7 @@ void render(t_FDF *FDF)
mat4_x_rot(rot_x, 30); mat4_x_rot(rot_x, 30);
mat4_z_rot(rot_z, -45); mat4_z_rot(rot_z, -45);
mat4_y_rot(rot_y, -20); mat4_y_rot(rot_y, -20);
mat4_scale(scale, 0.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