separation des bonus
This commit is contained in:
19
Makefile
19
Makefile
@@ -18,13 +18,20 @@ _LIBS = libft.a
|
||||
LIBS = $(_LIBS:lib%.a=%)
|
||||
|
||||
SRCS = fdf.c \
|
||||
draw.c \
|
||||
parse.c \
|
||||
modifs.c \
|
||||
draw.c \
|
||||
keypress.c
|
||||
|
||||
SRCS_B = fdf.c \
|
||||
parse.c \
|
||||
modifs.c \
|
||||
keypress_bonus.c \
|
||||
draw_bonus.c
|
||||
|
||||
ODIR = ./builds
|
||||
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||
OBJS_B = $(SRCS_B:%.c=$(ODIR)/%.o)
|
||||
|
||||
# flag -g generates debug informations, g3 is maximal version
|
||||
CFLAGS = -I$(IDIR) -g3 -Wall -Wextra -Werror
|
||||
@@ -39,17 +46,17 @@ LFLAGS += -lm -lmlx -lXext -lX11 -L./minilibx-linux-master
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
# it verify if anything has changed in .c and .h files
|
||||
# then it makes LDIR library, then it compiles NAME
|
||||
$(NAME): $(ODIR) $(OBJS) $(DEPS)
|
||||
make -C $(LDIR)
|
||||
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||
|
||||
# create "builds/" if doesn't exist
|
||||
bonus: fclean $(ODIR) $(OBJS_B) $(DEPS)
|
||||
make -C $(LDIR)
|
||||
$(CC) $(CFLAGS) -o fdf $(OBJS_B) $(LFLAGS)
|
||||
|
||||
$(ODIR):
|
||||
mkdir -p $@
|
||||
|
||||
# if a file.c has been modified, it's recompiled in object file.o
|
||||
$(ODIR)/%.o: %.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -61,7 +68,7 @@ leaks: $(NAME)
|
||||
# valgrind --leak-check=full --leak-resolution=low --show-reachable=yes ./$(NAME) maps/42_color.fdf
|
||||
|
||||
clean:
|
||||
/bin/rm -f $(OBJS)
|
||||
/bin/rm -f $(OBJS) $(OBJS_B)
|
||||
|
||||
fclean: clean
|
||||
/bin/rm -rf $(ODIR)
|
||||
|
||||
BIN
builds/draw.o
BIN
builds/draw.o
Binary file not shown.
BIN
builds/draw_bonus.o
Normal file
BIN
builds/draw_bonus.o
Normal file
Binary file not shown.
Binary file not shown.
BIN
builds/keypress_bonus.o
Normal file
BIN
builds/keypress_bonus.o
Normal file
Binary file not shown.
@@ -18,7 +18,6 @@ void draw_image(t_fdf *fdf)
|
||||
draw_grid(fdf, i, j);
|
||||
}
|
||||
mlx_put_image_to_window(fdf->mlx_ptr, fdf->win_ptr, fdf->img_ptr, 0, 0);
|
||||
position_state(fdf);
|
||||
}
|
||||
|
||||
void draw_grid(t_fdf *fdf, int i, int j)
|
||||
|
||||
99
srcs/draw_bonus.c
Normal file
99
srcs/draw_bonus.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "fdf.h"
|
||||
|
||||
void draw_image(t_fdf *fdf)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
fdf->rad_x = fdf->rot_x * M_PI / 180;
|
||||
fdf->rad_y = fdf->rot_y * M_PI / 180;
|
||||
i = -1;
|
||||
while (++i < fdf->img_size_y * fdf->img_sizel)
|
||||
*(unsigned int *)(fdf->img_addr + i) = 0;
|
||||
j = -1;
|
||||
while (++j < fdf->map_height)
|
||||
{
|
||||
i = -1;
|
||||
while (++i < fdf->map_width)
|
||||
draw_grid(fdf, i, j);
|
||||
}
|
||||
mlx_put_image_to_window(fdf->mlx_ptr, fdf->win_ptr, fdf->img_ptr, 0, 0);
|
||||
position_state(fdf);
|
||||
}
|
||||
|
||||
void draw_grid(t_fdf *fdf, int i, int j)
|
||||
{
|
||||
int *point_start;
|
||||
int *point_end;
|
||||
|
||||
point_start = new_coordinates(fdf, i, j);
|
||||
point_end = NULL;
|
||||
if (i + 1 < fdf->map_width)
|
||||
point_end = new_coordinates(fdf, i + 1, j);
|
||||
draw_lines(fdf, point_start, point_end);
|
||||
if (j + 1 < fdf->map_height)
|
||||
{
|
||||
free(point_end);
|
||||
point_end = new_coordinates(fdf, i, j + 1);
|
||||
}
|
||||
draw_lines(fdf, point_start, point_end);
|
||||
free(point_start);
|
||||
free(point_end);
|
||||
}
|
||||
|
||||
void draw_lines(t_fdf *fdf, int *start, int *end)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
int z;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if (end)
|
||||
{
|
||||
dx = end[0] - start[0];
|
||||
dy = end[1] - start[1];
|
||||
i = 0;
|
||||
j = 0;
|
||||
z = start[2];
|
||||
while (ft_abs(i) <= ft_abs(dx) && ft_abs(j) <= ft_abs(dy))
|
||||
{
|
||||
if ((dx + dy) && (i + j))
|
||||
z = start[2] + (end[2] - start[2]) * (i + j) / (dx + dy);
|
||||
draw_color_pixel(fdf, start[0] + i, start[1] + j, z);
|
||||
if (!ft_abs(dx) || ft_abs(j) < ft_abs(i * dy / dx))
|
||||
j += ft_sign(dy);
|
||||
else
|
||||
i += ft_sign(dx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z)
|
||||
{
|
||||
int color;
|
||||
|
||||
color = 0xffffff;
|
||||
z -= (z * fdf->zoom) / fdf->offset;
|
||||
z /= fdf->altitude;
|
||||
if (z > fdf->min_z && fdf->z_amplitude)
|
||||
{
|
||||
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 16);
|
||||
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 0);
|
||||
}
|
||||
draw_pixel(fdf, new_x, new_y, color);
|
||||
}
|
||||
|
||||
void draw_pixel(t_fdf *fdf, int x, int y, int color)
|
||||
{
|
||||
int position;
|
||||
int xmax;
|
||||
int ymax;
|
||||
|
||||
xmax = fdf->img_sizel / (fdf->img_bpp / 8);
|
||||
ymax = fdf->img_size_y;
|
||||
if (x < 0 || y < 0 || x > xmax || y > ymax)
|
||||
return ;
|
||||
position = y * fdf->img_sizel + x * fdf->img_bpp / 8;
|
||||
*(unsigned int *)(fdf->img_addr + position) = color;
|
||||
}
|
||||
@@ -1,69 +1,9 @@
|
||||
#include "fdf.h"
|
||||
|
||||
/*
|
||||
** U -> up wiew
|
||||
** I -> isometric original view
|
||||
** O -> increase altitude
|
||||
** P -> decrease altitude
|
||||
** F -> fit to window
|
||||
** C -> center
|
||||
*/
|
||||
void keypress_more(int keycode, t_fdf *fdf)
|
||||
{
|
||||
if (keycode == A)
|
||||
fdf->zoom += 1;
|
||||
else if (keycode == W)
|
||||
fdf->zoom -= 1;
|
||||
else if (keycode == U)
|
||||
{
|
||||
fdf->rot_x = 0;
|
||||
fdf->rot_y = 0;
|
||||
}
|
||||
else if (keycode == I)
|
||||
{
|
||||
fdf->rot_x = -45;
|
||||
fdf->rot_y = -35;
|
||||
fdf->mov_x = (fdf->win_size_x - fdf->map_size_x) / 2;
|
||||
fdf->mov_y = (fdf->win_size_y - fdf->map_size_y) / 2;
|
||||
fdf->zoom = 0;
|
||||
}
|
||||
else if (keycode == O)
|
||||
fdf->altitude++;
|
||||
else if (keycode == P)
|
||||
if (fdf->altitude > 1)
|
||||
fdf->altitude--;
|
||||
}
|
||||
|
||||
/*
|
||||
** Q -> move left
|
||||
** D -> move right
|
||||
** Z -> move up
|
||||
** S -> move down
|
||||
** A -> zoom
|
||||
** W -> unzoom
|
||||
*/
|
||||
int keypress(int keycode, t_fdf *fdf)
|
||||
{
|
||||
if (keycode == ESCAPE)
|
||||
shut_down(fdf);
|
||||
else if (keycode == LEFT)
|
||||
fdf->rot_x += 1;
|
||||
else if (keycode == RIGHT)
|
||||
fdf->rot_x -= 1;
|
||||
else if (keycode == UP)
|
||||
fdf->rot_y += 1;
|
||||
else if (keycode == DOWN)
|
||||
fdf->rot_y -= 1;
|
||||
else if (keycode == Q)
|
||||
fdf->mov_x -= 6;
|
||||
else if (keycode == D)
|
||||
fdf->mov_x += 6;
|
||||
else if (keycode == Z)
|
||||
fdf->mov_y -= 6;
|
||||
else if (keycode == S)
|
||||
fdf->mov_y += 6;
|
||||
else
|
||||
keypress_more(keycode, fdf);
|
||||
draw_image(fdf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
69
srcs/keypress_bonus.c
Normal file
69
srcs/keypress_bonus.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "fdf.h"
|
||||
|
||||
/*
|
||||
** U -> up wiew
|
||||
** I -> isometric original view
|
||||
** O -> increase altitude
|
||||
** P -> decrease altitude
|
||||
** F -> fit to window
|
||||
** C -> center
|
||||
*/
|
||||
void keypress_more(int keycode, t_fdf *fdf)
|
||||
{
|
||||
if (keycode == A)
|
||||
fdf->zoom += 1;
|
||||
else if (keycode == W)
|
||||
fdf->zoom -= 1;
|
||||
else if (keycode == U)
|
||||
{
|
||||
fdf->rot_x = 0;
|
||||
fdf->rot_y = 0;
|
||||
}
|
||||
else if (keycode == I)
|
||||
{
|
||||
fdf->rot_x = -45;
|
||||
fdf->rot_y = -35;
|
||||
fdf->mov_x = (fdf->win_size_x - fdf->map_size_x) / 2;
|
||||
fdf->mov_y = (fdf->win_size_y - fdf->map_size_y) / 2;
|
||||
fdf->zoom = 0;
|
||||
}
|
||||
else if (keycode == O)
|
||||
fdf->altitude++;
|
||||
else if (keycode == P)
|
||||
if (fdf->altitude > 1)
|
||||
fdf->altitude--;
|
||||
}
|
||||
|
||||
/*
|
||||
** Q -> move left
|
||||
** D -> move right
|
||||
** Z -> move up
|
||||
** S -> move down
|
||||
** A -> zoom
|
||||
** W -> unzoom
|
||||
*/
|
||||
int keypress(int keycode, t_fdf *fdf)
|
||||
{
|
||||
if (keycode == ESCAPE)
|
||||
shut_down(fdf);
|
||||
else if (keycode == LEFT)
|
||||
fdf->rot_x += 1;
|
||||
else if (keycode == RIGHT)
|
||||
fdf->rot_x -= 1;
|
||||
else if (keycode == UP)
|
||||
fdf->rot_y += 1;
|
||||
else if (keycode == DOWN)
|
||||
fdf->rot_y -= 1;
|
||||
else if (keycode == Q)
|
||||
fdf->mov_x -= 6;
|
||||
else if (keycode == D)
|
||||
fdf->mov_x += 6;
|
||||
else if (keycode == Z)
|
||||
fdf->mov_y -= 6;
|
||||
else if (keycode == S)
|
||||
fdf->mov_y += 6;
|
||||
else
|
||||
keypress_more(keycode, fdf);
|
||||
draw_image(fdf);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user