diff --git a/html/images/space.svg b/html/images/space.svg index 81c50c0..4ef3e44 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -112,7 +112,7 @@ - + @@ -190,7 +190,7 @@ const s = { position: { x: 0, y: 0 }, // velocity: { x: 0, y: 0 }, - velocity: { x: 0, y: -8 }, + velocity: { x: 0, y: -5000 }, // velocity: { x: 0.25 * mult, y: 1 * mult }, // velocity: { x: 0, y: 1 * mult }, @@ -386,8 +386,8 @@ const d = Math.abs(diffy * x0 - diffx * y0 + detv) / dv; // console.log("corner", c, "d", d, "shipRadius", shipRadius); return d <= shipRadius; - // }).map(c => ({ corner: c, node: w })); - }); + }).map(c => ({ corner: c, node: w.node })); + // }); return [...acc, ...filtered]; }, []); @@ -576,7 +576,30 @@ return detectEdgeCollision(position, pts, r); }); - return edge || actualCorner; + // return edge || actualCorner; + return actualCorner; + } + + function cornerCollisionPosition({ x: x1, y: y1 }, { x: x2, y: y2 }) { + const diffx = x2; + const diffy = y2; + const detv = x2 * y1 - y2 * x1; + const dv = Math.sqrt(diffy ** 2 + diffx ** 2); + const slopev = slope({ xa: x1, ya: y1, xb: x1 + x2, yb: y1 + y2 }); + + return ({ corner: { x: x0, y: y0 }, node: n }) => { + const velNormIntxn = perpIntxn(slopev, x1, y1, x0, y0); + const d = Math.abs(diffy * x0 - diffx * y0 + detv) / dv; + const b = Math.sqrt(shipRadius ** 2 - d ** 2); + + const cl = document.createElementNS(namespaceURIsvg, 'line'); + cl.setAttribute('x1', velNormIntxn.x); + cl.setAttribute('y1', velNormIntxn.y); + cl.setAttribute('x2', x1); + cl.setAttribute('y2', y1); + + return cl.getPointAtLength(b); + }; } function collisionPosition(edge, position, velocity, radius) { @@ -649,20 +672,24 @@ const changeY = 0.001 * elapsed * velocityY; let { x, y } = s.position; - // console.log("current position", x, y); - let position = [positionX, positionY] = restart ? [0, 0] : wrapPos(changeX + x, changeY + y); + console.log("current position", x, y); + // console.log("elapsed", elapsed, "changeX", changeX, "changeY", changeY); + // let position = [positionX, positionY] = restart ? [0, 0] : wrapPos(changeX + x, changeY + y); + let position = [positionX, positionY] = [changeX + x, changeY + y]; let [xc, yc] = position; + console.log("future position", xc, yc); const collE = getCollisionEdges(edgeszz, position); // console.log("position", { x, y }, "velocity", s.velocity); const collC = getCollisionCorners(ws, { x, y }, s.velocity); console.log("collision corners", collC); + ccps = collC.map(cornerCollisionPosition({ x, y }, s.velocity)); + console.log("corner collision position", ccps); current = s.collision; s.collision = detectCollisions(position, allWallCorners, collE); - // console.log("future position", xc, yc); // legs.style.display = !legs.style.display || legs.style.display === "none" ? "initial" : "none"; legs.style.display = s.gearDown ? "initial" : "none";