-- collision ported to lua for pico 8 function ellipseVTri(pos, dir, tri) -- tri format: v1,v2,v3,normal local planeConst = -v_dot(tri[4], tri[1]) local dist = v_dot(tri[4], pos) + planeConst local modDir = v_dot(tri[4], dir) if (dist < 0) return local t0, t1, embedded = false if (modDir == 0) then if (abs(dist) < 1) then t0 = 0 t1 = 1 embedded = true else t0 = 1000 t1 = 2000 end else t0 = (1-dist)/modDir t1 = ((-1)-dist)/modDir end if (t0 > t1) then local temp = t1 t1 = t0 t0 = temp end if (not (t0>1 or t1<0)) then if (t0 < 0) then embedded = true t0 = 0 end if (t1 > 1) t1 = 1 local newT = t0 local pt = v_cln(pos) if (embedded) then local tmp=v_cln(tri[4]) v_scl(tmp,dist) v_sub(pt, tmp) else local tmp=v_cln(dir) v_scl(tmp,newT) v_add(pt, tmp) v_sub(pt, tri[4]) end if (pointInTriangle(tri, pt, 0) and newT= 0 and edgePos <= 1) then t = root colPlane = tri v_scl(distLine,edgePos) colPoint = v_cln(vert) v_add(colPoint,distLine) edge = true end end end end end end function getSmallestRoot(a, b, c, upperLimit) local det = (b*b) - 4*(a*c) if (det<0) then return -1 else det = sqrt(det) local root1 = ((-b)-det)/(2*a) local root2 = ((-b)+det)/(2*a) if (root1 > root2) then local temp = root1 root1 = root2 root2 = temp end if (root1>0 && root10 && root2=-err && v>=-err && (u+v)<1+err) }