Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fish eye correction but weird after affect
#1
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:
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
Quote
#2
Ok It looks like this effect is inevitable with this method of raycasting, but Im fine with the effect so I have another question, I am working on making a textured version of this code using this resource:https://www.permadi.com/tutorial/raycast/rayc10.html but I don't understand a thing it is saying or how it works
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyGame] Something weird happens with my game jdrp 0 422 May-05-2018, 11:30 AM
Last Post: jdrp

Forum Jump:


Users browsing this thread: 1 Guest(s)