From 64402f86b6ed3757e189a2a2bdd5f94820cfc4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Wed, 3 Apr 2024 17:35:29 +0500 Subject: [PATCH 1/4] A commit. --- gyro.py | 3 ++- main.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gyro.py b/gyro.py index 5986992..64a9b3b 100644 --- a/gyro.py +++ b/gyro.py @@ -35,7 +35,8 @@ class GyroVector: self.normalize() def __add__(gA, gB): - cAdd, cGyr = MobiusAddGyr(gA.cPos, gB.cPos * (1 / gA.cRot)) + #cAdd, cGyr = MobiusAddGyr(gA.cPos, gB.cPos / gA.cRot) + cAdd, cGyr = MobiusAddGyr(gA.cPos, gB.cPos) return GyroVector(cAdd, gA.cRot * gB.cRot * cGyr) def __neg__(self): diff --git a/main.py b/main.py index 9207d8d..9695542 100755 --- a/main.py +++ b/main.py @@ -86,9 +86,9 @@ def mainLoop(): if keys[pygame.K_a]: gPlayer.rotate(IROT) if keys[pygame.K_w]: - gPlayer -= GyroVector(OFFSET, 1) + gPlayer -= GyroVector(OFFSET * gPlayer.cRot, 1) if keys[pygame.K_s]: - gPlayer += GyroVector(OFFSET, 1) + 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) From d4b559555bb6f8d7012c81fb4ada78b5c9bca6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Wed, 3 Apr 2024 17:47:27 +0500 Subject: [PATCH 2/4] A commit. --- main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 9695542..3153790 100755 --- a/main.py +++ b/main.py @@ -20,6 +20,8 @@ IROT = 1/ROT F = 5 * 10**7 F_ = 10**9 +SKY = (127,127,255) +GROUND = (102, 51, 0) class Segment: def __init__(self,bA,cA,cB,trColor): @@ -34,10 +36,10 @@ class DrawnSegment: self.color = color level = [ - Segment(False,.5,I*.5,(255,0,0)), - Segment(False,.5,-I*.5,(0,255,0)), - Segment(False,-.5,-I*.5,(0,0,255)), - Segment(False,-.5,I*.5,(255,255,0)) + 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)) ] def draw(level,gPlayer,fov,res): @@ -54,7 +56,7 @@ def draw(level,gPlayer,fov,res): cInt = cLineIntersection(tA,tB,complex(0),rot) except ZeroDivisionError: continue - rDist = cDist(0,cInt) + rDist = cDist(0,cInt) * irot.real if cDot(cInt,rot) > 0: continue if (1 - m.height) > rDist: @@ -92,9 +94,11 @@ def mainLoop(): display.fill(WHITE) #pygame.draw.rect(display,BLACK, c_tr(Poincare2Klein(gPlayer.cPos) * -100) + (100,100),0) drawn = draw(level,gPlayer,PI/2,640) + 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) * 500),10,cap(i.height) * 1000)) + pygame.draw.rect(display,i.color, (n,360 - (cap(i.height) * 360),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)) From 0d6d8c3339b4451f2579b042156ba4edd2437dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Wed, 3 Apr 2024 17:56:02 +0500 Subject: [PATCH 3/4] A commit. --- gyro.py | 9 +++++---- main.py | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/gyro.py b/gyro.py index 64a9b3b..e58de0e 100644 --- a/gyro.py +++ b/gyro.py @@ -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): diff --git a/main.py b/main.py index 3153790..24e8f25 100755 --- a/main.py +++ b/main.py @@ -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() From a0a33254e36f4e61b7b736cb6884e7951e70e35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Wed, 3 Apr 2024 18:06:28 +0500 Subject: [PATCH 4/4] A commit. --- gyro.py | 10 +++++----- main.py | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/gyro.py b/gyro.py index e58de0e..95fabed 100644 --- a/gyro.py +++ b/gyro.py @@ -1,7 +1,7 @@ -from numpy import complex128 +from numpy import complex256 def ZeroCheck(cN): - if cN == complex128(complex(0,0)): - return complex128(complex(1,0)) + if cN == complex256(complex(0,0)): + return complex256(complex(1,0)) else: return cN @@ -31,8 +31,8 @@ def Poincare2Klein(cN): class GyroVector: def __init__(self, cPos, cRot): - self.cPos = complex128(cPos) - self.cRot = complex128(cRot) + self.cPos = complex256(cPos) + self.cRot = complex256(cRot) self.normalize() def __add__(gA, gB): diff --git a/main.py b/main.py index 24e8f25..5939f13 100755 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -from numpy import complex128 +from numpy import complex256 from time import time_ns, sleep from cmath import exp, pi import pygame @@ -11,7 +11,7 @@ from lines import * def deg2rad(rA): return rA/180*PI -I = complex128(complex(0,1)) +I = complex256(complex(0,1)) WHITE = (255,255,255) BLACK = (0,0,0) OFFSET = 0.015625 @@ -37,10 +37,10 @@ class DrawnSegment: self.color = color level = [ - 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)) + Segment(True,.6,I*.6,(255,0,0)), + Segment(True,.6,-I*.6,(0,255,0)), + Segment(True,-.6,-I*.6,(0,0,255)), + Segment(True,-.6,I*.6,(255,255,0)) ] def draw(level,gPlayer,fov,res): @@ -54,10 +54,12 @@ 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,complex128(0),rot) + cInt = cLineIntersection(tA,tB,complex256(0),rot) except ZeroDivisionError: continue - rDist = cDist(0,cInt) * irot.real + rDist = cDist(0,cInt) + if not (j.isFinite and cBetween(tA,tB,cInt)): + continue if cDot(cInt,rot) > 0: continue if (1 - m.height) > rDist: