-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
204 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: pbondoer <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2016/02/22 23:12:10 by pbondoer #+# #+# # | ||
# Updated: 2016/05/20 14:51:47 by pbondoer ### ########.fr # | ||
# Updated: 2016/06/12 05:36:57 by pbondoer ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -20,15 +20,14 @@ SRC = main.c \ | |
draw.c \ | ||
matrix.c \ | ||
mouse.c \ | ||
keyboard.c \ | ||
image.c \ | ||
lineclip.c \ | ||
zbuffer.c \ | ||
viewport.c | ||
lineclip.c | ||
|
||
OBJ = $(addprefix $(OBJDIR),$(SRC:.c=.o)) | ||
|
||
# compiler | ||
CC = clang | ||
CC = gcc | ||
CFLAGS = -Wall -Wextra -Werror -g | ||
|
||
# mlx library | ||
|
@@ -63,7 +62,7 @@ $(MLX_LIB): | |
make -C $(MLX) | ||
|
||
$(NAME): $(OBJ) | ||
$(CC) $(OBJ) $(MLX_LNK) $(FT_LNK) -o $(NAME) | ||
$(CC) $(OBJ) $(MLX_LNK) $(FT_LNK) -lm -o $(NAME) | ||
|
||
clean: | ||
rm -rf $(OBJDIR) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: pbondoer <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2016/02/22 23:59:07 by pbondoer #+# #+# */ | ||
/* Updated: 2016/05/20 14:53:51 by pbondoer ### ########.fr */ | ||
/* Updated: 2016/06/12 05:37:22 by pbondoer ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,8 +17,8 @@ | |
|
||
typedef struct s_cam | ||
{ | ||
double offsetX; | ||
double offsetY; | ||
double offsetx; | ||
double offsety; | ||
double x; | ||
double y; | ||
int scale; | ||
|
@@ -35,6 +35,8 @@ typedef struct s_map | |
{ | ||
int width; | ||
int height; | ||
int depth_min; | ||
int depth_max; | ||
t_vector **vectors; | ||
} t_map; | ||
typedef struct s_mouse | ||
|
@@ -63,6 +65,17 @@ typedef struct s_mlx | |
t_mouse *mouse; | ||
double **zbuf; | ||
} t_mlx; | ||
typedef struct s_line | ||
{ | ||
t_vector start; | ||
t_vector stop; | ||
int dx; | ||
int dy; | ||
int sx; | ||
int sy; | ||
int err; | ||
int err2; | ||
} t_line; | ||
int read_file(int fd, t_map **map); | ||
t_vector *get_vector(int x, int y, char *str); | ||
t_map *get_map(int width, int height); | ||
|
@@ -74,11 +87,12 @@ t_vector project_vector(t_vector p, t_mlx *mlx); | |
int hook_mousemove(int x, int y, t_mlx *mlx); | ||
int hook_mousedown(int button, int x, int y, t_mlx *mlx); | ||
int hook_mouseup(int button, int x, int y, t_mlx *mlx); | ||
void set_pixel(t_image *image, int x, int y, int color); | ||
int hook_keydown(int key, t_mlx *mlx); | ||
void image_set_pixel(t_image *image, int x, int y, int color); | ||
void clear_image(t_image *image); | ||
int lineclip(t_vector *p1, t_vector *p2); | ||
t_image *new_image(t_mlx *mlx); | ||
t_image *del_image(t_mlx *mlx, t_image *img); | ||
double **new_zbuffer(); | ||
double **del_zbuffer(double **zbuf); | ||
void fill_colors(t_map *m); | ||
int clerp(int c1, int c2, double p); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-10 -10 -10 | ||
-10 -10 -10 | ||
-10 -10 -10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: pbondoer <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2016/02/26 06:06:04 by pbondoer #+# #+# */ | ||
/* Updated: 2016/05/20 12:23:30 by pbondoer ### ########.fr */ | ||
/* Updated: 2016/06/12 05:22:57 by pbondoer ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,58 +23,59 @@ int clerp(int c1, int c2, double p) | |
|
||
if (c1 == c2) | ||
return (c1); | ||
|
||
r = ft_lerpi((c1 >> 16) & 0xFF, (c2 >> 16) & 0xFF, p); | ||
g = ft_lerpi((c1 >> 8) & 0xFF, (c2 >> 8) & 0xFF, p); | ||
b = ft_lerpi(c1 & 0xFF, c2 & 0xFF, p); | ||
|
||
return (r << 16 | g << 8 | b); | ||
} | ||
|
||
int line_process_point(t_mlx *mlx, t_line *l, t_vector *p1, | ||
t_vector *p2) | ||
{ | ||
double percent; | ||
|
||
if (p1->x < 0 || p1->x >= WIN_WIDTH || p1->y < 0 || p1->y >= WIN_HEIGHT | ||
|| p2->x < 0 || p2->x >= WIN_WIDTH || p2->y < 0 || p2->y >= WIN_HEIGHT) | ||
return (1); | ||
percent = (l->dx > l->dy ? | ||
ft_ilerp((int)p1->x, (int)l->start.x, (int)l->stop.x) | ||
: ft_ilerp((int)p1->y, (int)l->start.y, (int)l->stop.y)); | ||
image_set_pixel(mlx->image, (int)p1->x, (int)p1->y, clerp(p1->color, | ||
p2->color, percent)); | ||
l->err2 = l->err; | ||
if (l->err2 > -l->dx) | ||
{ | ||
l->err -= l->dy; | ||
p1->x += l->sx; | ||
} | ||
if (l->err2 < l->dy) | ||
{ | ||
l->err += l->dx; | ||
p1->y += l->sy; | ||
} | ||
return (0); | ||
} | ||
|
||
void line(t_mlx *mlx, t_vector p1, t_vector p2) | ||
{ | ||
t_line line; | ||
|
||
p1.x = (int)p1.x; | ||
p2.x = (int)p2.x; | ||
p1.y = (int)p1.y; | ||
p2.y = (int)p2.y; | ||
|
||
double startx = p1.x; | ||
double starty = p1.y; | ||
|
||
line.start = p1; | ||
line.stop = p2; | ||
if (!lineclip(&p1, &p2)) | ||
return ; | ||
|
||
int dx = ft_abs((int)p2.x - (int)p1.x); | ||
int sx = (int)p1.x < (int)p2.x ? 1 : -1; | ||
int dy = ft_abs((int)p2.y - (int)p1.y); | ||
int sy = (int)p1.y < (int)p2.y ? 1 : -1; | ||
int err = (dx > dy ? dx : -dy) / 2; | ||
int e2; | ||
|
||
double percent = 0.0f; | ||
|
||
while ((int)p1.x != (int)p2.x || (int)p1.y != (int)p2.y) | ||
{ | ||
//printf("draw: %f %f -> %f %f\n", p1.x, p1.y, p2.x, p2.y); | ||
//if ((p1.x < 0 || p1.x >= WIN_WIDTH || p1.y < 0 || p1.y >= WIN_HEIGHT) | ||
// && (p2.x < 0 || p2.x >= WIN_WIDTH || p2.y < 0 || p2.y >= WIN_HEIGHT)) | ||
// break ; | ||
percent = (dx > dy ? ft_ilerp((int)p1.x, (int)startx, (int)p2.x) : ft_ilerp((int)p1.y, (int)starty, (int)p2.y)); | ||
//printf("%f; %f - %f; %f === %f\n", p1.x, p1.y, p2.x, p2.y, percent); | ||
//mlx_pixel_put(mlx->mlx, mlx->window, (int)p1.x, (int)p1.y, clerp(p1.color, p2.color, percent)); | ||
set_pixel(mlx->image, (int)p1.x, (int)p1.y, clerp(p1.color, p2.color, percent)); | ||
e2 = err; | ||
if (e2 > -dx) | ||
{ | ||
err -= dy; | ||
p1.x += sx; | ||
} | ||
if (e2 < dy) | ||
{ | ||
err += dx; | ||
p1.y += sy; | ||
} | ||
} | ||
line.dx = (int)ft_abs((int)p2.x - (int)p1.x); | ||
line.sx = (int)p1.x < (int)p2.x ? 1 : -1; | ||
line.dy = (int)ft_abs((int)p2.y - (int)p1.y); | ||
line.sy = (int)p1.y < (int)p2.y ? 1 : -1; | ||
line.err = (line.dx > line.dy ? line.dx : -line.dy) / 2; | ||
while (((int)p1.x != (int)p2.x || (int)p1.y != (int)p2.y)) | ||
if (line_process_point(mlx, &line, &p1, &p2)) | ||
break ; | ||
} | ||
|
||
void render(t_mlx *mlx) | ||
|
@@ -85,25 +86,21 @@ void render(t_mlx *mlx) | |
t_map *map; | ||
|
||
map = mlx->map; | ||
//mlx_clear_window(mlx->mlx, mlx->window); | ||
clear_image(mlx->image); | ||
x = 0; | ||
while (x < map->width) | ||
{ | ||
y = 0; | ||
while (y < map->height) | ||
{ | ||
//printf("%d %d\n", x, y); | ||
v = project_vector(vector_at(map, x, y), mlx); | ||
if (x + 1 < map->width) | ||
line(mlx, v, project_vector(vector_at(map, x + 1, y), mlx)); | ||
if (y + 1 < map->height) | ||
line(mlx, v, project_vector(vector_at(map, x, y + 1), mlx)); | ||
//mlx_pixel_put(mlx->mlx, mlx->window, (int)v.x, (int)v.y, v.color); | ||
y++; | ||
} | ||
x++; | ||
} | ||
//set_pixel(mlx, 0, 0, 0xFFAABB); | ||
mlx_put_image_to_window(mlx->mlx, mlx->window, mlx->image->image, 0, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,15 @@ | |
/* By: pbondoer <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2016/05/19 04:21:40 by pbondoer #+# #+# */ | ||
/* Updated: 2016/05/20 14:55:51 by pbondoer ### ########.fr */ | ||
/* Updated: 2016/05/22 02:25:23 by pbondoer ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
#include "fdf.h" | ||
#include "mlx.h" | ||
|
||
void set_pixel(t_image *image, int x, int y, int color) | ||
void image_set_pixel(t_image *image, int x, int y, int color) | ||
{ | ||
if (x < 0 || x >= WIN_WIDTH || y < 0 || y >= WIN_HEIGHT) | ||
return ; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* viewport.c :+: :+: :+: */ | ||
/* keyboard.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: pbondoer <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2016/05/20 14:56:03 by pbondoer #+# #+# */ | ||
/* Updated: 2016/05/20 14:56:04 by pbondoer ### ########.fr */ | ||
/* Created: 2016/06/12 05:33:43 by pbondoer #+# #+# */ | ||
/* Updated: 2016/06/12 05:42:08 by pbondoer ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "fdf.h" | ||
#include <stdlib.h> | ||
|
||
int hook_keydown(int key, t_mlx *mlx) | ||
{ | ||
(void)mlx; | ||
if (key == 53) | ||
exit(EXIT_SUCCESS); | ||
return (0); | ||
} |
Oops, something went wrong.