Place contact point just outside wall shape

This commit is contained in:
2026-02-02 14:27:48 -08:00
parent 93157f17dd
commit fae1fd255f

View File

@@ -244,17 +244,17 @@ const Move = (() => {
// https://en.wikipedia.org/wiki/Curve_orientation#Practical_considerations // https://en.wikipedia.org/wiki/Curve_orientation#Practical_considerations
// Determinant for a convex polygon // Determinant for a convex polygon
// const det = (xb - xa) * (yc - ya) - (xc - xa) * (yb - ya); const det = (xb - xa) * (yc - ya) - (xc - xa) * (yb - ya);
const subR = (a, b) => Math.round(a * 100 - b * 100) / 100; // const subR = (a, b) => Math.round(a * 100 - b * 100) / 100;
//
const xba = subR(xb, xa); // const xba = subR(xb, xa);
const yca = subR(yc, ya); // const yca = subR(yc, ya);
const xca = subR(xc, xa); // const xca = subR(xc, xa);
const yba = subR(yb, ya); // const yba = subR(yb, ya);
//
const det = subR(xba * yca, xca * yba); // const det = subR(xba * yca, xca * yba);
console.log("dett", det, "edge", xa, ya, xb, yb, "position", xc, yc); console.log("dett", det, "edge", xa, ya, xb, yb, "position", xc, yc, "aaa");
// console.log("xa, ya, xb, yb, xc, yc", xa, ya, xb, yb, xc, yc); // console.log("xa, ya, xb, yb, xc, yc", xa, ya, xb, yb, xc, yc);
// const detEx = (xb*expo - xa*expo) * (yc*expo - ya*expo) - (xc*expo - xa*expo) * (yb*expo - ya*expo); // const detEx = (xb*expo - xa*expo) * (yc*expo - ya*expo) - (xc*expo - xa*expo) * (yb*expo - ya*expo);
@@ -289,7 +289,7 @@ const Move = (() => {
// console.log(xb, xa, yc, ya, xc, xa, yb, ya); // console.log(xb, xa, yc, ya, xc, xa, yb, ya);
// console.log("dettttttttttttttttttttt", det); // console.log("dettttttttttttttttttttt", det);
// if det == 0, that means we are in contact with that edge // if det == 0, that means we are in contact with that edge
return det <= 0; return det < 0;
} }
function isAcute([xa, ya], [xb, yb], [xc, yc]) { function isAcute([xa, ya], [xb, yb], [xc, yc]) {
@@ -508,9 +508,20 @@ const Move = (() => {
// console.log("s", s, "roundedS", roundedS, "t", t, "roundedT", roundedT); // console.log("s", s, "roundedS", roundedS, "t", t, "roundedT", roundedT);
console.log("s", s, "t", t); console.log("s", s, "t", t);
console.log("sr", sr, "tr", tr); console.log("sr", sr, "tr", tr);
const x1r = Math.round(x1 * 100);
const x2r = Math.round(x2 * 100);
const y1r = Math.round(y1 * 100);
const y2r = Math.round(y2 * 100);
const x3r = Math.round(x3 * 100);
const x4r = Math.round(x4 * 100);
const y3r = Math.round(y3 * 100);
const y4r = Math.round(y4 * 100);
// 2.03 * 10 // 2.03 * 10
// 20.299999999999997 // 20.299999999999997
const xsrOff = Math.round(x1r + (sr + 1) * (x2r - x1r)) / 100;
const ysrOff = Math.round(y1r + (sr + 1) * (y2r - y1r)) / 100;
// if (roundedS >= 0 && roundedS <= 1 && roundedT >= 0 && roundedT <= 1) { // if (roundedS >= 0 && roundedS <= 1 && roundedT >= 0 && roundedT <= 1) {
// if (s >= 0 && s < 1 && t >= 0 && t <= 1) { // this falls through // if (s >= 0 && s < 1 && t >= 0 && t <= 1) { // this falls through
@@ -528,17 +539,10 @@ const Move = (() => {
console.log("x1", x1, "x2", x2); console.log("x1", x1, "x2", x2);
console.log("y1", y1, "y2", y2); console.log("y1", y1, "y2", y2);
const x1r = Math.round(x1 * 100);
const x2r = Math.round(x2 * 100);
const y1r = Math.round(y1 * 100);
const y2r = Math.round(y2 * 100);
const x3r = Math.round(x3 * 100);
const x4r = Math.round(x4 * 100);
const y3r = Math.round(y3 * 100);
const y4r = Math.round(y4 * 100);
const xsr = Math.round(x1r + sr * (x2r - x1r)) / 100; const xsr = Math.round(x1r + sr * (x2r - x1r)) / 100;
const ysr = Math.round(y1r + sr * (y2r - y1r)) / 100; const ysr = Math.round(y1r + sr * (y2r - y1r)) / 100;
const xtr = Math.round(x3r + tr * (x4r - x3r)) / 100; const xtr = Math.round(x3r + tr * (x4r - x3r)) / 100;
const ytr = Math.round(y3r + tr * (y4r - y3r)) / 100; const ytr = Math.round(y3r + tr * (y4r - y3r)) / 100;
@@ -555,7 +559,8 @@ const Move = (() => {
const lnP = ln.getPointAtLength(lnD); const lnP = ln.getPointAtLength(lnD);
// collision.position = { x: xs, y: ys }; // collision.position = { x: xs, y: ys };
collision.position = { x: xsr, y: ysr }; // collision.position = { x: xsr, y: ysr };
collision.position = { x: xsrOff, y: ysrOff };
// collision.position = { x: xtr, y: ytr }; // collision.position = { x: xtr, y: ytr };
// collision.position = lnP; // collision.position = lnP;
@@ -912,8 +917,8 @@ const Move = (() => {
}; };
console.log("reflection before rounding", refP, "aaa"); console.log("reflection before rounding", refP, "aaa");
refP.x = Math.round(refP.x * 100) / 100; // refP.x = Math.round(refP.x * 100) / 100;
refP.y = Math.round(refP.y * 100) / 100; // refP.y = Math.round(refP.y * 100) / 100;
// shouldnt change isClockwise if isAcute isn't also changing // shouldnt change isClockwise if isAcute isn't also changing
// if we go from clockwise to not clockwise without changing acuteness, // if we go from clockwise to not clockwise without changing acuteness,
@@ -926,6 +931,7 @@ const Move = (() => {
isA = isAcute([contact.edge.xa, contact.edge.ya], [contact.edge.xb, contact.edge.yb], [refP.x, refP.y]); isA = isAcute([contact.edge.xa, contact.edge.ya], [contact.edge.xb, contact.edge.yb], [refP.x, refP.y]);
console.log("is reflected position acute with current contact", isA, "aaa"); console.log("is reflected position acute with current contact", isA, "aaa");
// how close can you come to an edge without being on it?
const inWall = contact.wall.node.isPointInFill(newP); const inWall = contact.wall.node.isPointInFill(newP);
console.log("is our calculated next position inside current edge's wall?", inWall, "dett"); console.log("is our calculated next position inside current edge's wall?", inWall, "dett");
@@ -1072,8 +1078,8 @@ function init() {
// drawCircle(0, 0); // drawCircle(0, 0);
// s.acceleration = { x: -1, y: 2 }; // s.acceleration = { x: -1, y: 2 };
s.acceleration = { x: -2, y: 2 }; // s.acceleration = { x: -2, y: 2 };
// s.acceleration = { x: 0, y: 0 }; s.acceleration = { x: 0, y: 0 };
Ships.forEach(({ entity_id }) => { Ships.forEach(({ entity_id }) => {
// Acceleration[entity_id] = s.acceleration; // Acceleration[entity_id] = s.acceleration;

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB