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

Continue floor texturing

This commit is contained in:
Miloslav Číž 2018-09-28 23:27:21 +02:00
parent 3bfc3e2a38
commit 94a4fdb9ba

View file

@ -1104,8 +1104,6 @@ static inline int16_t _RCL_drawHorizontal(
{\ {\
dx = pixelInfo->hit.position.x - _RCL_camera.position.x;\ dx = pixelInfo->hit.position.x - _RCL_camera.position.x;\
dy = pixelInfo->hit.position.y - _RCL_camera.position.y;\ dy = pixelInfo->hit.position.y - _RCL_camera.position.y;\
pixPos = yCurrent - _RCL_middleRow;\
pixPosIncrement = yCurrent < yTo ? 1 : -1;\
rayCameraCos = RCL_vectorsAngleCos(\ rayCameraCos = RCL_vectorsAngleCos(\
RCL_angleToDirection(_RCL_camera.direction),ray->direction);\ RCL_angleToDirection(_RCL_camera.direction),ray->direction);\
}\ }\
@ -1118,12 +1116,11 @@ static inline int16_t _RCL_drawHorizontal(
pixelInfo->depth += depthIncrement;\ pixelInfo->depth += depthIncrement;\
if (doCoords) /*constant condition - compiler should optimize it out*/\ if (doCoords) /*constant condition - compiler should optimize it out*/\
{\ {\
RCL_Unit d = _RCL_floorPixelDistances[pixPos];\ RCL_Unit d = _RCL_floorPixelDistances[i];\
pixelInfo->texCoords.x =\ pixelInfo->texCoords.x =\
_RCL_camera.position.x + ((d * dx) / (pixelInfo->hit.distance));\ _RCL_camera.position.x + ((d * dx) / (pixelInfo->hit.distance));\
pixelInfo->texCoords.y =\ pixelInfo->texCoords.y =\
_RCL_camera.position.y + ((d * dy) / (pixelInfo->hit.distance));\ _RCL_camera.position.y + ((d * dy) / (pixelInfo->hit.distance));\
pixPos += pixPosIncrement;\
}\ }\
RCL_PIXEL_FUNCTION(pixelInfo);\ RCL_PIXEL_FUNCTION(pixelInfo);\
}\ }\
@ -1541,14 +1538,15 @@ void _RCL_columnFunctionSimple(RCL_HitResult *hits, uint16_t hitCount,
-1,&ray,&p); -1,&ray,&p);
} }
static inline void _RCL_precomputeFloorDistances(RCL_Unit viewingHeight, static inline void _RCL_precomputeFloorDistances(RCL_Camera camera,
RCL_Unit *dest, uint16_t pixels) RCL_Unit *dest)
{ {
RCL_Unit camHeightScreenSize = RCL_Unit camHeightScreenSize =
(viewingHeight * pixels * 2) / RCL_UNITS_PER_SQUARE; (camera.height * camera.resolution.y) / RCL_UNITS_PER_SQUARE;
for (uint16_t i = 0; i < pixels; ++i) // precompute the distances for (uint16_t i = 0; i < camera.resolution.y; ++i)
dest[i] = RCL_perspectiveScaleInverse(camHeightScreenSize,i + 1); dest[i] = RCL_perspectiveScaleInverse(camHeightScreenSize,
RCL_absVal(i - _RCL_middleRow));
} }
void RCL_renderComplex(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc, void RCL_renderComplex(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc,
@ -1581,8 +1579,8 @@ void RCL_renderComplex(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc,
_RCL_horizontalDepthStep = RCL_HORIZON_DEPTH / cam.resolution.y; _RCL_horizontalDepthStep = RCL_HORIZON_DEPTH / cam.resolution.y;
#if RCL_COMPUTE_FLOOR_TEXCOORDS == 1 #if RCL_COMPUTE_FLOOR_TEXCOORDS == 1
RCL_Unit floorPixelDistances[halfResY]; RCL_Unit floorPixelDistances[cam.resolution.y];
_RCL_precomputeFloorDistances(cam.height,floorPixelDistances,halfResY); _RCL_precomputeFloorDistances(cam,floorPixelDistances);
_RCL_floorPixelDistances = floorPixelDistances; // pass to column function _RCL_floorPixelDistances = floorPixelDistances; // pass to column function
#endif #endif
@ -1612,9 +1610,8 @@ void RCL_renderSimple(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc,
3; // for correctly rendering rolling doors we'll need 3 hits (NOT 2) 3; // for correctly rendering rolling doors we'll need 3 hits (NOT 2)
#if RCL_COMPUTE_FLOOR_TEXCOORDS == 1 #if RCL_COMPUTE_FLOOR_TEXCOORDS == 1
uint16_t halfResY = cam.resolution.y / 2; RCL_Unit floorPixelDistances[cam.resolution.y];
RCL_Unit floorPixelDistances[halfResY]; _RCL_precomputeFloorDistances(cam,floorPixelDistances);
_RCL_precomputeFloorDistances(cam.height,floorPixelDistances,halfResY);
_RCL_floorPixelDistances = floorPixelDistances; // pass to column function _RCL_floorPixelDistances = floorPixelDistances; // pass to column function
#endif #endif