mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-05 18:26:52 +08:00
[ts] Port physics translation and rotation methods.
This commit is contained in:
parent
468656ba0e
commit
73cb252bef
@ -267,4 +267,22 @@ export class PhysicsConstraint implements Updatable {
|
|||||||
}
|
}
|
||||||
bone.updateAppliedTransform();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -646,6 +646,19 @@ export class Skeleton {
|
|||||||
update (delta: number) {
|
update (delta: number) {
|
||||||
this.time += delta;
|
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. */
|
/** Determines how physics and other non-deterministic updates are applied. */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user