duu
This commit is contained in:
parent
88f618cadf
commit
8f9f5b5100
108 changed files with 2139 additions and 1500 deletions
|
|
@ -1,19 +1,12 @@
|
|||
"use strict";
|
||||
|
||||
(function (global) {
|
||||
|
||||
function rectLocalPoint(rect, x, y) {
|
||||
return global.TarinaiCollisionFootprints.rectLocalPoint(rect, x, y);
|
||||
}
|
||||
|
||||
function rectWorldVector(rect, x, y) {
|
||||
return global.TarinaiCollisionFootprints.rectWorldVector(rect, x, y);
|
||||
}
|
||||
const Geometry = global.TarinaiGeometry;
|
||||
|
||||
function circleBounceOffOrientedRect(obj, rect, radius, restitution, worldRef, opts = {}) {
|
||||
const hitRadius = Math.max(2, Number(radius || obj.r || obj.radius || 12) || 12);
|
||||
const minBounceSpeed = Math.max(0, Number(opts.minBounceSpeed ?? rect.minBounceSpeed ?? 0) || 0);
|
||||
const local = rectLocalPoint(rect, obj.x, obj.y);
|
||||
const local = Geometry.rectLocalPoint(rect, obj.x, obj.y);
|
||||
let clx = clamp(local.x, -(rect.halfW || 0), rect.halfW || 0);
|
||||
let cly = clamp(local.y, -(rect.halfH || 0), rect.halfH || 0);
|
||||
let dx = local.x - clx;
|
||||
|
|
@ -23,7 +16,7 @@
|
|||
const px = obj.prevX;
|
||||
const py = obj.prevY;
|
||||
if (!Number.isFinite(px) || !Number.isFinite(py)) return false;
|
||||
const prev = rectLocalPoint(rect, px, py);
|
||||
const prev = Geometry.rectLocalPoint(rect, px, py);
|
||||
const expanded = { left: -(rect.halfW || 0) - hitRadius, right: (rect.halfW || 0) + hitRadius, top: -(rect.halfH || 0) - hitRadius, bottom: (rect.halfH || 0) + hitRadius };
|
||||
const insideNow = local.x >= expanded.left && local.x <= expanded.right && local.y >= expanded.top && local.y <= expanded.bottom;
|
||||
const insidePrev = prev.x >= expanded.left && prev.x <= expanded.right && prev.y >= expanded.top && prev.y <= expanded.bottom;
|
||||
|
|
@ -54,10 +47,10 @@
|
|||
}
|
||||
const nxLocal = dx / d;
|
||||
const nyLocal = dy / d;
|
||||
const n = rectWorldVector(rect, nxLocal, nyLocal);
|
||||
const n = Geometry.rectWorldVector(rect, nxLocal, nyLocal);
|
||||
const nx = n.x;
|
||||
const ny = n.y;
|
||||
const worldClosest = rectWorldVector(rect, clx, cly);
|
||||
const worldClosest = Geometry.rectWorldVector(rect, clx, cly);
|
||||
obj.x = (rect.cx || 0) + worldClosest.x + nx * (hitRadius + 0.5);
|
||||
obj.y = (rect.cy || 0) + worldClosest.y + ny * (hitRadius + 0.5);
|
||||
const vx = obj.vx || 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue