A commit.

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

20
main.py
View File

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