From 751014a252746d6f8e687b28ac36d4c9d56d4674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 5 Sep 2018 11:44:15 +0200 Subject: [PATCH] Update ray constraints --- raycastlib.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 0c6650e..666baaa 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -116,6 +116,7 @@ typedef struct { uint16_t maxHits; uint16_t maxSteps; + uint8_t computeTextureCoords; ///< Turns texture coords on/off. } RayConstraints; /** @@ -579,6 +580,7 @@ int_maybe32_t _camResYLimit = 0; Unit _middleRow = 0; ArrayFunction _floorFunction = 0; ArrayFunction _ceilFunction = 0; +uint8_t _computeTextureCoords = 0; /// Helper function that determines intersection with both ceiling and floor. Unit _floorCeilFunction(int16_t x, int16_t y) @@ -651,7 +653,8 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) int_maybe32_t z2ScreenCeil = _middleRow - perspectiveScale( (worldZ2Ceil * _camera.resolution.y) / UNITS_PER_SQUARE,dist); - int_maybe32_t wallScreenHeightCeilNoClamp = z2ScreenCeil - z1ScreenCeilNoClamp; + int_maybe32_t wallScreenHeightCeilNoClamp = + z2ScreenCeil - z1ScreenCeilNoClamp; z2ScreenCeil = clamp(z2ScreenCeil,0,_camResYLimit); @@ -698,8 +701,11 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) { p.position.y = i; p.hit = hit; - p.textureCoordY = ((i - z1ScreenNoClamp) * UNITS_PER_SQUARE) / - wallScreenHeightNoClamp; + + if (_computeTextureCoords) + p.textureCoordY = ((i - z1ScreenNoClamp) * UNITS_PER_SQUARE) / + wallScreenHeightNoClamp; + _pixelFunction(p); } @@ -711,8 +717,11 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) { p.position.y = i; p.hit = hit; - p.textureCoordY = ((i - z1ScreenCeilNoClamp) * UNITS_PER_SQUARE) / - wallScreenHeightCeilNoClamp; + + if (_computeTextureCoords) + p.textureCoordY = ((i - z1ScreenCeilNoClamp) * UNITS_PER_SQUARE) / + wallScreenHeightCeilNoClamp; + _pixelFunction(p); } @@ -766,6 +775,7 @@ void render(Camera cam, ArrayFunction floorHeightFunc, ArrayFunction _camera = cam; _camResYLimit = cam.resolution.y - 1; _middleRow = cam.resolution.y / 2; + _computeTextureCoords = constraints.computeTextureCoords; _startFloorHeight = floorHeightFunc( divRoundDown(cam.position.x,UNITS_PER_SQUARE),