1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-20 20:19:57 +01:00

Ugly hack fix

This commit is contained in:
Miloslav Číž 2020-02-25 17:04:11 +01:00
parent b542aeebea
commit f09006066d

View file

@ -844,7 +844,7 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc,
RCL_Unit diff = h.position.x - ray.start.x;
h.position.y = // avoid division by multiplying with reciprocal
ray.start.y + ((ray.direction.y * diff) * rayDirXRecip) / RECIP_SCALE;
ray.start.y + (ray.direction.y * diff * rayDirXRecip) / RECIP_SCALE;
#if RCL_RECTILINEAR
/* Here we compute the fish eye corrected distance (perpendicular to
@ -876,7 +876,7 @@ void RCL_castRayMultiHit(RCL_Ray ray, RCL_ArrayFunction arrayFunc,
RCL_Unit diff = h.position.y - ray.start.y;
h.position.x =
ray.start.x + ((ray.direction.x * diff) * rayDirYRecip) / RECIP_SCALE;
ray.start.x + (ray.direction.x * diff * rayDirYRecip) / RECIP_SCALE;
#if RCL_RECTILINEAR
h.distance =
@ -1202,6 +1202,20 @@ static inline int16_t _RCL_drawWall(
RCL_Unit textureCoordScaled = pixelInfo->texCoords.y;
#if RCL_RECTILINEAR
RCL_Unit tmp = pixelInfo->depth;
pixelInfo->depth = (pixelInfo->depth * 23) / 32;
/* ^ UGLY HACK
For some reason the computed distance with rectilinear is larger, the
correct distance is about 0.711 (~= 23/32) of the computed distance, so
we correct it here in this ugly way.
TODO: investigate why, fix nicely
*/
#endif
for (RCL_Unit i = yCurrent + increment;
increment == -1 ? i >= limit : i <= limit; // TODO: is efficient?
i += increment)
@ -1218,6 +1232,10 @@ static inline int16_t _RCL_drawWall(
RCL_PIXEL_FUNCTION(pixelInfo);
}
#if RCL_RECTILINEAR
pixelInfo->depth = tmp;
#endif
return limit;
}
@ -1681,7 +1699,6 @@ RCL_PixelInfo RCL_mapToScreen(RCL_Vector2D worldPosition, RCL_Unit height,
result.position.y = camera.resolution.y / 2 -
(((3 * camera.resolution.y) / 4 ) *
// ((camera.resolution.y / 2) *
RCL_perspectiveScale(height - camera.height,result.depth))
/ RCL_UNITS_PER_SQUARE + camera.shear;