[ts] Port physics translation and rotation methods.

This commit is contained in:
Mario Zechner 2024-01-24 12:09:54 +01:00
parent 468656ba0e
commit 73cb252bef
2 changed files with 31 additions and 0 deletions

View File

@ -267,4 +267,22 @@ export class PhysicsConstraint implements Updatable {
}
bone.updateAppliedTransform();
}
translate (x: number, y: number) {
this.ux -= x;
this.uy -= y;
this.cx -= x;
this.cy -= y;
}
/** Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated around the
* specified point in world space. */
rotate (x: number, y: number, degrees: number) {
let r = degrees * MathUtils.degRad, cos = Math.cos(r), sin = Math.sin(r);
r = this.tx * cos - this.ty * sin;
this.ty = this.tx * sin + this.ty * cos;
this.tx = r;
const dx = this.cx - x, dy = this.cy - y;
this.translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy);
}
}

View File

@ -646,6 +646,19 @@ export class Skeleton {
update (delta: number) {
this.time += delta;
}
physicsTranslate (x: number, y: number) {
const physicsConstraints = this.physicsConstraints;
for (let i = 0, n = physicsConstraints.length; i < n; i++)
physicsConstraints[i].translate(x, y);
}
/** Calls {@link PhysicsConstraint#rotate(float, float, float)} for each physics constraint. */
physicsRotate (x: number, y: number, degrees: number) {
const physicsConstraints = this.physicsConstraints;
for (let i = 0, n = physicsConstraints.length; i < n; i++)
physicsConstraints[i].rotate(x, y, degrees);
}
}
/** Determines how physics and other non-deterministic updates are applied. */