Mar-14-2019, 12:54 AM (This post was last modified: Mar-14-2019, 01:04 AM by robie972003.)

When I finished my raycaster (pseudo 3d engine) I found out that when ever you look closely at a wall, it appears to be bent. Ex:

Straight wall:

_________________

_________________

Fish eye wall:

____________

..-- --..

..__ __..

------------

I combated this by inserting a line of code:

Help!

..--'''''''''''--..

''--...........--''

Here is the fish eye wall as it appears weird in my previous post

Straight wall:

_________________

_________________

Fish eye wall:

____________

..-- --..

..__ __..

------------

I combated this by inserting a line of code:

lis[i] = distance * math.sin(math.radians(90 - angle))but instead of the wall being straight when up close, it appeared to have many weird curves.

Help!

import turtle import math import pygame pygame.init() pygame.display.set_mode() events = pygame.event.get() colors = {1: "Blue", 2: "Mediumblue", 3: "Red", 4: "Crimson"} # I call this tab # Instructions: # UP = forward # LEFT = left # RIGHT = right # DOWN = backwards # Do not run into the walls partly because I haven't coded the collision # detection and also partly because it displays an error right after screen = turtle.Screen() screen.bgcolor("White") turtx = 0 turty = 0 plrx = 0 plry = 0 plrA = 45 draw = turtle.Turtle() draw.penup() draw.pensize(7) draw.speed(0) draw.hideturtle() angle = -35 distance = 0 lis = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] lis2 = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: plrA = plrA - 15 break if event.key == pygame.K_RIGHT: plrA = plrA + 15 break if event.key == pygame.K_UP: plrx = plrx + (math.sin(math.radians(90 - plrA)) * 5) plry = plry + (math.cos(math.radians(90 - plrA)) * 5) break if event.key == pygame.K_DOWN: plrx = plrx - (math.sin(math.radians(90 - plrA)) * 5) plry = plry - (math.cos(math.radians(90 - plrA)) * 5) break angle = -35 for i in range(70): turtx = plrx turty = plry distance = 0 for m in range(150): lis2[i] = 0 # bounderies if (turtx > 20): lis2[i] = 1 break if (turty < -20): lis2[i] = 2 break if (turty > 20): lis2[i] = 2 break if (turtx < -20): lis2[i] = 1 break turtx = turtx + math.cos(math.radians(plrA + angle)) turty = turty + math.sin(math.radians(plrA + angle)) distance = math.sqrt(((turtx - plrx) ** 2) + ((turty - plry) ** 2)) lis[i] = distance * math.sin(math.radians(90 - angle)) angle += 1 draw.setx(-200) draw.clear() for i in range(70): draw.tracer(0, 0) draw.sety(200) draw.pendown() draw.color("Grey") draw.sety(800 / lis[i]) draw.color(colors.get(lis2[i])) draw.sety(-800 / lis[i]) draw.color("Saddlebrown") draw.sety(-200) draw.penup() draw.setx(draw.xcor() + 5) draw.color("Black") draw.update()

..--'''''''''''--..

''--...........--''

Here is the fish eye wall as it appears weird in my previous post