Skip to content

Commit

Permalink
[libgdx] Added physics methods to apply translation and rotation forces.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSweet committed Jan 18, 2024
1 parent ec1d602 commit 2563c7c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,22 @@ public void setToSetupPose () {
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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,20 @@ public void setPosition (float x, float y) {
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)}. */
Expand Down

0 comments on commit 2563c7c

Please sign in to comment.