some minor changes in functions signature

This commit is contained in:
Gregory 2017-03-16 00:48:56 +02:00
parent 59c581a9ac
commit 7f902e30dc
12 changed files with 74 additions and 62 deletions

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.6) cmake_minimum_required(VERSION 3.6)
project(fdf) project(fdf)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra -O3") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra")
include_directories(inc libft/includes minilibx) # headers include_directories(inc libft/includes minilibx) # headers
link_directories(libft minilibx) # libraries link_directories(libft minilibx) # libraries
@ -21,7 +21,9 @@ set(SOURCE_FILES
src/map_routine.c src/map_routine.c
src/mat4_init_funcs.c src/mat4_init_funcs.c
src/mat4_operations.c src/mat4_operations.c
src/matrix_routine.c src/map_movement.c) # sources src/matrix_routine.c
src/map_movement.c
src/parse_input.c) # sources
add_executable(fdf ${SOURCE_FILES}) # compilation add_executable(fdf ${SOURCE_FILES}) # compilation

View file

@ -129,7 +129,7 @@ t_mat4 *viewport_mat_init(int x, int y);
t_mat4 *orth_mat_init(float r, float t, float f); t_mat4 *orth_mat_init(float r, float t, float f);
void initial_trnsf_mats(t_FDF *FDF); void initial_trnsf_mats(t_FDF *FDF);
void mat4_mult_chain(t_FDF *FDF); void mat4_mult_chain(t_trnsf *tf);
void viewport_projection_translate(t_trnsf *tf); void viewport_projection_translate(t_trnsf *tf);
void mat4_translate(t_mat4 *m, double x, double y, double z); void mat4_translate(t_mat4 *m, double x, double y, double z);
void mat4_scale(t_mat4 *m, double x, double y, double z); void mat4_scale(t_mat4 *m, double x, double y, double z);

View file

@ -19,6 +19,7 @@ void swap_init(t_swap *s)
s->swap_coord = 0; s->swap_coord = 0;
s->swap_x = 1; s->swap_x = 1;
s->swap_z = 0; s->swap_z = 0;
} }
void print_help(void) void print_help(void)
@ -41,11 +42,11 @@ int tab_length(char **tab)
int len; int len;
len = 0; len = 0;
while (*tab) if (tab)
{ while (*tab)
tab++; {
if (*tab) tab++;
len++; len++;
} }
return (len); return (len);
} }

View file

@ -83,7 +83,7 @@ void line(t_pnt p1, t_pnt p2, t_FDF *FDF)
if (p1.z > p2.z) if (p1.z > p2.z)
{ {
swap_z(&p1, &p2); swap_z(&p1, &p2);
swap.swap_z = 1; swap.swap_z = -1;
} }
line.p1 = p1; line.p1 = p1;
line.p2 = p2; line.p2 = p2;

View file

@ -9,7 +9,7 @@ int main(int argc, char **argv)
center(FDF->map); center(FDF->map);
initial_trnsf_mats(FDF); initial_trnsf_mats(FDF);
viewport_projection_translate(FDF->map->trnsf); viewport_projection_translate(FDF->map->trnsf);
mat4_mult_chain(FDF); mat4_mult_chain(FDF->map->trnsf);
transform(FDF->map->trnsf->fin, FDF->map); transform(FDF->map->trnsf->fin, FDF->map);
render(FDF); render(FDF);
mlx_hook(FDF->mw->win, 2, 5, key_hook, FDF); mlx_hook(FDF->mw->win, 2, 5, key_hook, FDF);

View file

