[libgdx] Improved physic constraint rotate().

This commit is contained in:
Nathan Sweet 2024-01-22 12:31:21 -04:00
parent 09e1436504
commit e17766127d
2 changed files with 8 additions and 9 deletions

View File

@ -117,13 +117,12 @@ public class PhysicsConstraint implements Updatable {
cy -= y; cy -= y;
} }
/** Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated an additional /** Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated around the
* amount in world space. */ * specified point in world space. */
public void rotate (float degrees) { public void rotate (float x, float y, float degrees) {
float r = degrees * degRad, cos = cos(r), sin = sin(r); float r = degrees * degRad, cos = cos(r), sin = sin(r);
r = tx * cos - ty * sin; float dx = cx - x, dy = cy - y;
ty = tx * sin + ty * cos; translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy);
tx = r;
} }
/** Applies the constraint to the constrained bones. */ /** Applies the constraint to the constrained bones. */

View File

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