0

I'm actually using the algorithme of Toto Briac from Raycaster, searching for more effective floor/ceiling raycast When using it, the floor casting is working well for east and west side, but for north and south it just does weird things (just look image).

    double pixelsToBottom;
double pixelsToMid;
double directDistFloor;
double realDistance;
double y;
t_point f_p;

pixelsToBottom = (double)data->s_height - wall[1].y;
pixelsToMid = (double)data->s_height / 2 - pixelsToBottom;
for (int i = pixelsToMid; i < data->s_height / 2; i += 1)
{
    directDistFloor = (data->dist_proj * (double)(data->s_height / 2)) / i;
    realDistance = directDistFloor / fabs(cos(angle));
    f_p.x = data->player.pos.x + cos(angle) * (realDistance) / (data->dist_proj / (64.0));
    f_p.y = data->player.pos.y + sin(angle) * (realDistance) / (data->dist_proj / (64.0));
    y = (wall->x + (i + data->s_height / 2) * data->s_width) / data->s_width;
    pixel_put(&data->obj, wall->x, y, f_pixel(data, f_p));
}

But i'm facing an issu, when i'm facing north and south side it's all ok, but when the ray is going into east or west side, the texture just do a weird thing like that :

I know that it refer to : realDistance = directDistFloor / fabs(cos(angle)); if i replace the cos(angle) by sin(angle) in this line, it just invert things. I didn't find a way to change the calcule in right moment. I you have any idea I will take it ! Thank you !!

When facing north or south side

  • Why exactly do you divide by the `fabs(cos(angle))`? In the following lines, you are multiplying by the `cos(angle)` and `sin(angle)` respectively, this does not look quite correct. How does the result look if you do not do the division? – ZwergofPhoenix Oct 06 '22 at 20:26
  • I divide by the `fabs(cos(angle))` to avoid the fisheye effect. If i don't divid directDistFloor, all the side work properly, there isn't this huge deep effect but the floor is hardly rounded. the `cos(angle)` and `sin(angle)` are used to get the properly texture, if i remove them there is juste huge green line instead off all pixel of the texture. the `directDistFloor` variable is the brut real distance from player to the floor coordinate i'm working on (which decrease with the for). So I have to divided it with `cos(angle)` to applicate the angle of the ray. Thank's for your reply man ! – Samuel Janssens Oct 06 '22 at 21:19
  • see [Ray Casting with different height size](https://stackoverflow.com/a/47251071/2521214) for some inspiration – Spektre Oct 07 '22 at 06:17

1 Answers1

2

It's okay I found the answer, for the people who are interest, in the line realDistance = directDistFloor / fabs(cos(angle)); I was using the angle of the ray in the world, I changed it by the angle relative to my player dir (so 0° if it's the player dir ray) and it work properly ! Thank's @ZwergofPhoenix for the time you took !