A commit.

This commit is contained in:
bʰedoh₂ swé 2024-04-03 16:46:22 +05:00
parent 1bf215fbf1
commit 6b4380d130

24
main.py
View File

@ -8,12 +8,14 @@ from gyro import *
from lines import *
def deg2rad(rA): return rA/180*PI
WHITE = (255,255,255)
BLACK = (0,0,0)
OFFSET = .00781250
OFFSET = .015625
I = complex(0,1)
PI = 3.14159265358979323846264338327
ROT = cNorm(0.99939 + 0.0003490*I)
ROT = cNorm(exp(deg2rad(2)*I))
IROT = 1/ROT
F = 5 * 10**7
F_ = 10**9
@ -33,20 +35,24 @@ class DrawnSegment:
level = [
# Segment(False,cNorm(-1),cNorm(I),(255,255,20)),
Segment(False,cNorm(-1),cNorm(I),BLACK)
Segment(False,-.5,I*.5,BLACK)
]
def draw(level,gPlayer,fov,res):
drawn = list()
irot = exp(fov/res*I)
iprot = gPlayer.cRot
for i in range(res):
m = DrawnSegment(0,BLACK)
rot = irot**(i-(res/2)) * gPlayer.cRot
rot = irot**(i-(res/2)) * iprot
for j in level:
tA = Poincare2Klein(MobiusAdd(j.pointA,-gPlayer.cPos))
tB = Poincare2Klein(MobiusAdd(j.pointB,-gPlayer.cPos))
cInt = cLineIntersection(tA,tB,complex(0),rot)
rDist = cDist(0,cInt)
try: # This function faults from time to time
cInt = cLineIntersection(tA,tB,complex(0),rot)
except ZeroDivisionError:
continue
rDist = cDist(0,cInt)
if cDot(cInt,rot) > 0:
continue
if (1 - m.height) > rDist:
@ -80,11 +86,11 @@ def mainLoop():
gPlayer -= GyroVector(OFFSET, 1)
display.fill(WHITE)
#pygame.draw.rect(display,BLACK, c_tr(Poincare2Klein(gPlayer.cPos) * -100) + (100,100),0)
drawn = draw(level,gPlayer,PI/2,40)
drawn = draw(level,gPlayer,PI/2,640)
n = 0
for i in drawn:
pygame.draw.rect(display,i.color, (n,500 - (cap(i.height) * 500),10,cap(i.height) * 1000))
n += 10
pygame.draw.rect(display,i.color, (n,360 - (cap(i.height) * 500),10,cap(i.height) * 1000))
n += 2
font.render_to(display, (20, 150), str(gPlayer.cPos), (0, 0, 0))
font.render_to(display, (20, 250), str(gPlayer.cRot), (0, 0, 0))
pygame.display.update()