mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-23 20:49:57 +01:00
Add height to PixelInfo
This commit is contained in:
parent
a5b5d6d43e
commit
66c9ace75a
1 changed files with 22 additions and 15 deletions
33
raycastlib.h
33
raycastlib.h
|
@ -235,6 +235,7 @@ typedef struct
|
||||||
int8_t isFloor; ///< Whether the pixel is floor or ceiling.
|
int8_t isFloor; ///< Whether the pixel is floor or ceiling.
|
||||||
int8_t isHorizon; ///< If the pixel belongs to horizon segment.
|
int8_t isHorizon; ///< If the pixel belongs to horizon segment.
|
||||||
RCL_Unit depth; ///< Corrected depth.
|
RCL_Unit depth; ///< Corrected depth.
|
||||||
|
RCL_Unit height; ///< World height (mostly for floor).
|
||||||
RCL_HitResult hit; ///< Corresponding ray hit.
|
RCL_HitResult hit; ///< Corresponding ray hit.
|
||||||
RCL_Vector2D texCoords; /**< Normalized (0 to RCL_UNITS_PER_SQUARE - 1)
|
RCL_Vector2D texCoords; /**< Normalized (0 to RCL_UNITS_PER_SQUARE - 1)
|
||||||
texture coordinates. */
|
texture coordinates. */
|
||||||
|
@ -1240,6 +1241,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t
|
||||||
|
|
||||||
RCL_PixelInfo p;
|
RCL_PixelInfo p;
|
||||||
p.position.x = x;
|
p.position.x = x;
|
||||||
|
p.height = 0;
|
||||||
p.texCoords.x = 0;
|
p.texCoords.x = 0;
|
||||||
p.texCoords.y = 0;
|
p.texCoords.y = 0;
|
||||||
|
|
||||||
|
@ -1295,6 +1297,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t
|
||||||
|
|
||||||
// draw floor until wall
|
// draw floor until wall
|
||||||
p.isFloor = 1;
|
p.isFloor = 1;
|
||||||
|
p.height = fZ1World + _RCL_camera.height;
|
||||||
|
|
||||||
#if RCL_COMPUTE_FLOOR_DEPTH == 1
|
#if RCL_COMPUTE_FLOOR_DEPTH == 1
|
||||||
p.depth = (_RCL_fHorizontalDepthStart - fPosY) * _RCL_horizontalDepthStep;
|
p.depth = (_RCL_fHorizontalDepthStart - fPosY) * _RCL_horizontalDepthStep;
|
||||||
|
@ -1313,6 +1316,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t
|
||||||
{
|
{
|
||||||
// draw ceiling until wall
|
// draw ceiling until wall
|
||||||
p.isFloor = 0;
|
p.isFloor = 0;
|
||||||
|
p.height = cZ1World + _RCL_camera.height;
|
||||||
|
|
||||||
#if RCL_COMPUTE_CEILING_DEPTH == 1
|
#if RCL_COMPUTE_CEILING_DEPTH == 1
|
||||||
p.depth = (cPosY - _RCL_cHorizontalDepthStart) *
|
p.depth = (cPosY - _RCL_cHorizontalDepthStart) *
|
||||||
|
@ -1334,6 +1338,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t
|
||||||
p.isFloor = 1;
|
p.isFloor = 1;
|
||||||
p.hit = hit;
|
p.hit = hit;
|
||||||
p.texCoords.x = hit.textureCoord;
|
p.texCoords.x = hit.textureCoord;
|
||||||
|
p.height = 0; // don't compute this, no use
|
||||||
|
|
||||||
// draw floor wall
|
// draw floor wall
|
||||||
|
|
||||||
|
@ -1492,6 +1497,7 @@ void _RCL_columnFunctionSimple(RCL_HitResult *hits, uint16_t hitCount,
|
||||||
p.isFloor = 0;
|
p.isFloor = 0;
|
||||||
p.isHorizon = 1;
|
p.isHorizon = 1;
|
||||||
p.depth = 1;
|
p.depth = 1;
|
||||||
|
p.height = RCL_UNITS_PER_SQUARE;
|
||||||
|
|
||||||
y = _RCL_drawHorizontal(-1,wallStart,-1,_RCL_middleRow,_RCL_camera.height,1,
|
y = _RCL_drawHorizontal(-1,wallStart,-1,_RCL_middleRow,_RCL_camera.height,1,
|
||||||
RCL_COMPUTE_CEILING_DEPTH,0,1,&ray,&p);
|
RCL_COMPUTE_CEILING_DEPTH,0,1,&ray,&p);
|
||||||
|
@ -1501,6 +1507,7 @@ void _RCL_columnFunctionSimple(RCL_HitResult *hits, uint16_t hitCount,
|
||||||
p.isWall = 1;
|
p.isWall = 1;
|
||||||
p.isFloor = 1;
|
p.isFloor = 1;
|
||||||
p.depth = dist;
|
p.depth = dist;
|
||||||
|
p.height = 0;
|
||||||
|
|
||||||
#if RCL_ROLL_TEXTURE_COORDS == 1 && RCL_COMPUTE_WALL_TEXCOORDS == 1
|
#if RCL_ROLL_TEXTURE_COORDS == 1 && RCL_COMPUTE_WALL_TEXCOORDS == 1
|
||||||
p.hit.textureCoord -= p.hit.doorRoll;
|
p.hit.textureCoord -= p.hit.doorRoll;
|
||||||
|
@ -1528,6 +1535,16 @@ void _RCL_columnFunctionSimple(RCL_HitResult *hits, uint16_t hitCount,
|
||||||
-1,&ray,&p);
|
-1,&ray,&p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void _RCL_precomputeFloorDistances(RCL_Unit viewingHeight,
|
||||||
|
RCL_Unit *dest, uint16_t pixels)
|
||||||
|
{
|
||||||
|
RCL_Unit camHeightScreenSize =
|
||||||
|
(viewingHeight * pixels * 2) / RCL_UNITS_PER_SQUARE;
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < pixels; ++i) // precompute the distances
|
||||||
|
dest[i] = RCL_perspectiveScaleInverse(camHeightScreenSize,i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
void RCL_renderComplex(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc,
|
void RCL_renderComplex(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc,
|
||||||
RCL_ArrayFunction ceilingHeightFunc, RCL_ArrayFunction typeFunction,
|
RCL_ArrayFunction ceilingHeightFunc, RCL_ArrayFunction typeFunction,
|
||||||
RCL_RayConstraints constraints)
|
RCL_RayConstraints constraints)
|
||||||
|
@ -1584,19 +1601,9 @@ void RCL_renderSimple(RCL_Camera cam, RCL_ArrayFunction floorHeightFunc,
|
||||||
|
|
||||||
#if RCL_COMPUTE_FLOOR_TEXCOORDS == 1
|
#if RCL_COMPUTE_FLOOR_TEXCOORDS == 1
|
||||||
uint16_t halfResY = cam.resolution.y / 2;
|
uint16_t halfResY = cam.resolution.y / 2;
|
||||||
|
RCL_Unit floorPixelDistances[halfResY];
|
||||||
RCL_Unit floorPixelDistances[halfResY]; /* for each vertical floor pixel,
|
_RCL_precomputeFloorDistances(cam.height,floorPixelDistances,halfResY);
|
||||||
this will contain precomputed
|
_RCL_floorPixelDistances = floorPixelDistances; // pass to column function
|
||||||
distance to the camera */
|
|
||||||
RCL_Unit camHeightScreenSize =
|
|
||||||
(cam.height * cam.resolution.y) / RCL_UNITS_PER_SQUARE;
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < halfResY; ++i) // precompute the distances
|
|
||||||
floorPixelDistances[i] =
|
|
||||||
RCL_perspectiveScaleInverse(camHeightScreenSize,i + 1);
|
|
||||||
|
|
||||||
// pass to _RCL_columnFunctionSimple
|
|
||||||
_RCL_floorPixelDistances = floorPixelDistances;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RCL_castRaysMultiHit(cam,_floorHeightNotZeroFunction,typeFunc,
|
RCL_castRaysMultiHit(cam,_floorHeightNotZeroFunction,typeFunc,
|
||||||
|
|
Loading…
Reference in a new issue