mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-09 16:48:43 +08:00
worldToLocalRotation and localToWorldRotation utility methods.
http://esotericsoftware.com/forum/RegionAttachment-offset-7662?p=35770#p35770
This commit is contained in:
parent
cdaaf295b2
commit
12c986806d
@ -380,29 +380,6 @@ public class Bone implements Updatable {
|
||||
return (float)Math.sqrt(b * b + d * d);
|
||||
}
|
||||
|
||||
public float worldToLocalRotationX () {
|
||||
Bone parent = this.parent;
|
||||
if (parent == null) return arotation;
|
||||
return atan2(parent.a * c - parent.c * a, parent.d * a - parent.b * c) * radDeg;
|
||||
}
|
||||
|
||||
public float worldToLocalRotationY () {
|
||||
Bone parent = this.parent;
|
||||
if (parent == null) return arotation;
|
||||
return atan2(parent.a * d - parent.c * b, parent.d * b - parent.b * d) * radDeg;
|
||||
}
|
||||
|
||||
/** Rotates the world transform the specified amount. {@link #updateWorldTransform()} will need to be called on any child
|
||||
* bones, recursively. */
|
||||
public void rotateWorld (float degrees) {
|
||||
float cos = cosDeg(degrees), sin = sinDeg(degrees);
|
||||
a = cos * a - sin * c;
|
||||
b = cos * b - sin * d;
|
||||
c = sin * a + cos * c;
|
||||
d = sin * b + cos * d;
|
||||
appliedValid = false;
|
||||
}
|
||||
|
||||
/** Computes the individual applied transform values from the world transform. This can be useful to perform processing using
|
||||
* the applied transform after the world transform has been modified directly (eg, by a constraint).
|
||||
* <p>
|
||||
@ -480,6 +457,29 @@ public class Bone implements Updatable {
|
||||
return local;
|
||||
}
|
||||
|
||||
/** Transforms a world rotation to a local rotation. */
|
||||
public float worldToLocalRotation (float worldRotation) {
|
||||
float sin = sinDeg(worldRotation), cos = cosDeg(worldRotation);
|
||||
return atan2(a * sin - c * cos, d * cos - b * sin) * radDeg;
|
||||
}
|
||||
|
||||
/** Transforms a local rotation to a world rotation. */
|
||||
public float localToWorldRotation (float localRotation) {
|
||||
float sin = sinDeg(localRotation), cos = cosDeg(localRotation);
|
||||
return atan2(cos * c + sin * d, cos * a + sin * b) * radDeg;
|
||||
}
|
||||
|
||||
/** Rotates the world transform the specified amount. {@link #updateWorldTransform()} will need to be called on any child
|
||||
* bones, recursively. */
|
||||
public void rotateWorld (float degrees) {
|
||||
float cos = cosDeg(degrees), sin = sinDeg(degrees);
|
||||
a = cos * a - sin * c;
|
||||
b = cos * b - sin * d;
|
||||
c = sin * a + cos * c;
|
||||
d = sin * b + cos * d;
|
||||
appliedValid = false;
|
||||
}
|
||||
|
||||
public String toString () {
|
||||
return data.name;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user