-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cube_notes.txt
216 lines (176 loc) · 6.92 KB
/
Cube_notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# **************************************************************************** #
# #
# ::: :::::::: #
# Cube_notes.txt :+: :+: :+: #
# +:+ +:+ +:+ #
# By: abelhadi <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/08/09 17:40:17 by abelhadi #+# #+# #
# Updated: 2022/08/16 16:51:34 by abelhadi ### ########.fr #
# #
# **************************************************************************** #
RAY-CASTING STEP 1: CREATING A WORLD
To illustrate the process of ray-casting, we will create a maze world that has the following geometric constraints:
1. Walls are always at 90° angle with the floor.
2. Walls are made of cubes that have the same size.
3. Floor is always flat.
RAY-CASTING STEP 2: DEFINING PROJECTION ATTRIBUTES
Now that we have the world, we need to define some attributes before we can project and render the world. Specifically, we need to know these attributes:
1. Player/viewer’s height, player’s field of view (FOV), and player’s position.
2. Projection plane’s dimension.
3. Relationship between player and projection plane.
The player should be able to see what is in front of him/her.
For this, we will need to define a field of view (FOV).
The FOV determines how wide the player sees the world in front
of him/her (see Figure 8). Most humans have a FOV of 90 degrees
or more. However, FOV with this angle does not look good on screen.
Therefore, we define the FOV to be 60 degrees through trial and
experimentation (on how good it looks on screen).
The player’s height is defined to be 32 units because this is
a reasonable assumption considering that walls (the cubes) are 64 units high.
next intersection point -call it (Xnew,Ynew) is Xnew=Xold+Xa, and Ynew=YOld+Ya.
======Finding horizontal intersection ======
1. Finding the coordinate of A.
If the ray is facing up
A.y = rounded_down(Py/64) * (64) - 1;
If the ray is facing down
A.y = rounded_down(Py/64) * (64) + 64;
(In the picture, the ray is facing up, so we use
the first formula.
A.y=rounded_down(224/64) * (64) - 1 = 191;
Now at this point, we can find out the grid
coordinate of y.
However, we must decide whether A is part of
the block above the line,
or the block below the line.
Here, we chose to make A part of the block
above the line, that is why we subtract 1 from A.y.
So the grid coordinate of A.y is 191/64 = 2;
A.x = Px + (Py-A.y)/tan(ALPHA);
In the picture, (assume ALPHA is 60 degrees),
A.x=96 + (224-191)/tan(60) = about 115;
The grid coordinate of A.x is 115/64 = 1;
So A is at grid (1,2) and we can check
whether there is a wall on that grid.
There is no wall on (1,2) so the ray will be
extended to C.
2. Finding Ya
If the ray is facing up
Ya=-64;
If the ray is facing down
Ya=64;
3. Finding Xa
Xa = 64/tan(60) = 36;
4. We can get the coordinate of C as follows:
C.x=A.x+Xa = 115+36 = 151;
C.y=A.y+Ya = 191-64 = 127;
Convert this into grid coordinate by
dividing each component with 64.
The result is
C.x = 151/64 = 2 (grid coordinate),
C.y = 127/64 = 1 (grid coordinate)
So the grid coordinate of C is (2, 1).
(C programmer's note: Remember we always round down,
this is especially true since
you can use right shift by 8 to divide by 64).
5. Grid (2,1) is checked.
Again, there is no wall, so the ray is extended
to D.
6. We can get the coordinate of D as follows:
D.x=C.x+Xa = 151+36 = 187;
D.y=C.y+Ya = 127-64 = 63;
Convert this into grid coordinate by
dividing each component with 64.
The result is
D.x = 187/64 = 2 (grid coordinate),
D.y = 63/64 = 0 (grid coordinate)
So the grid coordinate of D is (2, 0).
6. Grid (2,0) is checked.
There is a wall there, so the process stop.
Steps of finding intersections with vertical grid lines:
Find coordinate of the first intersection (point B in this example).
The ray is facing right in the picture, so B.x = rounded_down(Px/64) * (64) + 64.
If the ray had been facing left B.x = rounded_down(Px/64) * (64) – 1.
A.y = Py + (Px-A.x)*tan(ALPHA);
Find Xa. (Note: Xa is just the width of the grid; however,
if the ray is facing right, Xa will be positive,
if the ray is facing left, Ya will be negative.)
method :
1. open description file ==> fnc(filename, int **map, int **textures)
int **map_data; // contain the parsing of the map
int *tab_of_fds_of_textures, and ground color; // contain opened fds of textures files,
parsed in order NO => EA => SO => WE => R => G => B.
NAME = minishell
CC = gcc
BTIN_DIR = ./srcs/built_ins/
BTIN_SRCS = built_in.c \
builtin_functions.c \
builtin_functions2.c \
export_utils.c \
export_utils2.c \
export_utils3.c \
export_utils4.c \
env_utils.c \
unset_utils.c \
exit_utils.c \
cd_utils.c \
cd_utils2.c \
echo_utils.c \
EXEC_DIR = ./srcs/execution/
EXEC_SRCS = exec.c \
here_doc.c \
child_process.c \
exec_utils.c \
signals.c \
signals_utils.c \
SRCS_DIR = ./srcs/
SRCS = minishell.c \
env_manager.c \
parsing.c \
get_tokens.c \
get_tokens_type.c \
tokens_expansion.c \
tokens_expansion2.c \
tokens_expansion_utils.c \
fill_commands_tab.c \
setup_redirections.c \
triming_tokens.c \
t_type_utils.c \
t_type_utils_2.c \
t_type_utils_3.c \
find_path.c \
quotes_manage.c \
redirect_manage.c \
errors_manage.c \
syntax_error_checker.c \
new_prompt_manage.c \
utilitaries.c \
list_functions4.c \
BTIN_PATH = $(addprefix ${BTIN_DIR},${BTIN_SRCS})
BTIN_OBJS = $(addprefix ${BTIN_DIR},${BTIN_SRCS:.c=.o})
EXEC_PATH = $(addprefix ${EXEC_DIR},${EXEC_SRCS})
EXEC_OBJS = $(addprefix ${EXEC_DIR},${EXEC_SRCS:.c=.o})
SRCS_PATH = $(addprefix ${SRCS_DIR},${SRCS})
OBJS = $(addprefix ${SRCS_DIR},${SRCS:.c=.o})
READLINE = -L/Users/${USER}/.brew/Cellar/readline/8.1.2/lib/ -lreadline
#READLINE = -L/usr/local/Cellar/readline/8.1.2/lib/ -lreadline
LIB = libft/libft.a
CFLAGS = -Wall -Wextra -Werror
HEADERS = -I./includes/
RM = rm -f
SURPL_O = *.o
all: ${NAME}
make all -C ./libft
$(NAME): $(OBJS) $(EXEC_OBJS) ${BTIN_OBJS}
make all -C ./libft
$(CC) $(CFLAGS) ${LIB} ${READLINE} $(HEADERS) $(SRCS_PATH) $(EXEC_PATH) ${BTIN_PATH} -o ${NAME}
${RM} ${SURPL_O}
libft:
make all -C ./libft
clean:
make clean -C ./libft
${RM} ${OBJS} ${EXEC_OBJS} ${BTIN_OBJS} ${SURPL_O}
fclean: clean
${RM} ${NAME}
re: fclean all
.PHONY: all clean fclean re