[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;
}
/** 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) {
/** Rotates the physics constraint so next {@link #update(Physics)} forces are applied as if the bone rotated around the
* specified point in world space. */
public void rotate (float x, float y, float degrees) {
float r = degrees * degRad, cos = cos(r), sin = sin(r);
r = tx * cos - ty * sin;
ty = tx * sin + ty * cos;
tx = r;
float dx = cx - x, dy = cy - y;
translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy);
}
/** Applies the constraint to the constrained bones. */

View File

@ -810,11 +810,11 @@ public class Skeleton {
((PhysicsConstraint)physicsConstraints[i]).translate(x, y);
}
/** Calls {@link PhysicsConstraint#rotate(float)} for each physics constraint. */
public void physicsRotate (float degrees) {
/** Calls {@link PhysicsConstraint#rotate(float, float, float)} for each physics constraint. */
public void physicsRotate (float x, float y, float degrees) {
Object[] physicsConstraints = this.physicsConstraints.items;
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}.