Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrid Geels committed Mar 14, 2022
1 parent d8265b4 commit b6eed1a
Show file tree
Hide file tree
Showing 62 changed files with 1,946 additions and 147 deletions.
Binary file removed MLX42/lib/glad/glad.o
Binary file not shown.
Binary file removed MLX42/lib/png/lodepng.o
Binary file not shown.
Binary file removed MLX42/libmlx42.a
Binary file not shown.
Binary file removed MLX42/src/font/mlx_font.o
Binary file not shown.
Binary file removed MLX42/src/mlx_cursor.o
Binary file not shown.
Binary file removed MLX42/src/mlx_exit.o
Binary file not shown.
26 changes: 0 additions & 26 deletions MLX42/src/mlx_frag.c

This file was deleted.

Binary file removed MLX42/src/mlx_frag.o
Binary file not shown.
Binary file removed MLX42/src/mlx_images.o
Binary file not shown.
Binary file removed MLX42/src/mlx_init.o
Binary file not shown.
Binary file removed MLX42/src/mlx_keys.o
Binary file not shown.
Binary file removed MLX42/src/mlx_loop.o
Binary file not shown.
Binary file removed MLX42/src/mlx_monitor.o
Binary file not shown.
Binary file removed MLX42/src/mlx_mouse.o
Binary file not shown.
Binary file removed MLX42/src/mlx_putpixel.o
Binary file not shown.
Binary file removed MLX42/src/mlx_shader.o
Binary file not shown.
28 changes: 0 additions & 28 deletions MLX42/src/mlx_vert.c

This file was deleted.

Binary file removed MLX42/src/mlx_vert.o
Binary file not shown.
Binary file removed MLX42/src/mlx_window.o
Binary file not shown.
Binary file removed MLX42/src/textures/mlx_png.o
Binary file not shown.
Binary file removed MLX42/src/textures/mlx_texture.o
Binary file not shown.
Binary file removed MLX42/src/textures/mlx_xpm42.o
Binary file not shown.
Binary file removed MLX42/src/textures/mlx_xpm42_utils.o
Binary file not shown.
Binary file removed MLX42/src/utils/mlx_hash.o
Binary file not shown.
Binary file removed MLX42/src/utils/mlx_image_utils.o
Binary file not shown.
Binary file removed MLX42/src/utils/mlx_list.o
Binary file not shown.
Binary file removed MLX42/src/utils/mlx_list_utils.o
Binary file not shown.
Binary file removed MLX42/src/utils/mlx_log.o
Binary file not shown.
Binary file removed MLX42/src/utils/mlx_utils.o
Binary file not shown.
Binary file removed MLX42/src/utils/mlx_window_utils.o
Binary file not shown.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME := fdf
CFLAGS := -Wall -Werror -Wextra
CFLAGS := -g -Wall -Werror -Wextra
SRC = src/main.c\
src/fill.c\
src/wrap.c\
Expand Down Expand Up @@ -27,13 +27,13 @@ libmlx42.a :

obj/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC) -Imlx -o $@ -c $< -I MLX42/include -I ./
$(CC) $(CFLAGS) -Imlx -o $@ -c $< -I MLX42/include -I ./

$(NAME) : $(OBJ) libmlx42.a
$(CC) $(OBJ) libmlx42.a -lglfw -L "/Users/$(USER)/.brew/opt/glfw/lib/" -o $(NAME)

clean:
@test -e obj && rm -fr obj && rm -fr libmlx42.a || echo "$(GREEN)clean: No objects to clean$(RESET)"''
@test -e obj && rm -fr obj && rm -fr libmlx42.a && make fclean -C MLX42/ || echo "$(GREEN)clean: No objects to clean$(RESET)"''

fclean : clean
rm -f $(NAME)
Expand Down
Binary file added fdf
Binary file not shown.
27 changes: 12 additions & 15 deletions fdflib.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@
/* By: ageels <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/03/02 22:03:13 by ageels #+# #+# */
/* Updated: 2022/03/02 22:03:16 by ageels ######## odam.nl */
/* Updated: 2022/03/14 17:56:25 by ageels ######## odam.nl */
/* */
/* ************************************************************************** */

#ifndef FDFLIB_H
# define FDFLIB_H
# include "MLX42/MLX42.h"
# include <stdlib.h>
# include <math.h>
# include "get_next_line_copy/get_next_line.h"
# include <fcntl.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
# include <sys/uio.h>
# include <math.h>

# define WIDTH 2000
# define HEIGHT 900
Expand All @@ -33,13 +27,15 @@ typedef struct s_int
int j;
int fd;
char *lines;
char **dots;
char **d;
void *int_ptr;
void *start_ptr;
} t_int;

