A commit.

This commit is contained in:
bʰedoh₂ swé 2024-04-03 17:56:02 +05:00
parent d4b559555b
commit 0d6d8c3339
2 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,7 @@
from numpy import complex128
def ZeroCheck(cN):
if cN == complex(0,0):
return complex(1,0)
if cN == complex128(complex(0,0)):
return complex128(complex(1,0))
else:
return cN
@ -30,8 +31,8 @@ def Poincare2Klein(cN):
class GyroVector:
def __init__(self, cPos, cRot):
self.cPos = complex(cPos)
self.cRot = complex(cRot)
self.cPos = complex128(cPos)
self.cRot = complex128(cRot)
self.normalize()
def __add__(gA, gB):

21
main.py
View File

@ -1,7 +1,8 @@
#!/usr/bin/env python3
from numpy import complex128
from time import time_ns, sleep
from cmath import exp
from cmath import exp, pi
import pygame
import pygame.freetype
from gyro import *
@ -10,11 +11,11 @@ from lines import *
def deg2rad(rA): return rA/180*PI
I = complex(0,1)
I = complex128(complex(0,1))
WHITE = (255,255,255)
BLACK = (0,0,0)
OFFSET = 0.015625
PI = 3.14159265358979323846264338327
PI = pi
ROT = cNorm(exp(deg2rad(2)*I))
IROT = 1/ROT
F = 5 * 10**7
@ -36,10 +37,10 @@ class DrawnSegment:
self.color = color
level = [
Segment(False,.7,I*.7,(255,0,0)),
Segment(False,.7,-I*.7,(0,255,0)),
Segment(False,-.7,-I*.7,(0,0,255)),
Segment(False,-.7,I*.7,(255,255,0))
Segment(False,.6,I*.6,(255,0,0)),
Segment(False,.6,-I*.6,(0,255,0)),
Segment(False,-.6,-I*.6,(0,0,255)),
Segment(False,-.6,I*.6,(255,255,0))
]
def draw(level,gPlayer,fov,res):
@ -53,7 +54,7 @@ def draw(level,gPlayer,fov,res):
tA = Poincare2Klein(MobiusAdd(j.pointA,-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,complex128(0),rot)
except ZeroDivisionError:
continue
rDist = cDist(0,cInt) * irot.real
@ -93,13 +94,13 @@ def mainLoop():
gPlayer += GyroVector(OFFSET * gPlayer.cRot, 1)
display.fill(WHITE)
#pygame.draw.rect(display,BLACK, c_tr(Poincare2Klein(gPlayer.cPos) * -100) + (100,100),0)
drawn = draw(level,gPlayer,PI/2,640)
drawn = draw(level,gPlayer,PI/2,160)
pygame.draw.rect(display,SKY, (0,0,1280,360))
pygame.draw.rect(display,GROUND, (0,360,1280,360))
n = 0
for i in drawn:
pygame.draw.rect(display,i.color, (n,360 - (cap(i.height) * 360),10,cap(i.height) * 1000))
n += 2
n += 8
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()