5 [Edit removed during grace period]; added 403 characters in body
source | link

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here I have fisheye effect, if i use depth directly

    if (l == 0)
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        h_seen = dist_c * wall_h / depth;
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000);
    }

enter image description here

// Direction of each ray inside the while loop

if ((hit = intersection(w, l, &dir)))
        w->cam->rays[i].endpoint = w->cam->intersection;
else
    {
        w->cam->rays[i].endpoint.x = w->cam->position.x + w->cam->raylength * tcos((w->cam->angle + w->cam->fov / 2) - (i * (w->cam->fov / limit)));
        w->cam->rays[i].endpoint.y = w->cam->position.y + w->cam->raylength * tsin((w->cam->angle + w->cam->fov / 2) - (i * (w->cam->fov / limit))); // limit is just the screen width
    }

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here I have fisheye effect, if i use depth directly

    if (l == 0)
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        h_seen = dist_c * wall_h / depth;
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000);
    }

enter image description here

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here I have fisheye effect, if i use depth directly

    if (l == 0)
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        h_seen = dist_c * wall_h / depth;
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000);
    }

enter image description here

// Direction of each ray inside the while loop

if ((hit = intersection(w, l, &dir)))
        w->cam->rays[i].endpoint = w->cam->intersection;
else
    {
        w->cam->rays[i].endpoint.x = w->cam->position.x + w->cam->raylength * tcos((w->cam->angle + w->cam->fov / 2) - (i * (w->cam->fov / limit)));
        w->cam->rays[i].endpoint.y = w->cam->position.y + w->cam->raylength * tsin((w->cam->angle + w->cam->fov / 2) - (i * (w->cam->fov / limit))); // limit is just the screen width
    }
4 deleted 283 characters in body
source | link

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description hereenter image description here I have fisheye effect, if i use depth directly

    if (l == 0) // some check for projecting in the minimap or the 2.5D version
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        //
        // dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
        distortion = depth * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
        // if (distortion)
        h_seen = dist_c * wall_h / distortion;
        //printf("h_seen = %f\n", h_seen); // to check what was the diff of heightsdepth;
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000); // fill my image of the corresponding pixels
    }

enter image description here

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here

    if (l == 0) // some check for projecting in the minimap or the 2.5D version
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        //
        // dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
        distortion = depth * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
        // if (distortion)
        h_seen = dist_c * wall_h / distortion;
        //printf("h_seen = %f\n", h_seen); // to check what was the diff of heights
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000); // fill my image of the corresponding pixels
    }

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here I have fisheye effect, if i use depth directly

    if (l == 0)
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        h_seen = dist_c * wall_h / depth;
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000);
    }

enter image description here

3 added 850 characters in body
source | link

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here

    if (l == 0) // some check for projecting in the minimap or the 2.5D version
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        //
        // dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
        distortion = depth * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
        // if (distortion)
        h_seen = dist_c * wall_h / distortion;
        //printf("h_seen = %f\n", h_seen); // to check what was the diff of heights
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000); // fill my image of the corresponding pixels
    }

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here

I have an issue to find the correct height of walls to make them straight in raycasting rendering.

This is how I calculate the height of the wall which is h_seen:

dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
distortion = dist_w * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
if (distortion)
    h_seen = dist_c * wall_h / distortion;
//printf("h_seen = %f\n", h_seen);
y = cam_h - (h_seen / 2) - 1;

This is a screenshot of the problem enter image description here

    if (l == 0) // some check for projecting in the minimap or the 2.5D version
    {
        raytravel.y = w->cam->rays[i].endPoint.y - w->cam->position.y;
        raytravel.x = w->cam->rays[i].endPoint.x - w->cam->position.x;
        depth = raytravel.x * dir.x + raytravel.y * dir.y;
        //
        // dist_w = sqrt(pow((w->cam->position.x - w->cam->rays[i].endPoint.x), 2) + pow((w->cam->position.y - w->cam->rays[i].endPoint.y), 2));
        distortion = depth * tCos(w->cam->fov / 2 - (i * w->cam->fov / WIN_W));
        // if (distortion)
        h_seen = dist_c * wall_h / distortion;
        //printf("h_seen = %f\n", h_seen); // to check what was the diff of heights
        y = cam_h - (h_seen / 2) - 1;
        if (hit == 1)
            while (++y < (cam_h + (h_seen / 2)))
                put_pixel_img(w, WIN_W - i + WIDTH_MM, y + 150, 0xff0000); // fill my image of the corresponding pixels
    }
2 Formatting & spelling
source | link
1
source | link