typedef struct s_map
{
t_img *img;
t_mlx *mlx;
char *path;
int hor;
int ver;
Expand All @@ -51,13 +47,14 @@ typedef struct s_map
int offsety;
int zoom;
int steepness;
float angle;
} t_map;

typedef struct s_var
{
t_mlx *my_mlx;
t_img *my_img;
t_map mapdata;
t_map *mapdata;
char *path;
} t_var;

Expand All @@ -68,15 +65,15 @@ char *ft_strjoin(char const *s1, char const *s2);
char **ft_split(char const *s, char c);
int ft_atoi(const char *str);
int ft_isdigit(int c);
void ft_map(char *path, t_map mdata, t_img *my_img, t_mlx *my_mlx);
t_map ft_scan_map(t_map my_map);
int **ft_make_map(t_map map);
int ft_map(char *path, t_map *mdata, t_img *my_img, t_mlx *my_mlx);
int ft_scan_map(t_map *my_map);
int **ft_make_map(t_map *map);
void ft_toomanylines(t_int *te, t_map *map);
void ft_isometric(int *x, int *y, int z, int steepness);
void ft_isometric(int *x, int *y, int z, t_map *mapdata);
void ft_draw(int **map, t_map *mapdata, t_img *img, t_mlx *mlx);
void ft_line(t_img *img, t_map *mapdata);
void ft_stop(t_mlx *my_mlx);
int ft_strncmp(const char *s1, const char *s2, size_t n);
void ft_pixelputwrap(t_img *img, int x, int y, unsigned int color);
void ft_pixelputwrap(t_img *img, const uint32_t x, const uint32_t y, unsigned int color);

#endif
3 changes: 1 addition & 2 deletions get_next_line_copy/get_next_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ageels <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/03/02 22:03:39 by ageels #+# #+# */
/* Updated: 2022/03/02 22:04:07 by ageels ######## odam.nl */
/* Updated: 2022/03/14 17:46:40 by ageels ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -17,7 +17,6 @@
# include <sys/types.h>
# include <sys/uio.h>
# include <stdlib.h>
# include <stdio.h>
# define BUFFER_SIZE 4

char *get_next_line(int fd);
Expand Down
44 changes: 29 additions & 15 deletions src/keypress.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ageels <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/02/11 18:18:32 by ageels #+# #+# */
/* Updated: 2022/03/02 22:04:27 by ageels ######## odam.nl */
/* Updated: 2022/03/14 18:19:28 by ageels ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -17,13 +17,13 @@ void ft_movey(t_mlx_key_cbdata keydata, t_var *var)
if (keydata.key == MLX_KEY_UP
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS))
{
var->mapdata.offsety -= 10;
var->mapdata->offsety -= 10;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
if (keydata.key == MLX_KEY_DOWN
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS))
{
var->mapdata.offsety += 10;
var->mapdata->offsety += 10;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
}
Expand All @@ -33,47 +33,61 @@ void ft_movex(t_mlx_key_cbdata keydata, t_var *var)
if (keydata.key == MLX_KEY_LEFT
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS))
{
var->mapdata.offsetx -= 10;
var->mapdata->offsetx -= 10;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
if (keydata.key == MLX_KEY_RIGHT
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS))
{
var->mapdata.offsetx += 10;
var->mapdata->offsetx += 10;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
}

void ft_zoom(t_mlx_key_cbdata keydata, t_var *var)
void ft_zoomangle(t_mlx_key_cbdata keydata, t_var *var)
{
if (keydata.key == MLX_KEY_M
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS)
&& var->mapdata.zoom > 1)
&& var->mapdata->zoom > 1)
{
var->mapdata.zoom -= 2;
var->mapdata->zoom -= 2;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
if (keydata.key == MLX_KEY_P
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS))
{
var->mapdata.zoom += 2;
var->mapdata->zoom += 2;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
if (keydata.key == MLX_KEY_X
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS)
&& var->mapdata->angle > 0.1)
{
var->mapdata->angle -= 0.1;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
}

void ft_steep(t_mlx_key_cbdata keydata, t_var *var)
void ft_steepangle(t_mlx_key_cbdata keydata, t_var *var)
{
if (keydata.key == MLX_KEY_S
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS))
{
var->mapdata.steepness += 1;
var->mapdata->steepness += 1;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
if (keydata.key == MLX_KEY_F
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS)
&& var->mapdata.steepness > 0)
&& var->mapdata->steepness > 0)
{
var->mapdata->steepness -= 1;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
if (keydata.key == MLX_KEY_Z
&& (keydata.action == MLX_REPEAT || keydata.action == MLX_PRESS)
&& var->mapdata->angle < ((M_PI / 4) - 0.1))
{
var->mapdata.steepness -= 1;
var->mapdata->angle += 0.1;
ft_map(var->path, var->mapdata, var->my_img, var->my_mlx);
}
}
Expand All @@ -87,6 +101,6 @@ void ft_keypress(t_mlx_key_cbdata keydata, void *invar)
mlx_close_window(var->my_mlx);
ft_movey(keydata, var);
ft_movex(keydata, var);
ft_zoom(keydata, var);
ft_steep(keydata, var);
ft_zoomangle(keydata, var);
ft_steepangle(keydata, var);
}
3 changes: 2 additions & 1 deletion src/libftfunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ageels <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/02/11 17:51:10 by ageels #+# #+# */
/* Updated: 2022/02/25 15:23:29 by ageels ######## odam.nl */
/* Updated: 2022/03/14 17:42:40 by ageels ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -92,3 +92,4 @@ int ft_strncmp(const char *s1, const char *s2, size_t n)
a++;
return (((const unsigned char *)s1)[a] - ((const unsigned char *)s2)[a]);
}

4 changes: 1 addition & 3 deletions src/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ageels <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/02/11 18:18:27 by ageels #+# #+# */
/* Updated: 2022/03/02 21:17:10 by ageels ######## odam.nl */
/* Updated: 2022/03/14 17:49:16 by ageels ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -70,8 +70,6 @@ void ft_line(t_img *img, t_map *mapdata)
float xd;
float yd;
float mn[2];
int mypoint[2];
float basey;

xd = mapdata->xb - mapdata->xa;
yd = mapdata->yb - mapdata->ya;
Expand Down
56 changes: 45 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,46 @@
/* By: ageels <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/02/11 16:58:15 by ageels #+# #+# */
/* Updated: 2022/03/02 21:32:48 by ageels ######## odam.nl */
/* Updated: 2022/03/14 17:54:27 by ageels ######## odam.nl */
/* */
/* ************************************************************************** */

