[libgdx] Added physics methods to apply translation and rotation forces.

This commit is contained in:
Nathan Sweet 2024-01-18 13:17:59 -04:00
parent ec1d6028c0
commit 2563c7cbce
2 changed files with 30 additions and 1 deletions

View File

@ -108,7 +108,22 @@ public class PhysicsConstraint implements Updatable {
mix = data.mix;
}
public void translate () {
/** Translates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone moved an additional
* amount in world space. */
public void translate (float x, float y) {
ux -= x;
uy -= y;
cx -= x;
cy -= y;
}
/** Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated an additional
* amount in world space. */
public void rotate (float degrees) {
float r = degrees * degRad, cos = cos(r), sin = sin(r);
r = tx * cos - ty * sin;
ty = tx * sin + ty * cos;
tx = r;
}
/** Applies the constraint to the constrained bones. */

View File

@ -803,6 +803,20 @@ public class Skeleton {
this.y = y;
}
/** Calls {@link PhysicsConstraint#translate(float, float)} for each physics constraint. */
public void physicsTranslate (float x, float y) {
Object[] physicsConstraints = this.physicsConstraints.items;
for (int i = 0, n = this.physicsConstraints.size; i < n; i++)
((PhysicsConstraint)physicsConstraints[i]).translate(x, y);
}
/** Calls {@link PhysicsConstraint#rotate(float)} for each physics constraint. */
public void physicsRotate (float degrees) {
Object[] physicsConstraints = this.physicsConstraints.items;
for (int i = 0, n = this.physicsConstraints.size; i < n; i++)
((PhysicsConstraint)physicsConstraints[i]).rotate(degrees);
}
/** Returns the skeleton's time. This is used for time-based manipulations, such as {@link PhysicsConstraint}.
* <p>
* See {@link #update(float)}. */