p3he/draw.py

36 lines
1.1 KiB
Python
Raw Normal View History

from cmath import exp
from constants import *
from gyro import *
from lines import *
class DrawnSegment:
2024-04-04 20:46:39 +00:00
def __init__(self,dist,color):
self.dist = dist
self.color = color
def draw(level,gPlayer,fov,res):
drawn = list()
irot = exp(fov/res*I)
iprot = gPlayer.cRot
for i in range(res):
2024-04-04 20:46:39 +00:00
m = None
rot = irot**(i-(res/2)) * iprot
for j in level:
try: # Function "LineIntersection" faults from time to time
cInt = MobiusInt(j.pointA,j.pointB,gPlayer.cPos,rot)
except ZeroDivisionError:
continue
if cDot(rot,MobiusAdd(cInt,-gPlayer.cPos)) > 0:
continue
rDist = MobiusDist(cInt,gPlayer.cPos)*1.1
2024-04-04 20:31:27 +00:00
if j.isFinite and not cBetween(j.pointA,j.pointB,cInt):
continue
2024-04-04 20:46:39 +00:00
if m is None:
m = DrawnSegment(rDist,j.color)
continue
if m.dist > rDist:
m = DrawnSegment(rDist,j.color)
drawn.append(m if m is not None else DrawnSegment(0, BLACK))
return drawn