#include "fdflib.h"
#include "MLX42/MLX42.h"

int ft_check_args(int num, char *filename)
{
if (num != 2)
{
write(1, "What map do you want?\n", 22);
return (0);
}
if (ft_strncmp(filename, "test_maps/\0", 11) == 0
|| ft_strncmp(filename, "test_maps\0", 10) == 0)
{
write(1, "issa folder", 11);
return (0);
}
return (1);
}

void ft_putmapdata(t_mlx *my_mlx, t_img *my_img, t_map *mapdata)
{
mapdata->mlx = my_mlx;
mapdata->img = my_img;
mapdata->offsetx = my_mlx->width / 2;
mapdata->offsety = my_mlx->height / 4;
mapdata->zoom = 15;
mapdata->steepness = 3;
mapdata->angle = 0.523599;
}

void ft_makevar(t_map *mapdata, char *path, t_var *my_var)
{
my_var->my_mlx = mapdata->mlx;
my_var->my_img = mapdata->img;
my_var->mapdata = mapdata;
my_var->path = path;
}

int main(int argc, char **argv)
{
Expand All @@ -20,18 +54,18 @@ int main(int argc, char **argv)
t_img *my_img;
t_map mapdata;

if (ft_check_args(argc, argv[1]) == 0)
return (0);
my_mlx = mlx_init(WIDTH, HEIGHT, "frame it", false);
my_img = mlx_new_image(my_mlx, my_mlx->width, my_mlx->height);
mapdata.offsetx = my_mlx->width / 2;
mapdata.offsety = my_mlx->height / 4;
mapdata.zoom = 15;
mapdata.steepness = 3;
ft_map(argv[1], mapdata, my_img, my_mlx);
ft_putmapdata(my_mlx, my_img, &mapdata);
if (ft_map(argv[1], &mapdata, my_img, my_mlx) == -1)
{
ft_stop(my_mlx);
return (0);
}
mlx_image_to_window(my_mlx, my_img, 0, 0);
my_var.my_mlx = my_mlx;
my_var.my_img = my_img;
my_var.mapdata = mapdata;
my_var.path = argv[1];
ft_makevar(&mapdata, argv[1], &my_var);
mlx_key_hook(my_mlx, ft_keypress, &my_var);
mlx_loop(my_mlx);
ft_stop(my_mlx);
Expand Down
Loading

0 comments on commit b6eed1a

Please sign in to comment.