some minor changes in functions signature
This commit is contained in:
parent
59c581a9ac
commit
7f902e30dc
12 changed files with 74 additions and 62 deletions
|
@ -1,7 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.6)
|
||||
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
|
||||
link_directories(libft minilibx) # libraries
|
||||
|
@ -21,7 +21,9 @@ set(SOURCE_FILES
|
|||
src/map_routine.c
|
||||
src/mat4_init_funcs.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
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ t_mat4 *viewport_mat_init(int x, int y);
|
|||
|
||||
t_mat4 *orth_mat_init(float r, float t, float f);
|
||||
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 mat4_translate(t_mat4 *m, double x, double y, double z);
|
||||
void mat4_scale(t_mat4 *m, double x, double y, double z);
|
||||
|
|
|
@ -19,6 +19,7 @@ void swap_init(t_swap *s)
|
|||
s->swap_coord = 0;
|
||||
s->swap_x = 1;
|
||||
s->swap_z = 0;
|
||||
|
||||
}
|
||||
|
||||
void print_help(void)
|
||||
|
@ -41,10 +42,10 @@ int tab_length(char **tab)
|
|||
int len;
|
||||
|
||||
len = 0;
|
||||
if (tab)
|
||||
while (*tab)
|
||||
{
|
||||
tab++;
|
||||
if (*tab)
|
||||
len++;
|
||||
}
|
||||
return (len);
|
||||
|
|
|
@ -83,7 +83,7 @@ void line(t_pnt p1, t_pnt p2, t_FDF *FDF)
|
|||
if (p1.z > p2.z)
|
||||
{
|
||||
swap_z(&p1, &p2);
|
||||
swap.swap_z = 1;
|
||||
swap.swap_z = -1;
|
||||
}
|
||||
line.p1 = p1;
|
||||
line.p2 = p2;
|
||||
|
|
|
@ -9,7 +9,7 @@ int main(int argc, char **argv)
|
|||
center(FDF->map);
|
||||
initial_trnsf_mats(FDF);
|
||||
viewport_projection_translate(FDF->map->trnsf);
|
||||
mat4_mult_chain(FDF);
|
||||
mat4_mult_chain(FDF->map->trnsf);
|
||||
transform(FDF->map->trnsf->fin, FDF->map);
|
||||
render(FDF);
|
||||
mlx_hook(FDF->mw->win, 2, 5, key_hook, FDF);
|
||||
|
|
|
@ -1,5 +1,26 @@
|
|||
#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)
|
||||
{
|
||||
int fd;
|
||||
|
@ -13,11 +34,25 @@ char *to_str_map(char *path)
|
|||
int map_width(char **tab)
|
||||
{
|
||||
int width;
|
||||
int width_tmp;
|
||||
char **line_tab;
|
||||
|
||||
line_tab = ft_strsplit(*tab, ' ');
|
||||
width = tab_length(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);
|
||||
}
|
||||
|
||||
|
@ -38,14 +73,14 @@ void to_vec_arr(char **tab, t_map *map)
|
|||
|
||||
map->y_max = tab_length(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;
|
||||
while (i <= map->y_max)
|
||||
while (i < map->y_max)
|
||||
{
|
||||
j = 0;
|
||||
line = ft_strsplit(tab[i], ' ');
|
||||
map->arr_vec[i] = malloc(sizeof(t_vec) * (map->x_max + 1));
|
||||
while (j <= map->x_max)
|
||||
map->arr_vec[i] = malloc(sizeof(t_vec) * (map->x_max));
|
||||
while (j < map->x_max)
|
||||
{
|
||||
map->arr_vec[i][j].z = ft_atoi(line[j]);
|
||||
map->arr_vec[i][j].x = j;
|
||||
|
@ -73,6 +108,8 @@ t_map *map_init(char *path)
|
|||
map->scale[0] = 1;
|
||||
map->scale[1] = 1;
|
||||
map->scale[2] = 1;
|
||||
map->low = NULL;
|
||||
map->high = NULL;
|
||||
if (!(str_map = to_str_map(path)))
|
||||
{
|
||||
ft_putstr("Wrong path to a map! For help help put \"fdf --help\"\n");
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
void move(t_FDF *FDF)
|
||||
{
|
||||
recalculate_trnsf_matrs(FDF->map);
|
||||
mat4_mult_chain(FDF);
|
||||
mat4_mult_chain(FDF->map->trnsf);
|
||||
transform(FDF->map->trnsf->fin, FDF->map);
|
||||
mlx_destroy_image(FDF->mw->mlx, FDF->image);
|
||||
FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT);
|
||||
|
|
|
@ -6,10 +6,10 @@ void transform(t_mat4 *mat, t_map *map)
|
|||
int j;
|
||||
|
||||
i = 0;
|
||||
while (i <= map->y_max)
|
||||
while (i < map->y_max)
|
||||
{
|
||||
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]);
|
||||
j++;
|
||||
|
@ -30,10 +30,10 @@ void center(t_map *map)
|
|||
d_y = map->y_max / 2.0f;
|
||||
d_z = map->z_max / 2.0f;
|
||||
i = 0;
|
||||
while (i <= map->y_max)
|
||||
while (i < map->y_max)
|
||||
{
|
||||
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].x -= d_x;
|
||||
|
|
|
@ -54,12 +54,10 @@ void viewport_projection_translate(t_trnsf *tf)
|
|||
free(tmp);
|
||||
}
|
||||
|
||||
void mat4_mult_chain(t_FDF *FDF)
|
||||
void mat4_mult_chain(t_trnsf *tf)
|
||||
{
|
||||
t_trnsf *tf;
|
||||
t_mat4 *tmp;
|
||||
|
||||
tf = FDF->map->trnsf;
|
||||
tmp = tf->fin;
|
||||
tf->fin = mat4_mult(tf->zr, tf->vp_pr_tr);
|
||||
free(tmp);
|
||||
|
|
|
@ -37,14 +37,14 @@ static void parse_heatmap(char *hm, t_color **low, t_color **high)
|
|||
*low = malloc(sizeof(t_color));
|
||||
*high = malloc(sizeof(t_color));
|
||||
hm_tab = ft_strsplit(hm, '-');
|
||||
if ((tab_length(hm_tab) != 1))
|
||||
if ((tab_length(hm_tab) != 2))
|
||||
{
|
||||
wrong_heatmap(low, high);
|
||||
return ;
|
||||
}
|
||||
low_tab = ft_strsplit(hm_tab[0], ',');
|
||||
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);
|
||||
return ;
|
||||
|
|
|
@ -6,13 +6,13 @@ void pnt_init(t_map *map)
|
|||
int j;
|
||||
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;
|
||||
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;
|
||||
while (j <= map->x_max)
|
||||
while (j < map->x_max)
|
||||
{
|
||||
z = map->arr_vec[i][j].z - map->z_min;
|
||||
map->arr_pnt[i][j].z = z;
|
||||
|
|
36
src/render.c
36
src/render.c
|
@ -8,16 +8,16 @@ void render(t_FDF *FDF)
|
|||
|
||||
map = FDF->map;
|
||||
i = 0;
|
||||
while (i <= map->y_max)
|
||||
while (i < map->y_max)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
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][j + 1], FDF);
|
||||
|
@ -28,29 +28,3 @@ void render(t_FDF *FDF)
|
|||
}
|
||||
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++;
|
||||
// }
|
||||
|
|
Loading…
Add table
Reference in a new issue