From bdc4fc5bb74303e1bf78259df820b3bcdd92e257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 8 Sep 2018 18:45:57 +0200 Subject: [PATCH] Fix ceiling --- raycastlib.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index e2ec85d..96a87bf 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -657,9 +657,6 @@ Unit _floorCeilFunction(int16_t x, int16_t y) void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) { -if (x == 25) - printf("------%d\n",hitCount); - int_maybe32_t y = _camResYLimit; // screen y (for floor), will only go up int_maybe32_t y2 = 0; // screen y (for ceil), will only fo down @@ -671,7 +668,7 @@ if (x == 25) #define VERTICAL_DEPTH_MULTIPLY 2 - // we'll be simulatenously drawing the floor and the ceiling now + // we'll be simulatenously drawing the floor and the ceiling now for (uint_maybe32_t j = 0; j < hitCount; ++j) { HitResult hit = hits[j]; @@ -859,19 +856,19 @@ if (x == 25) // draw ceiling until horizon - if (_ceilFunction != 0) + p.isFloor = 0; + + Unit ceilCameraDiff = + _ceilFunction != 0 ? + absVal(worldZPrevCeil) * VERTICAL_DEPTH_MULTIPLY : UNITS_PER_SQUARE; + + horizon = y > _middleRow ? _middleRow : y; + + for (int_maybe32_t i = y2; i < horizon; ++i) { - p.isFloor = 0; - - Unit ceilCameraDiff = absVal(worldZPrevCeil) * VERTICAL_DEPTH_MULTIPLY; - horizon = y > _middleRow ? _middleRow : y; - - for (int_maybe32_t i = y2; i < horizon; ++i) - { - p.position.y = i; - p.depth = (i - _fogStartYTop) * _floorDepthStep + ceilCameraDiff; - _pixelFunction(p); - } + p.position.y = i; + p.depth = (i - _fogStartYTop) * _floorDepthStep + ceilCameraDiff; + _pixelFunction(p); } #undef VERTICAL_DEPTH_MULTIPLY