p3he/draw.py

47 lines
1.4 KiB
Python
Raw Normal View History

from cmath import exp
2024-04-05 12:40:54 +00:00
from constants import I, BLACK
from gyro import MobiusInt, MobiusAdd, MobiusBetween, MobiusDist, cDot, Poincare2Klein
2024-04-05 12:40:54 +00:00
from numba import jit, byte, double, prange, optional
from numba.types import UniTuple
from numba.typed import List as nlist
from numba.experimental import jitclass
from numpy import full
drawnsegmentsig = [
('dist', double),
('color', UniTuple(byte, 3))
]
@jitclass(drawnsegmentsig)
class DrawnSegment:
2024-04-04 20:46:39 +00:00
def __init__(self,dist,color):
self.dist = dist
self.color = color
2024-04-05 12:40:54 +00:00
@jit#(cache=True,parallel=True)
2024-04-07 12:48:14 +00:00
def draw(level,gPlayer,fov,res,dscale):
2024-04-05 12:40:54 +00:00
EMPTYDRAWN = DrawnSegment(0, BLACK)
drawn = [EMPTYDRAWN] * res
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:
cInt = MobiusInt(j.pointA,j.pointB,gPlayer.cPos,rot)
if cDot(rot,MobiusAdd(cInt,-gPlayer.cPos)) > 0:
continue
2024-04-07 12:48:14 +00:00
rDist = MobiusDist(cInt,gPlayer.cPos) * dscale
if j.isFinite and not MobiusBetween(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)
2024-04-05 12:40:54 +00:00
drawn[i] = (m if m is not None else EMPTYDRAWN)
return drawn