Better clipping
This commit is contained in:
parent
b063e5606e
commit
b4f1cf6353
@ -366,20 +366,28 @@ class Main:
|
|||||||
|
|
||||||
# Clipping
|
# Clipping
|
||||||
lineEnd = textureSegmentEnd
|
lineEnd = textureSegmentEnd
|
||||||
if lineEnd > lineOffset + lineHeight:
|
if lineEnd > RAYCAST_RENDER_HEIGHT:
|
||||||
lineEnd = lineOffset + lineHeight
|
lineEnd = RAYCAST_RENDER_HEIGHT
|
||||||
lineStart = textureSegmentStart
|
lineStart = textureSegmentStart
|
||||||
if lineStart < 0:
|
if lineStart < 0:
|
||||||
lineStart = 0
|
lineStart = 0
|
||||||
|
if lineEnd < lineStart:
|
||||||
|
continue
|
||||||
|
|
||||||
# Upscaling
|
# Upscaling
|
||||||
lineStart = lineStart * RAYCAST_RESOLUTION_SCALING
|
lineStart = lineStart * RAYCAST_RESOLUTION_SCALING
|
||||||
lineEnd = lineEnd * RAYCAST_RESOLUTION_SCALING
|
lineEnd = lineEnd * RAYCAST_RESOLUTION_SCALING
|
||||||
|
|
||||||
# Draw segment
|
# Draw segment
|
||||||
for repeat in range(1, RAYCAST_RESOLUTION_SCALING + 1):
|
for repeat in range(1, RAYCAST_RESOLUTION_SCALING + 1):
|
||||||
x = i * RAYCAST_RESOLUTION_SCALING + repeat
|
x = i * RAYCAST_RESOLUTION_SCALING + repeat
|
||||||
self.drawVline(self.raycastSurface, color, x, int(lineStart), int(lineEnd))
|
self.drawVline(self.raycastSurface, color, x, int(lineStart), int(lineEnd))
|
||||||
|
|
||||||
def drawVline(self, surface, color, x, startY, endY):
|
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
|
startIdx = startY * RAYCAST_WIN_WIDTH + x
|
||||||
for idx in range(startIdx, endY * RAYCAST_WIN_WIDTH + x, RAYCAST_WIN_WIDTH):
|
for idx in range(startIdx, endY * RAYCAST_WIN_WIDTH + x, RAYCAST_WIN_WIDTH):
|
||||||
self.raycast_u32_pixels[idx] = color
|
self.raycast_u32_pixels[idx] = color
|
||||||
|
Loading…
Reference in New Issue
Block a user