Render natively in Poincaré.
This commit is contained in:
parent
380b9f96a4
commit
f7ee5715c7
33
gyro.py
33
gyro.py
@ -3,6 +3,10 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from numpy import complex128 as complex256
|
from numpy import complex128 as complex256
|
||||||
|
|
||||||
|
from cmath import sqrt
|
||||||
|
from math import tanh, atanh
|
||||||
|
from lines import cLineIntersection
|
||||||
|
|
||||||
def ZeroCheck(cN):
|
def ZeroCheck(cN):
|
||||||
if cN == complex256(complex(0,0)):
|
if cN == complex256(complex(0,0)):
|
||||||
return complex256(complex(1,0))
|
return complex256(complex(1,0))
|
||||||
@ -21,6 +25,9 @@ def cDot(cA, cB):
|
|||||||
def cDist(cA, cB):
|
def cDist(cA, cB):
|
||||||
return abs(cA-cB)
|
return abs(cA-cB)
|
||||||
|
|
||||||
|
def MobiusInt(cA,cB,cC,cD): # Bruh
|
||||||
|
return Klein2Poincare(cLineIntersection(Poincare2Klein(cA),Poincare2Klein(cB),Poincare2Klein(cC),Poincare2Klein(cD)))
|
||||||
|
|
||||||
def MobiusAdd(cA, cB):
|
def MobiusAdd(cA, cB):
|
||||||
return (cA + cB) / (1 + cA.conjugate() * cB)
|
return (cA + cB) / (1 + cA.conjugate() * cB)
|
||||||
|
|
||||||
@ -30,9 +37,32 @@ def MobiusGyr(cA, cB):
|
|||||||
def MobiusAddGyr(cA, cB):
|
def MobiusAddGyr(cA, cB):
|
||||||
return MobiusAdd(cA, cB), MobiusGyr(cA, cB)
|
return MobiusAdd(cA, cB), MobiusGyr(cA, cB)
|
||||||
|
|
||||||
|
def MobiusScalar(cA, rT):
|
||||||
|
m = abs(cA)
|
||||||
|
return tanh(rT * atanh(m)) * cA / m
|
||||||
|
|
||||||
|
def MobiusCoadd(cA,cB):
|
||||||
|
return MobiusAdd(cA, (MobiusGyr(cA,-cB) * cB))
|
||||||
|
|
||||||
|
def MobiusCosub(cA,cB):
|
||||||
|
return MobiusAdd(cA, -(MobiusGyr(cA,cB) * cB))
|
||||||
|
|
||||||
|
def MobiusLine(cA,cB,rT):
|
||||||
|
return MobiusAdd(
|
||||||
|
cA,
|
||||||
|
MobiusScalar(
|
||||||
|
MobiusAdd(-cA,cB),
|
||||||
|
rT))
|
||||||
|
|
||||||
|
def MobiusDist(cA,cB):
|
||||||
|
return abs(MobiusAdd(-cB,cA))
|
||||||
|
|
||||||
def Poincare2Klein(cN):
|
def Poincare2Klein(cN):
|
||||||
return 2*cN / (1 + cDot(cN,cN))
|
return 2*cN / (1 + cDot(cN,cN))
|
||||||
|
|
||||||
|
def Klein2Poincare(cN):
|
||||||
|
return (1-sqrt(1-cDot(cN,cN)))*cN/cDot(cN,cN)
|
||||||
|
|
||||||
class GyroVector:
|
class GyroVector:
|
||||||
def __init__(self, cPos, cRot):
|
def __init__(self, cPos, cRot):
|
||||||
self.cPos = complex256(cPos)
|
self.cPos = complex256(cPos)
|
||||||
@ -74,3 +104,6 @@ class GyroVector:
|
|||||||
|
|
||||||
def nrtransformed(self, cA):
|
def nrtransformed(self, cA):
|
||||||
return MobiusAdd(self.cPos, cA / self.cRot)
|
return MobiusAdd(self.cPos, cA / self.cRot)
|
||||||
|
|
||||||
|
def dist(self,gA):
|
||||||
|
return abs((-self+gA).cPos)
|
||||||
|
22
main.py
22
main.py
@ -24,6 +24,8 @@ IROT = 1/ROT
|
|||||||
F = 5 * 10**7
|
F = 5 * 10**7
|
||||||
F_ = 10**9
|
F_ = 10**9
|
||||||
|
|
||||||
|
gOrigin = GyroVector(complex256(0),1)
|
||||||
|
|
||||||
SKY = (127,127,255)
|
SKY = (127,127,255)
|
||||||
GROUND = (102, 51, 0)
|
GROUND = (102, 51, 0)
|
||||||
|
|
||||||
@ -54,16 +56,16 @@ def draw(level,gPlayer,fov,res):
|
|||||||
m = DrawnSegment(0,BLACK)
|
m = DrawnSegment(0,BLACK)
|
||||||
rot = irot**(i-(res/2)) * iprot
|
rot = irot**(i-(res/2)) * iprot
|
||||||
for j in level:
|
for j in level:
|
||||||
tA = Poincare2Klein(MobiusAdd(j.pointA,-gPlayer.cPos))
|
#tA = MobiusAdd(j.pointA,-gPlayer.cPos)
|
||||||
tB = Poincare2Klein(MobiusAdd(j.pointB,-gPlayer.cPos))
|
#tB = MobiusAdd(j.pointB,-gPlayer.cPos)
|
||||||
try: # This function faults from time to time
|
try: # Function "LineIntersection" faults from time to time
|
||||||
cInt = cLineIntersection(tA,tB,complex256(0),rot)
|
cInt = MobiusInt(j.pointA,j.pointB,gPlayer.cPos,rot)
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
continue
|
continue
|
||||||
rDist = cDist(0,cInt) * irot.real
|
if cDot(rot,MobiusAdd(cInt,-gPlayer.cPos)) > 0:
|
||||||
if not (j.isFinite and cBetween(tA,tB,cInt)):
|
|
||||||
continue
|
continue
|
||||||
if cDot(cInt,rot) > 0:
|
rDist = MobiusDist(cInt,gPlayer.cPos)
|
||||||
|
if not (j.isFinite and cBetween(j.pointA,j.pointB,cInt)):
|
||||||
continue
|
continue
|
||||||
if (1 - m.height) > rDist:
|
if (1 - m.height) > rDist:
|
||||||
m = DrawnSegment(1-rDist,j.color)
|
m = DrawnSegment(1-rDist,j.color)
|
||||||
@ -116,13 +118,13 @@ def mainLoop():
|
|||||||
|
|
||||||
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,160)
|
drawn = draw(level,gPlayer,PI/4,320)
|
||||||
pygame.draw.rect(display,SKY, (0,0,1280,360))
|
pygame.draw.rect(display,SKY, (0,0,1280,360))
|
||||||
pygame.draw.rect(display,GROUND, (0,360,1280,360))
|
pygame.draw.rect(display,GROUND, (0,360,1280,360))
|
||||||
n = 0
|
n = 0
|
||||||
for i in drawn:
|
for i in drawn:
|
||||||
pygame.draw.rect(display,i.color, (n,(1 - i.height) * 360,8,cap(i.height) * 1280))
|
pygame.draw.rect(display,i.color, (n,int((1 - cap(i.height)) * 360),8,int(cap(i.height) * 1280)))
|
||||||
n += 8
|
n += 4
|
||||||
|
|
||||||
if debugInfo:
|
if debugInfo:
|
||||||
fps_surf, cPos_surf, cRot_surf = renderDebugInfo(gPlayer, clock, fontSize)
|
fps_surf, cPos_surf, cRot_surf = renderDebugInfo(gPlayer, clock, fontSize)
|
||||||
|
Loading…
Reference in New Issue
Block a user