I want to check the horizontal and vertical intersections on my raycasting view, and I can't exactly understand what is ALPHA using this drawing
source : https://www.permadi.com/tutorial/raycast/rayc7.html
I wrote something that makes the walls straights and with less stairs on top and bottom, but i have some columns which go out of the view row, i can't figure out where i failed my operations (rounds)
this is the code of the vertical and the horizontal intersections :
static inline void inter_hor(t_wolf3d *w, int i, double angle){
t_vec2f a; // first intersection point
t_vec2f o; // offset
double tangent;
tangent = ttan(angle) + 0.001;
a.y = (angle <= 180) ? floor(w->cam->position.y / 32) *
32 - 1 : ceil(w->cam->position.y / 32) * 32 + 32;
o.y = (angle < 180) ? -32 : 32;
o.x = (angle < 90 || angle > 270) ? 32 / tangent : -32 / tangent;
a.x = (angle != 180.0 && angle < 359.97) ? w->cam->position.x + (w->cam->position.y - a.y) / tangent :
w->cam->position.x + (w->cam->position.y - a.y) / -tangent; //w->mini_h is the w->map->h * 32 and so on for w->mini_w
a.x = (angle >= 179.97 && angle <= 180) ? w->cam->position.x + (w->cam->position.y - a.y) / -tangent : a.x;
if (ceil(a.x / 32) < 0 || ceil(a.x / 32) >= w->map->w)
a.x = (ceil(a.x / 32) < 0) ? 0 : w->mini_w - 1;
while (w->map->board[(int)a.y / 32][(int)a.x / 32] == 0)
{
a.x += ((angle >= 90 && angle < 180) || angle >= 270) ? -o.x : o.x;
a.y += o.y;
if (ceil(a.x / 32) < 0 || ceil(a.x / 32) >= w->map->w)
a.x = (ceil(a.x / 32) < 0) ? 0 : w->mini_w - 1;
if (a.y < 0 || a.y > w->mini_h - 1)
break;
}
w->cam->interh[i].x = a.x;
w->cam->interh[i].y = a.y;}
static inline void inter_ver(t_wolf3d *w, int i, double angle){
t_vec2f a; // intersection point
t_vec2f o; // offset
double tangent;
tangent = ttan(angle) + 0.001;
a.x = (angle >= 90 && angle < 270) ? ceil(w->cam->position.x / 32) *
32 - 1 : floor(w->cam->position.x / 32) * 32 + 32;
o.x = (angle > 90 && angle < 270) ? -32 : 32;
o.y = (angle > 0 && angle < 180) ? -32 * tangent : 32 * tangent;
a.y = (angle != 270 && angle != 90) ? w->cam->position.y + (w->cam->position.x - a.x) * tangent :
w->cam->position.y + (w->cam->position.x - a.x) * -tangent;
if (ceil(a.y / 32) < 0 || ceil(a.y / 32) >= w->map->h)
a.y = (ceil(a.y / 32) < 0) ? 0 : w->mini_h - 1;
while (w->map->board[(int)ceil(a.y / 32)][(int)a.x / 32] == 0)
{
a.y += ((angle > 90 && angle < 180) || angle > 270) ? -o.y : o.y;
a.x += o.x;
if (ceil(a.y / 32) < 0 || ceil(a.y / 32) >= w->map->h)
a.y = (ceil(a.y / 32) < 0) ? 0 : w->mini_h - 1;
if (a.x < 0 || a.x > w->mini_w - 1)
break;
}
w->cam->interv[i].x = a.x;
w->cam->interv[i].y = a.y;}
I could use the dir.y / dir.x computed before for my tangent, but i didn't cause i had some divisions by zero when my rays was facing at 180, 360, 0 degrees, angles are complexes and i dont understand completely the vectors method to do that way; these are some screeshots :