forked from bedohswe/p3he
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from cmath import exp
|
|
from constants import *
|
|
from gyro import *
|
|
from lines import *
|
|
|
|
class DrawnSegment:
|
|
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):
|
|
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
|
|
if j.isFinite and not cBetween(j.pointA,j.pointB,cInt):
|
|
continue
|
|
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
|
|
|