add new file for textures
This commit is contained in:
3
Makefile
3
Makefile
@@ -46,7 +46,8 @@ SRCS += player_moves.c \
|
|||||||
# draw/
|
# draw/
|
||||||
SRCS += draw.c \
|
SRCS += draw.c \
|
||||||
ray_intersect.c \
|
ray_intersect.c \
|
||||||
raycast.c
|
raycast.c \
|
||||||
|
draw_column.c
|
||||||
|
|
||||||
# headers
|
# headers
|
||||||
D_HEADERS = headers
|
D_HEADERS = headers
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* nbr pixel player move */
|
/* nbr pixel player move */
|
||||||
# define PLR_MV 2
|
# define PLR_MV 1
|
||||||
/* degree of rotation of the player per press */
|
/* degree of rotation of the player per press */
|
||||||
# define PLR_ROT 2
|
# define PLR_ROT 2
|
||||||
/* nbr key you can press at the same time */
|
/* nbr key you can press at the same time */
|
||||||
|
|||||||
@@ -86,5 +86,7 @@ void draw(t_game *game);
|
|||||||
void raycast(t_game *game, t_rcast *rcast);
|
void raycast(t_game *game, t_rcast *rcast);
|
||||||
// ray_intersect.c
|
// ray_intersect.c
|
||||||
void ray_intersect(t_game *game, t_rcast *rcast, t_vec *ray);
|
void ray_intersect(t_game *game, t_rcast *rcast, t_vec *ray);
|
||||||
|
// draw_column.c
|
||||||
|
void draw_column(t_game *game, t_rcast *rcast);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
31
srcs/draw/draw_column.c
Normal file
31
srcs/draw/draw_column.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "cube3d.h"
|
||||||
|
|
||||||
|
void draw_floor_ceiling(t_game *game, t_rcast *rcast)
|
||||||
|
{
|
||||||
|
t_vec plan;
|
||||||
|
|
||||||
|
plan.start.x = rcast->ray_nb;
|
||||||
|
plan.end.x = rcast->ray_nb;
|
||||||
|
if (rcast->wall.start.y > 0)
|
||||||
|
{
|
||||||
|
plan.start.y = rcast->screen_height;
|
||||||
|
plan.end.y = rcast->wall.start.y;
|
||||||
|
draw_line(&game->img, &plan, 0x00FF0000);
|
||||||
|
}
|
||||||
|
if (rcast->wall.start.y < rcast->screen_height)
|
||||||
|
{
|
||||||
|
plan.start.y = rcast->wall.end.y;
|
||||||
|
plan.end.y = 0;
|
||||||
|
draw_line(&game->img, &plan, 0x000000FF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_column(t_game *game, t_rcast *rcast)
|
||||||
|
{
|
||||||
|
int color;
|
||||||
|
draw_floor_ceiling(game, rcast);
|
||||||
|
color = 0x00FF00FF;
|
||||||
|
if (rcast->is_x)
|
||||||
|
color = 0x00EE00EE;
|
||||||
|
draw_line(&game->img, &rcast->wall, color);
|
||||||
|
}
|
||||||
@@ -30,6 +30,16 @@
|
|||||||
}
|
}
|
||||||
// tmp end
|
// tmp end
|
||||||
|
|
||||||
|
static void fill_wall_vector(t_rcast *rcast, int height)
|
||||||
|
{
|
||||||
|
if (height < 0)
|
||||||
|
height = 0;
|
||||||
|
if (height > rcast->screen_height)
|
||||||
|
height = rcast->screen_height;
|
||||||
|
rcast->wall.start.y = rcast->screen_height / 2 + height / 2;
|
||||||
|
rcast->wall.end.y = rcast->screen_height / 2 - height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
static void calcul_wall(t_rcast *rcast)
|
static void calcul_wall(t_rcast *rcast)
|
||||||
{
|
{
|
||||||
int height;
|
int height;
|
||||||
@@ -48,39 +58,8 @@ static void calcul_wall(t_rcast *rcast)
|
|||||||
height *= rcast->slope_y;
|
height *= rcast->slope_y;
|
||||||
if (delta && rcast->screen_dist)
|
if (delta && rcast->screen_dist)
|
||||||
height /= (delta * rcast->screen_dist);
|
height /= (delta * rcast->screen_dist);
|
||||||
|
|
||||||
height = ft_abs(height);
|
height = ft_abs(height);
|
||||||
if (height < 0)
|
fill_wall_vector(rcast, height);
|
||||||
height = 0;
|
|
||||||
if (height > rcast->screen_height)
|
|
||||||
height = rcast->screen_height;
|
|
||||||
rcast->wall.start.y = rcast->screen_height / 2 + height / 2;
|
|
||||||
rcast->wall.end.y = rcast->screen_height / 2 - height / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_column(t_game *game, t_rcast *rcast)
|
|
||||||
{
|
|
||||||
t_vec plan;
|
|
||||||
int color;
|
|
||||||
|
|
||||||
plan.start.x = rcast->ray_nb;
|
|
||||||
plan.end.x = rcast->ray_nb;
|
|
||||||
if (rcast->wall.start.y > 0)
|
|
||||||
{
|
|
||||||
plan.start.y = rcast->screen_height;
|
|
||||||
plan.end.y = rcast->wall.start.y;
|
|
||||||
draw_line(&game->img, &plan, 0x00FF0000);
|
|
||||||
}
|
|
||||||
if (rcast->wall.start.y < rcast->screen_height)
|
|
||||||
{
|
|
||||||
plan.start.y = rcast->wall.end.y;
|
|
||||||
plan.end.y = 0;
|
|
||||||
draw_line(&game->img, &plan, 0x000000FF);
|
|
||||||
}
|
|
||||||
color = 0x00FF00FF;
|
|
||||||
if (rcast->is_x)
|
|
||||||
color = 0x00EE00EE;
|
|
||||||
draw_line(&game->img, &rcast->wall, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void raycast(t_game *game, t_rcast *rcast)
|
void raycast(t_game *game, t_rcast *rcast)
|
||||||
|
|||||||
Reference in New Issue
Block a user