Better clipping
This commit is contained in:
parent
b063e5606e
commit
b4f1cf6353
@ -366,20 +366,28 @@ class Main:
|
||||
|
||||
# Clipping
|
||||
lineEnd = textureSegmentEnd
|
||||
if lineEnd > lineOffset + lineHeight:
|
||||
lineEnd = lineOffset + lineHeight
|
||||
if lineEnd > RAYCAST_RENDER_HEIGHT:
|
||||
lineEnd = RAYCAST_RENDER_HEIGHT
|
||||
lineStart = textureSegmentStart
|
||||
if lineStart < 0:
|
||||
lineStart = 0
|
||||
if lineEnd < lineStart:
|
||||
continue
|
||||
|
||||
# Upscaling
|
||||
lineStart = lineStart * RAYCAST_RESOLUTION_SCALING
|
||||
lineEnd = lineEnd * RAYCAST_RESOLUTION_SCALING
|
||||
|
||||
# Draw segment
|
||||
for repeat in range(1, RAYCAST_RESOLUTION_SCALING + 1):
|
||||
x = i * RAYCAST_RESOLUTION_SCALING + repeat
|
||||
self.drawVline(self.raycastSurface, color, x, int(lineStart), int(lineEnd))
|
||||
|
||||
def drawVline(self, surface, color, x, startY, endY):
|
||||
if x < 0 or x > RAYCAST_WIN_WIDTH or startY < 0 or endY > RAYCAST_WIN_HEIGHT or endY < startY:
|
||||
print("Trying to write outside bounds: vertical line with x {} from y {} to y {}".format(x, startY, endY))
|
||||
return
|
||||
|
||||
startIdx = startY * RAYCAST_WIN_WIDTH + x
|
||||
for idx in range(startIdx, endY * RAYCAST_WIN_WIDTH + x, RAYCAST_WIN_WIDTH):
|
||||
self.raycast_u32_pixels[idx] = color
|
||||
|
Loading…
Reference in New Issue
Block a user