WIP: Add edge collision back
This commit is contained in:
@@ -118,8 +118,12 @@
|
|||||||
<!-- <polygon class="wall" points="20,-50 10,-50 10,-60 20,-60" /> -->
|
<!-- <polygon class="wall" points="20,-50 10,-50 10,-60 20,-60" /> -->
|
||||||
<!-- <polygon class="wall" points="-20,50 -10,50 -10,60 -20,60" /> -->
|
<!-- <polygon class="wall" points="-20,50 -10,50 -10,60 -20,60" /> -->
|
||||||
|
|
||||||
<polygon class="wall" points="-20,-50 -10,-50 -10,-60 -20,-60" />
|
<!-- <polygon class="wall" points="-20,-50 -10,-50 -10,-60 -20,-60" /> -->
|
||||||
<polygon class="wall" points="20,50 10,50 10,60 20,60" />
|
<!-- <polygon class="wall" points="20,50 10,50 10,60 20,60" /> -->
|
||||||
|
|
||||||
|
<!-- <polygon class="wall" points="-100,-50 -10,-50 -10,-60 -100,-60" /> -->
|
||||||
|
<polygon class="wall" points="-100,-60 -10,-60 -10,-50 -100,-50" />
|
||||||
|
<polygon class="wall" points="10,50 100,50 100,60 10,60" />
|
||||||
|
|
||||||
<!-- <polygon class="wall" points="-10,20 10,10 10,20" /> -->
|
<!-- <polygon class="wall" points="-10,20 10,10 10,20" /> -->
|
||||||
<!-- <polygon class="wall" points="20,20 40,20 40,40 20,40" /> -->
|
<!-- <polygon class="wall" points="20,20 40,20 40,40 20,40" /> -->
|
||||||
@@ -196,7 +200,7 @@
|
|||||||
|
|
||||||
const s = {
|
const s = {
|
||||||
position: { x: 0, y: 0 },
|
position: { x: 0, y: 0 },
|
||||||
velocity: { x: 0, y: 0 },
|
velocity: { x: -10, y: -10 },
|
||||||
|
|
||||||
// velocity: { x: 5, y: -10 },
|
// velocity: { x: 5, y: -10 },
|
||||||
// velocity: { x: -5*mult, y: -10*mult },
|
// velocity: { x: -5*mult, y: -10*mult },
|
||||||
@@ -390,7 +394,7 @@
|
|||||||
return walls.reduce((acc, wall) => {
|
return walls.reduce((acc, wall) => {
|
||||||
return [...acc, ...wall.edges.filter(({ xa, ya, xb, yb }) => {
|
return [...acc, ...wall.edges.filter(({ xa, ya, xb, yb }) => {
|
||||||
return [isClockwise, isAcute].every(c => c([xa, ya], [xb, yb], [xc, yc]));
|
return [isClockwise, isAcute].every(c => c([xa, ya], [xb, yb], [xc, yc]));
|
||||||
}).map(e => { return { edge: e, node: wall }; })];
|
}).map(edge => ({ edge, wall }))];
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +475,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { a, b } = perppts;
|
const { a, b } = perppts;
|
||||||
if (a && b) drawLine(a.x, a.y, b.x, b.y);
|
// if (a && b) drawLine(a.x, a.y, b.x, b.y);
|
||||||
|
|
||||||
return walls.reduce((acc, w) => {
|
return walls.reduce((acc, w) => {
|
||||||
const filtered = a && b ? w.corners.filter(c => {
|
const filtered = a && b ? w.corners.filter(c => {
|
||||||
@@ -681,7 +685,7 @@
|
|||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
|
|
||||||
const edge = z.find(({ edge: pts, node: ee }) => {
|
const edge = z.find(({ edge: pts, wall: ee }) => {
|
||||||
const str = `${pts.xa},${pts.ya} ${pts.xb},${pts.yb}`;
|
const str = `${pts.xa},${pts.ya} ${pts.xb},${pts.yb}`;
|
||||||
const r = Object.is(slope(pts), 0) && s.gearDown ? shipRadius + 1 : shipRadius;
|
const r = Object.is(slope(pts), 0) && s.gearDown ? shipRadius + 1 : shipRadius;
|
||||||
|
|
||||||
@@ -876,7 +880,7 @@
|
|||||||
|
|
||||||
// corners within collision distance
|
// corners within collision distance
|
||||||
cwcd = fCollC.filter(withinCollisionDistance({ x, y }, s.velocity));
|
cwcd = fCollC.filter(withinCollisionDistance({ x, y }, s.velocity));
|
||||||
console.log("corners on collision path", cwcd);
|
// console.log("corners on collision path", cwcd);
|
||||||
|
|
||||||
// cwcd.forEach(c => {
|
// cwcd.forEach(c => {
|
||||||
// const positionSeg = { xa: x, ya: y, xb: xc, yb: yc };
|
// const positionSeg = { xa: x, ya: y, xb: xc, yb: yc };
|
||||||
@@ -891,12 +895,32 @@
|
|||||||
ccps = fCollC.filter(cornerCollisionPosition({ x, y }, s.velocity));
|
ccps = fCollC.filter(cornerCollisionPosition({ x, y }, s.velocity));
|
||||||
// console.log("corner collision position", ccps);
|
// console.log("corner collision position", ccps);
|
||||||
|
|
||||||
console.log("collision edges", collE);
|
// console.log("collision edges", collE);
|
||||||
|
|
||||||
current = s.collision;
|
current = s.collision;
|
||||||
// s.collision = detectCollisions(position, allWallCorners, collE);
|
// s.collision = detectCollisions(position, allWallCorners, collE);
|
||||||
|
|
||||||
s.collision = cwcd.find(detectCornerCollision([xc, yc], [x, y], shipRadius));
|
const cornerColl = cwcd.find(detectCornerCollision([xc, yc], [x, y], shipRadius));
|
||||||
|
console.log("edge we are tracking", collE);
|
||||||
|
const edgeColl = collE.find(({ edge, wall }) => {
|
||||||
|
const { xa, ya, xb, yb } = edge;
|
||||||
|
const da = distance(xa, ya, xc, yc);
|
||||||
|
const db = distance(xb, yb, xc, yc);
|
||||||
|
// TODO: calculate this one ahead of time
|
||||||
|
const dc = distance(xa, ya, xb, yb);
|
||||||
|
|
||||||
|
// https://en.wikipedia.org/wiki/Altitude_(triangle)#Altitude_in_terms_of_the_sides
|
||||||
|
// Find altitude of side c (the base)
|
||||||
|
const s = (1 / 2) * (da + db + dc);
|
||||||
|
const hc = (2 / dc) * Math.sqrt(s * (s - da) * (s - db) * (s - dc));
|
||||||
|
console.log("hc", hc);
|
||||||
|
|
||||||
|
return +hc.toFixed(2) <= shipRadius;
|
||||||
|
});
|
||||||
|
|
||||||
|
s.collision = cornerColl || edgeColl;
|
||||||
|
|
||||||
|
console.log("COLLISION", s.collision);
|
||||||
|
|
||||||
legs.style.display = s.gearDown ? "initial" : "none";
|
legs.style.display = s.gearDown ? "initial" : "none";
|
||||||
|
|
||||||
@@ -908,6 +932,8 @@
|
|||||||
let posP;
|
let posP;
|
||||||
if (s.collision.corner) {
|
if (s.collision.corner) {
|
||||||
posP = cornerContactPosition(xc, yc, x, y, s.collision.corner, shipRadius);
|
posP = cornerContactPosition(xc, yc, x, y, s.collision.corner, shipRadius);
|
||||||
|
} else if (s.collision.edge) {
|
||||||
|
posP = collisionPosition(s.collision.edge, s.position, s.velocity, shipRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
s.velocity = { x: 0, y: 0 };
|
s.velocity = { x: 0, y: 0 };
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 42 KiB |
Reference in New Issue
Block a user