function pointInTriangle ax ay az c1x c1y c1z c2x c2y c2z c3x c3y c3z call sameSide ax ay az c1x c1y c1z c2x c2y c2z c3x c3y c3z if then else isSameSide call sameSide ax ay az c2x c2y c2z c1x c1y c1z c3x c3y c3z if then else isSameSide call sameSide ax ay az c3x c3y c3z c1x c1y c1z c2x c2y c2z isSameSide set isPointInTriangle to false set isPointInTriangle to false set isPointInTriangle to function sameSide ax ay az bx by bz cx cy cz dx dy dx cx - dy cy - dz cz - cx ax - cy ay - cz az - sy caz × sz cay × - sz cax × sx caz × - sx cay × sy cax × - cx bx - cy by - cz bz - sy cbz × sz cby × - sz cbx × sx cbz × - sx cby × sy cbx × - cp1x cp2x × cp1y cp2y × cp1z cp2z × dotx doty + dotz + 0 set isSameSide to set dotz to set doty to set dotx to set cp2z to set cp2y to set cp2x to set cbz to set cby to set cbx to set cp1z to set cp1y to set cp1x to set caz to set cay to set cax to set sz to set sy to set sx to dz function getIntersectionDistance linePointX linePointY linePointZ lineAngleX lineAngleY lineAngleZ planeA planeB planeC planeK tc1x tc1y tc1z tc2x tc2y tc2z tc3x tc3y tc3z tminx tminy tminz tmaxx tmaxy tmaxz 0 call getLambda planeA planeB planeC planeK linePointX linePointY linePointZ lineAngleX lineAngleY lineAngleZ lambda linePointX lambda lineAngleX × + z tminx z tmaxx linePointY lambda lineAngleY × + a tminy a tmaxy linePointZ lambda lineAngleZ × + b tminz b tmaxz call pointInTriangle z a b tc1x tc1y tc1z tc2x tc2y tc2z tc3x tc3y tc3z isPointInTriangle lambda set intersectionDistance to if then if then if then set b to if then if then set a to if then if then set z to if then set intersectionDistance to function getLambda planeA planeB planeC planeK linePointX linePointY linePointZ lineAngleX lineAngleY lineAngleZ call getScale planeA planeB planeC lineAngleX lineAngleY lineAngleZ scale 0 planeA linePointX × planeB linePointY × + planeC linePointZ × + planeK + - scale ÷ set lambda to if then function render screenSize cameraRays × rays 1 - 2 ÷ 0 0 1 call rotateInX cameraPitch call rotateInY cameraYaw vectorX vectorY vectorZ viewWidth rays ÷ 0 0 call rotateInX cameraPitch call rotateInY cameraYaw vectorX vectorY vectorZ 0 viewWidth rays ÷ 0 call rotateInX cameraPitch call rotateInY cameraYaw vectorX vectorY vectorZ cameraVectorX xIncVectorX raysExtreme × - yIncVectorX raysExtreme × - cameraVectorY xIncVectorY raysExtreme × - yIncVectorY raysExtreme × - cameraVectorZ xIncVectorZ raysExtreme × - yIncVectorZ raysExtreme × - call resetPixels y rays 1 - x rays 1 - x cameraRays ÷ floor y cameraRays ÷ floor rayStartVectorX xIncVectorX x × + yIncVectorX y × + rayStartVectorY xIncVectorY x × + yIncVectorY y × + rayStartVectorZ xIncVectorZ x × + yIncVectorZ y × + call traceRay xPx yPx cameraCoordX cameraCoordY cameraCoordZ rayVectorX rayVectorY rayStartVectorZ set rayVectorZ to set rayVectorY to set rayVectorX to set yPx to set xPx to for from 0 to do call display for from 0 to do set rayStartVectorZ to set rayStartVectorY to set rayStartVectorX to set yIncVectorZ to set yIncVectorY to set yIncVectorX to set vectorZ to set vectorY to set vectorX to set xIncVectorZ to set xIncVectorY to set xIncVectorX to set vectorZ to set vectorY to set vectorX to set cameraVectorZ to set cameraVectorY to set cameraVectorX to set vectorZ to set vectorY to set vectorX to set raysExtreme to set rays to function getScale planeA planeB planeC angleX angleY angleZ planeA angleX × planeB angleY × + planeC angleZ × + set scale to function rotateInY rads vectorX cos rads × vectorZ sin rads × + 0 vectorX - sin rads × vectorZ cos rads × + newX newZ2 set vectorZ to set vectorX to set newZ2 to set newX to let scale: number; let lambda: number; let intersectionDistance: number; let isSameSide: boolean; let isPointInTriangle: boolean; 1 5 1 0.05 let triangleCoords: number[][]; empty array let triangle1: number[]; empty array triangle1 -1 triangle1 0 triangle1 2 triangle1 0 triangle1 -2 triangle1 3 triangle1 1 triangle1 0 triangle1 2 triangle1 bright triangleCoords triangle1 let triangle2: number[]; empty array triangle2 -1 triangle2 0 triangle2 4 triangle2 0 triangle2 -2 triangle2 3 triangle2 1 triangle2 0 triangle2 4 triangle2 dim triangleCoords triangle2 let triangle3: number[]; empty array triangle3 -1 triangle3 0 triangle3 2 triangle3 0 triangle3 -2 triangle3 3 triangle3 -1 triangle3 0 triangle3 4 triangle3 dim triangleCoords triangle3 let triangle4: number[]; empty array triangle4 1 triangle4 0 triangle4 2 triangle4 0 triangle4 -2 triangle4 3 triangle4 1 triangle4 0 triangle4 4 triangle4 bright triangleCoords triangle4