WIP Vertical line check
This commit is contained in:
parent
142a92b2fc
commit
082097e0d0
46
raycaster.py
46
raycaster.py
@ -124,26 +124,24 @@ class Main:
|
|||||||
# Casts rays for raycasting
|
# Casts rays for raycasting
|
||||||
rayAngle = self.player_position["r"]
|
rayAngle = self.player_position["r"]
|
||||||
for r in range(1):
|
for r in range(1):
|
||||||
|
'''
|
||||||
# Check horizontal lines
|
# Check horizontal lines
|
||||||
dof = 0 # Depth of field
|
dof = 0 # Depth of field
|
||||||
if rayAngle == 0 or rayAngle == math.pi:
|
if rayAngle == 0 or rayAngle == math.pi:
|
||||||
print("horiz")
|
|
||||||
# Looking left or right (ray will never intersect parallel lines)
|
# Looking left or right (ray will never intersect parallel lines)
|
||||||
rayY = self.player_position["y"]
|
rayY = self.player_position["y"]
|
||||||
rayX = self.player_position["x"]
|
rayX = self.player_position["x"]
|
||||||
dof = DOF # Set depth of field to maximum to avoid unneeded checks
|
dof = DOF # Set depth of field to maximum to avoid unneeded checks
|
||||||
elif rayAngle > math.pi:
|
elif rayAngle > math.pi:
|
||||||
aTan = -1/math.tan(rayAngle)
|
|
||||||
print("down")
|
|
||||||
# Looking up
|
# Looking up
|
||||||
|
aTan = -1/math.tan(rayAngle)
|
||||||
rayY = (int(self.player_position["y"] / MAP_SCALE) * MAP_SCALE) - 0.00001
|
rayY = (int(self.player_position["y"] / MAP_SCALE) * MAP_SCALE) - 0.00001
|
||||||
rayX = (self.player_position["y"] - rayY) * aTan + self.player_position["x"]
|
rayX = (self.player_position["y"] - rayY) * aTan + self.player_position["x"]
|
||||||
yOffset = -MAP_SCALE
|
yOffset = -MAP_SCALE
|
||||||
xOffset = -yOffset * aTan
|
xOffset = -yOffset * aTan
|
||||||
else:
|
else:
|
||||||
aTan = -1/math.tan(rayAngle)
|
|
||||||
print("up")
|
|
||||||
# Looking down
|
# Looking down
|
||||||
|
aTan = -1/math.tan(rayAngle)
|
||||||
rayY = (int(self.player_position["y"] / MAP_SCALE) * MAP_SCALE) + MAP_SCALE
|
rayY = (int(self.player_position["y"] / MAP_SCALE) * MAP_SCALE) + MAP_SCALE
|
||||||
rayX = (self.player_position["y"] - rayY) * aTan + self.player_position["x"]
|
rayX = (self.player_position["y"] - rayY) * aTan + self.player_position["x"]
|
||||||
yOffset = MAP_SCALE
|
yOffset = MAP_SCALE
|
||||||
@ -161,9 +159,45 @@ class Main:
|
|||||||
rayX = rayX + xOffset
|
rayX = rayX + xOffset
|
||||||
rayY = rayY + yOffset
|
rayY = rayY + yOffset
|
||||||
dof = dof + 1
|
dof = dof + 1
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Check vertical lines
|
||||||
|
dof = 0 # Depth of field
|
||||||
|
nTan = -math.tan(rayAngle)
|
||||||
|
if rayAngle == math.pi * 0.5 or rayAngle == math.pi * 1.5:
|
||||||
|
# Looking up or down (ray will never intersect vertical lines)
|
||||||
|
rayX = self.player_position["y"]
|
||||||
|
rayY = self.player_position["x"]
|
||||||
|
dof = DOF # Set depth of field to maximum to avoid unneeded checks
|
||||||
|
elif rayAngle > math.pi * 0.5 and rayAngle < math.pi * 1.5:
|
||||||
|
# Looking right
|
||||||
|
rayX = (int(self.player_position["x"] / MAP_SCALE) * MAP_SCALE) - 0.00001
|
||||||
|
rayY = (self.player_position["x"] - rayX) * nTan + self.player_position["y"]
|
||||||
|
xOffset = -MAP_SCALE
|
||||||
|
yOffset = -xOffset * nTan
|
||||||
|
else:
|
||||||
|
# Looking left
|
||||||
|
rayX = (int(self.player_position["x"] / MAP_SCALE) * MAP_SCALE) + MAP_SCALE
|
||||||
|
rayY = (self.player_position["x"] - rayX) * nTan + self.player_position["y"]
|
||||||
|
xOffset = MAP_SCALE
|
||||||
|
yOffset = -xOffset * nTan
|
||||||
|
|
||||||
|
# Check if we reached a wall
|
||||||
|
while dof < 8:
|
||||||
|
mapX = int(rayX / MAP_SCALE)
|
||||||
|
mapY = int(rayY / MAP_SCALE)
|
||||||
|
mapArrayPosition = mapY * MAP_SIZE + mapX
|
||||||
|
print([rayX, rayY, mapX, mapY, mapArrayPosition])
|
||||||
|
if mapArrayPosition < MAP_SIZE*MAP_SIZE and MAP[mapArrayPosition] != 0:
|
||||||
|
dof = 8 # Hit the wall: we are done, no need to do other checks
|
||||||
|
else:
|
||||||
|
# Didn't hit the wall: check successive horizontal line
|
||||||
|
rayX = rayX + xOffset
|
||||||
|
rayY = rayY + yOffset
|
||||||
|
dof = dof + 1
|
||||||
|
|
||||||
# Draw ray
|
# Draw ray
|
||||||
sdl2.ext.draw.line(self.mapSurface, sdl2.ext.Color(0,255,0,255), (self.player_position["x"], self.player_position["y"], rayX, rayY))
|
sdl2.ext.draw.line(self.mapSurface, sdl2.ext.Color(0,0,255,255), (self.player_position["x"], self.player_position["y"], rayX, rayY))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user