@ -1,5 +1,26 @@
#include "fdf.h" #include "fdf.h"
int wrong_symbols(char **line)
{
char *tmp;
tmp = *line;
while (*tmp)
{
while ((*tmp == '-' || (*tmp >= '0' && *tmp <= '9') || *tmp == ',' || *tmp == 'x') && *tmp)
tmp++;
if (!tmp)
return (1);
}
return (0);
}
void wrong_map(void)
{
ft_putstr("Wrong map!\n");
quit(0);
}
char *to_str_map(char *path) char *to_str_map(char *path)
{ {
int fd; int fd;
@ -13,11 +34,25 @@ char *to_str_map(char *path)
int map_width(char **tab) int map_width(char **tab)
{ {
int width; int width;
int width_tmp;
char **line_tab; char **line_tab;
line_tab = ft_strsplit(*tab, ' '); line_tab = ft_strsplit(*tab, ' ');
width = tab_length(line_tab); width = tab_length(line_tab);
free_tab(line_tab); width_tmp = width;
tab++;
while (*tab)
{
if ((line_tab = ft_strsplit(*tab, ' ')))
{
if (wrong_symbols(line_tab))
wrong_map();
if ((width = tab_length(line_tab)) != width_tmp)
wrong_map();
}
free_tab(line_tab);
tab++;
}
return (width); return (width);
} }
@ -38,14 +73,14 @@ void to_vec_arr(char **tab, t_map *map)
map->y_max = tab_length(tab); map->y_max = tab_length(tab);
map->x_max = map_width(tab); map->x_max = map_width(tab);
map->arr_vec = malloc(sizeof(t_vec *) * (map->y_max + 1)); map->arr_vec = malloc(sizeof(t_vec *) * (map->y_max));
i = 0; i = 0;
while (i <= map->y_max) while (i < map->y_max)
{ {
j = 0; j = 0;
line = ft_strsplit(tab[i], ' '); line = ft_strsplit(tab[i], ' ');
map->arr_vec[i] = malloc(sizeof(t_vec) * (map->x_max + 1)); map->arr_vec[i] = malloc(sizeof(t_vec) * (map->x_max));
while (j <= map->x_max) while (j < map->x_max)
{ {
map->arr_vec[i][j].z = ft_atoi(line[j]); map->arr_vec[i][j].z = ft_atoi(line[j]);
map->arr_vec[i][j].x = j; map->arr_vec[i][j].x = j;
@ -73,6 +108,8 @@ t_map *map_init(char *path)
map->scale[0] = 1; map->scale[0] = 1;
map->scale[1] = 1; map->scale[1] = 1;
map->scale[2] = 1; map->scale[2] = 1;
map->low = NULL;
map->high = NULL;
if (!(str_map = to_str_map(path))) if (!(str_map = to_str_map(path)))
{ {
ft_putstr("Wrong path to a map! For help help put \"fdf --help\"\n"); ft_putstr("Wrong path to a map! For help help put \"fdf --help\"\n");
@ -83,4 +120,4 @@ t_map *map_init(char *path)
free(str_map); free(str_map);
free_tab(tab_map); free_tab(tab_map);
return (map); return (map);
} }

View file

@ -3,7 +3,7 @@
void move(t_FDF *FDF) void move(t_FDF *FDF)
{ {
recalculate_trnsf_matrs(FDF->map); recalculate_trnsf_matrs(FDF->map);
mat4_mult_chain(FDF); mat4_mult_chain(FDF->map->trnsf);
transform(FDF->map->trnsf->fin, FDF->map); transform(FDF->map->trnsf->fin, FDF->map);
mlx_destroy_image(FDF->mw->mlx, FDF->image); mlx_destroy_image(FDF->mw->mlx, FDF->image);
FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT); FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT);

View file

@ -6,10 +6,10 @@ void transform(t_mat4 *mat, t_map *map)
int j; int j;
i = 0; i = 0;
while (i <= map->y_max) while (i < map->y_max)
{ {
j = 0; j = 0;
while (j <= map->x_max) while (j < map->x_max)
{ {
vec_mat_mult(mat, &map->arr_vec[i][j], &map->arr_pnt[i][j]); vec_mat_mult(mat, &map->arr_vec[i][j], &map->arr_pnt[i][j]);
j++; j++;
@ -30,10 +30,10 @@ void center(t_map *map)
d_y = map->y_max / 2.0f; d_y = map->y_max / 2.0f;
d_z = map->z_max / 2.0f; d_z = map->z_max / 2.0f;
i = 0; i = 0;
while (i <= map->y_max) while (i < map->y_max)
{ {
j = 0; j = 0;
while (j <= map->x_max) while (j < map->x_max)
{ {
map->arr_vec[i][j].z -= d_z; map->arr_vec[i][j].z -= d_z;
map->arr_vec[i][j].x -= d_x; map->arr_vec[i][j].x -= d_x;

View file

@ -54,12 +54,10 @@ void viewport_projection_translate(t_trnsf *tf)
free(tmp); free(tmp);
} }
void mat4_mult_chain(t_FDF *FDF) void mat4_mult_chain(t_trnsf *tf)
{ {
t_trnsf *tf;
t_mat4 *tmp; t_mat4 *tmp;
tf = FDF->map->trnsf;
tmp = tf->fin; tmp = tf->fin;
tf->fin = mat4_mult(tf->zr, tf->vp_pr_tr); tf->fin = mat4_mult(tf->zr, tf->vp_pr_tr);
free(tmp); free(tmp);

View file

@ -37,14 +37,14 @@ static void parse_heatmap(char *hm, t_color **low, t_color **high)
*low = malloc(sizeof(t_color)); *low = malloc(sizeof(t_color));
*high = malloc(sizeof(t_color)); *high = malloc(sizeof(t_color));
hm_tab = ft_strsplit(hm, '-'); hm_tab = ft_strsplit(hm, '-');
if ((tab_length(hm_tab) != 1)) if ((tab_length(hm_tab) != 2))
{ {
wrong_heatmap(low, high); wrong_heatmap(low, high);
return ; return ;
} }
low_tab = ft_strsplit(hm_tab[0], ','); low_tab = ft_strsplit(hm_tab[0], ',');
high_tab = ft_strsplit(hm_tab[1], ','); high_tab = ft_strsplit(hm_tab[1], ',');
if (tab_length(low_tab) != 2 || tab_length(high_tab) != 2) if (tab_length(low_tab) != 3 || tab_length(high_tab) != 3)
{ {
wrong_heatmap(low, high); wrong_heatmap(low, high);
return ; return ;

View file

@ -6,13 +6,13 @@ void pnt_init(t_map *map)
int j; int j;
float z; float z;
map->arr_pnt = malloc(sizeof(t_pnt *) * (map->y_max + 1)); map->arr_pnt = malloc(sizeof(t_pnt *) * (map->y_max));
i = 0; i = 0;
while (i <= map->y_max) while (i < map->y_max)
{ {
map->arr_pnt[i] = malloc(sizeof(t_pnt) * (map->x_max + 1)); map->arr_pnt[i] = malloc(sizeof(t_pnt) * (map->x_max));
j = 0; j = 0;
while (j <= map->x_max) while (j < map->x_max)
{ {
z = map->arr_vec[i][j].z - map->z_min; z = map->arr_vec[i][j].z - map->z_min;
map->arr_pnt[i][j].z = z; map->arr_pnt[i][j].z = z;

View file

@ -8,16 +8,16 @@ void render(t_FDF *FDF)
map = FDF->map; map = FDF->map;
i = 0; i = 0;
while (i <= map->y_max) while (i < map->y_max)
{ {
j = 0; j = 0;
while (j <= map->x_max) while (j < map->x_max)
{ {
if (i == map->y_max && j < map->x_max) if (i == map->y_max - 1 && j < map->x_max - 1)
line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], FDF); line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], FDF);
else if (i < map->y_max && j == map->x_max) else if (i < map->y_max - 1 && j == map->x_max - 1)
line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], FDF); line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], FDF);
else if (i < map->y_max && j < map->x_max) else if (i < map->y_max - 1 && j < map->x_max - 1)
{ {
line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], FDF); line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], FDF);
line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], FDF); line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], FDF);
@ -27,30 +27,4 @@ void render(t_FDF *FDF)
i++; i++;
} }
mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0); mlx_put_image_to_window(FDF->mw->mlx, FDF->mw->win, FDF->image, 0, 0);
} }
// usleep(10000000);
// int i = 0;
// while (i < 720)
// {
// usleep(14000);
// mlx_destroy_image(FDF->mw->mlx, FDF->image);
// FDF->image = mlx_new_image(FDF->mw->mlx, FDF->w_height, FDF->w_height);
// FDF->image_data = mlx_get_data_addr(
// FDF->image,
// &FDF->bpp,
// &FDF->line_size,
// &FDF->endian);
// tmp = tf->vp_pr_tr;
// mat4_x_rot(tf->xr, 30);
// mat4_z_rot(tf->zr, -45 + i);
// mat4_y_rot(tf->yr, -20 + i);
// tmp = mat4_mult(tf->zr, tmp);
// tmp = mat4_mult(tf->xr, tmp);
// tmp = mat4_mult(tf->yr, tmp);
// tmp = mat4_mult(tf->sc, tmp);
// transform(tmp, FDF->map);
// draw(FDF);
// i++;
// }