mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[libgdx] Replaced MathUtils usage with new TrigUtils. Does not use LUTs, yielding higher precision necessary for IK & path constraints
This commit is contained in:
parent
a8f1159934
commit
3da247d92d
@ -30,7 +30,7 @@
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
import static com.badlogic.gdx.math.MathUtils.*;
|
||||
import static com.esotericsoftware.spine.utils.TrigUtils.*;
|
||||
import static com.badlogic.gdx.math.Matrix3.*;
|
||||
|
||||
import com.badlogic.gdx.math.Matrix3;
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
import static com.badlogic.gdx.math.MathUtils.*;
|
||||
import static com.esotericsoftware.spine.utils.TrigUtils.*;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
import static com.badlogic.gdx.math.MathUtils.*;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
@ -39,6 +38,7 @@ import com.esotericsoftware.spine.PathConstraintData.RotateMode;
|
||||
import com.esotericsoftware.spine.PathConstraintData.SpacingMode;
|
||||
import com.esotericsoftware.spine.attachments.Attachment;
|
||||
import com.esotericsoftware.spine.attachments.PathAttachment;
|
||||
import com.esotericsoftware.spine.utils.TrigUtils;
|
||||
|
||||
/** Stores the current pose for a path constraint. A path constraint adjusts the rotation, translation, and scale of the
|
||||
* constrained bones so they follow a {@link PathAttachment}.
|
||||
@ -131,7 +131,7 @@ public class PathConstraint implements Constraint {
|
||||
else {
|
||||
tip = false;
|
||||
Bone p = target.bone;
|
||||
offsetRotation *= p.a * p.d - p.b * p.c > 0 ? degRad : -degRad;
|
||||
offsetRotation *= p.a * p.d - p.b * p.c > 0 ? TrigUtils.degRad : -TrigUtils.degRad;
|
||||
}
|
||||
for (int i = 0, p = 3; i < boneCount; i++, p += 3) {
|
||||
Bone bone = (Bone)bones[i];
|
||||
@ -155,23 +155,23 @@ public class PathConstraint implements Constraint {
|
||||
else if (spaces[i + 1] == 0)
|
||||
r = positions[p + 2];
|
||||
else
|
||||
r = atan2(dy, dx);
|
||||
r -= atan2(c, a);
|
||||
r = (float)Math.atan2(dy, dx);
|
||||
r -= (float)Math.atan2(c, a);
|
||||
if (tip) {
|
||||
cos = cos(r);
|
||||
sin = sin(r);
|
||||
cos = (float)Math.cos(r);
|
||||
sin = (float)Math.sin(r);
|
||||
float length = bone.data.length;
|
||||
boneX += (length * (cos * a - sin * c) - dx) * rotateMix;
|
||||
boneY += (length * (sin * a + cos * c) - dy) * rotateMix;
|
||||
} else
|
||||
r += offsetRotation;
|
||||
if (r > PI)
|
||||
r -= PI2;
|
||||
else if (r < -PI) //
|
||||
r += PI2;
|
||||
if (r > TrigUtils.PI)
|
||||
r -= TrigUtils.PI2;
|
||||
else if (r < -TrigUtils.PI) //
|
||||
r += TrigUtils.PI2;
|
||||
r *= rotateMix;
|
||||
cos = cos(r);
|
||||
sin = sin(r);
|
||||
cos = (float)Math.cos(r);
|
||||
sin = (float)Math.sin(r);
|
||||
bone.a = cos * a - sin * c;
|
||||
bone.b = cos * b - sin * d;
|
||||
bone.c = sin * a + cos * c;
|
||||
@ -399,16 +399,16 @@ public class PathConstraint implements Constraint {
|
||||
}
|
||||
|
||||
private void addBeforePosition (float p, float[] temp, int i, float[] out, int o) {
|
||||
float x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = atan2(dy, dx);
|
||||
out[o] = x1 + p * cos(r);
|
||||
out[o + 1] = y1 + p * sin(r);
|
||||
float x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = (float)Math.atan2(dy, dx);
|
||||
out[o] = x1 + p * (float)Math.cos(r);
|
||||
out[o + 1] = y1 + p * (float)Math.sin(r);
|
||||
out[o + 2] = r;
|
||||
}
|
||||
|
||||
private void addAfterPosition (float p, float[] temp, int i, float[] out, int o) {
|
||||
float x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = atan2(dy, dx);
|
||||
out[o] = x1 + p * cos(r);
|
||||
out[o + 1] = y1 + p * sin(r);
|
||||
float x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = (float)Math.atan2(dy, dx);
|
||||
out[o] = x1 + p * (float)Math.cos(r);
|
||||
out[o + 1] = y1 + p * (float)Math.sin(r);
|
||||
out[o + 2] = r;
|
||||
}
|
||||
|
||||
@ -420,7 +420,7 @@ public class PathConstraint implements Constraint {
|
||||
float x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
|
||||
out[o] = x;
|
||||
out[o + 1] = y;
|
||||
if (tangents) out[o + 2] = atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
|
||||
if (tangents) out[o + 2] = (float)Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
|
||||
}
|
||||
|
||||
public int getOrder () {
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
import static com.badlogic.gdx.math.MathUtils.*;
|
||||
import static com.esotericsoftware.spine.utils.TrigUtils.*;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@ -94,8 +94,8 @@ public class RegionAttachment extends Attachment {
|
||||
localX2 *= scaleX;
|
||||
localY2 *= scaleY;
|
||||
float rotation = getRotation();
|
||||
float cos = MathUtils.cosDeg(rotation);
|
||||
float sin = MathUtils.sinDeg(rotation);
|
||||
float cos = (float)Math.cos(MathUtils.degRad * rotation);
|
||||
float sin = (float)Math.sin(MathUtils.degRad * rotation);
|
||||
float x = getX();
|
||||
float y = getY();
|
||||
float localXCos = localX * cos + x;
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes Software License v2.5
|
||||
*
|
||||
* Copyright (c) 2013-2016, Esoteric Software
|
||||
* All rights reserved.
|
||||
*
|
||||
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||
* non-transferable license to use, install, execute, and perform the Spine
|
||||
* Runtimes software and derivative works solely for personal or internal
|
||||
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||
* or other intellectual property or proprietary rights notices on or in the
|
||||
* Software, including any copy thereof. Redistributions in binary or source
|
||||
* form must include this license and terms.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package com.esotericsoftware.spine.utils;
|
||||
|
||||
public class TrigUtils {
|
||||
static public final float PI = 3.1415927f;
|
||||
static public final float PI2 = PI * 2;
|
||||
static public final float radiansToDegrees = 180f / PI;
|
||||
static public final float radDeg = radiansToDegrees;
|
||||
static public final float degreesToRadians = PI / 180;
|
||||
static public final float degRad = degreesToRadians;
|
||||
|
||||
public static float cosDeg(float angle) {
|
||||
return (float)Math.cos(angle * degRad);
|
||||
}
|
||||
|
||||
public static float sinDeg(float angle) {
|
||||
return (float)Math.sin(angle * degRad);
|
||||
}
|
||||
|
||||
public static float cos(float angle) {
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
|
||||
public static float sin(float angle) {
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
public static float atan2(float y, float x) {
|
||||
return (float)Math.atan2(y, x);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user