Cub3D
Loading...
Searching...
No Matches
set_texture_x_coordinate.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* set_texture_x_coordinate.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/10/17 19:55:06 by kamitsui #+# #+# */
9/* Updated: 2024/12/21 09:43:19 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
15t_type_wall get_texture_direction(
16 int type_of_grid_line, t_vector ray_dir)
17{
18 if (type_of_grid_line == 1)
19 {
20 if (ray_dir.y < 0)
21 return (ENUM_SOUTH);
22 else
23 return (ENUM_NORTH);
24 }
25 else
26 {
27 if (ray_dir.x < 0)
28 return (ENUM_EAST);
29 else
30 return (ENUM_WEST);
31 }
32}
33// reference type_cub3d.h
34//typedef enum e_type_wall {
35// NORTH,
36// WEST,
37// EAST,
38// SOUTH
39//} t_type_wall;
40
44void set_texture_x_coordinate(t_frame *frame, int x)
45{
46 double wall_x;
47 t_vector view_point;
48 t_vector ray_dir;
49 t_dda *dda;
50 t_type_wall type_wall;
51
52 dda = &frame->dda;
53 view_point = frame->player->view_point;
54 ray_dir = frame->ray_cast.ray_dir;
55 if (dda->type_of_grid_line == 0)
56 wall_x = view_point.y + dda->perp_wall_dist * ray_dir.y;
57 else
58 wall_x = view_point.x + dda->perp_wall_dist * ray_dir.x;
59 wall_x -= floor(wall_x);
60 type_wall = get_texture_direction(dda->type_of_grid_line, ray_dir);
61 dda->texture = frame->texture[type_wall];
62 dda->tex_x = (int)(wall_x * (double)dda->texture.width);
63 if (dda->type_of_grid_line == 0 && ray_dir.x < 0)
64 dda->tex_x = dda->texture.width - dda->tex_x - 1;
65 if (dda->type_of_grid_line == 1 && ray_dir.y >= 0)
66 dda->tex_x = dda->texture.width - dda->tex_x - 1;
67 (void)x;
68}
69// debug code
70 //debug_texture_coordinate(frame->debug.fd, wall_x, frame,
71 // "end set_texture_x_coordinage()");
72// debug_put_texture_image(frame);
73// Note : comment out in source file because using forbidden function
74//
75// reference cub3.h
76//typedef struct s_dda {
77// int type_of_grid_line;
78// double perp_wall_dist;
79// int tex_x;
80// t_texture texture;
81//} t_dda;
single still image for render_frame
Definition type_cub3d.h:247
vector
Definition type_cub3d.h:74