mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
Merged with master, pulling in change from MathUtils -> TrigUtils in spine-libgdx as well as Maven pom.xml
This commit is contained in:
parent
011aca7b25
commit
b2d4fa4012
@ -88,7 +88,7 @@ namespace Spine {
|
||||
float id = 1 / (p.a * p.d - p.b * p.c);
|
||||
float x = targetX - p.worldX, y = targetY - p.worldY;
|
||||
float tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
|
||||
float rotationIK = MathUtils.Atan2(ty, tx) * MathUtils.RadDeg - bone.ashearX - bone.arotation;
|
||||
float rotationIK = (float)Math.Atan2(ty, tx) * MathUtils.RadDeg - bone.ashearX - bone.arotation;
|
||||
if (bone.ascaleX < 0) rotationIK += 180;
|
||||
if (rotationIK > 180)
|
||||
rotationIK -= 360;
|
||||
@ -157,12 +157,12 @@ namespace Spine {
|
||||
else if (cos > 1) cos = 1;
|
||||
a2 = (float)Math.Acos(cos) * bendDir;
|
||||
a = l1 + l2 * cos;
|
||||
b = l2 * MathUtils.Sin(a2);
|
||||
a1 = MathUtils.Atan2(ty * a - tx * b, tx * a + ty * b);
|
||||
b = l2 * (float)Math.Sin(a2);
|
||||
a1 = (float)Math.Atan2(ty * a - tx * b, tx * a + ty * b);
|
||||
} else {
|
||||
a = psx * l2;
|
||||
b = psy * l2;
|
||||
float aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = MathUtils.Atan2(ty, tx);
|
||||
float aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = (float)Math.Atan2(ty, tx);
|
||||
c = bb * l1 * l1 + aa * dd - aa * bb;
|
||||
float c1 = -2 * bb * l1, c2 = bb - aa;
|
||||
d = c1 * c1 - 4 * c2 * c;
|
||||
@ -174,8 +174,8 @@ namespace Spine {
|
||||
float r = Math.Abs(r0) < Math.Abs(r1) ? r0 : r1;
|
||||
if (r * r <= dd) {
|
||||
y = (float)Math.Sqrt(dd - r * r) * bendDir;
|
||||
a1 = ta - MathUtils.Atan2(y, r);
|
||||
a2 = MathUtils.Atan2(y / psy, (r - l1) / psx);
|
||||
a1 = ta - (float)Math.Atan2(y, r);
|
||||
a2 = (float)Math.Atan2(y / psy, (r - l1) / psx);
|
||||
goto outer;
|
||||
}
|
||||
}
|
||||
@ -191,13 +191,13 @@ namespace Spine {
|
||||
x = l1 - a;
|
||||
d = x * x;
|
||||
if (d < minDist) {
|
||||
minAngle = MathUtils.PI;
|
||||
minAngle = (float)Math.PI;
|
||||
minDist = d;
|
||||
minX = x;
|
||||
}
|
||||
float angle = (float)Math.Acos(-a * l1 / (aa - bb));
|
||||
x = a * MathUtils.Cos(angle) + l1;
|
||||
y = b * MathUtils.Sin(angle);
|
||||
x = a * (float)Math.Cos(angle) + l1;
|
||||
y = b * (float)Math.Sin(angle);
|
||||
d = x * x + y * y;
|
||||
if (d < minDist) {
|
||||
minAngle = angle;
|
||||
@ -212,15 +212,15 @@ namespace Spine {
|
||||
maxY = y;
|
||||
}
|
||||
if (dd <= (minDist + maxDist) / 2) {
|
||||
a1 = ta - MathUtils.Atan2(minY * bendDir, minX);
|
||||
a1 = ta - (float)Math.Atan2(minY * bendDir, minX);
|
||||
a2 = minAngle * bendDir;
|
||||
} else {
|
||||
a1 = ta - MathUtils.Atan2(maxY * bendDir, maxX);
|
||||
a1 = ta - (float)Math.Atan2(maxY * bendDir, maxX);
|
||||
a2 = maxAngle * bendDir;
|
||||
}
|
||||
}
|
||||
outer:
|
||||
float os = MathUtils.Atan2(cy, cx) * s2;
|
||||
float os = (float)Math.Atan2(cy, cx) * s2;
|
||||
float rotation = parent.arotation;
|
||||
a1 = (a1 - os) * MathUtils.RadDeg + os1 - rotation;
|
||||
if (a1 > 180)
|
||||
|
||||
@ -27,6 +27,63 @@ Alternatively, the contents of the `spine-libgdx/src` directory can be copied in
|
||||
* spine-libgdx depends on the gdx-backend-lwjgl project so the tests can easily be run on the desktop. If the tests are excluded, spine-libgdx only needs to depend on the gdx project.
|
||||
* spine-libgdx depends on the gdx-box2d extension project solely for the `Box2DExample` test.
|
||||
|
||||
## Maven & Gradle
|
||||
The spine-libgdx runtime is released to Maven Central through SonaType. We also deploy snapshot builds on every commit to the master repository. You can find the Jenkins build [here](http://libgdx.badlogicgames.com:8080/job/spine-libgdx/).
|
||||
|
||||
### Versions
|
||||
|
||||
You can find the latest version for release builds [here](http://search.maven.org/#search%7Cga%7C1%7Cspine-libgdx).
|
||||
|
||||
You can find the latest SNAPSHOT version in the project's [pom.xml](https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-libgdx/spine-libgdx/pom.xml#L13).
|
||||
|
||||
If you want to use a different branch, e.g. `3.6-beta`, build the artifact locally:
|
||||
|
||||
```
|
||||
cd spine-libgdx/spine-libgdx
|
||||
mvn install
|
||||
```
|
||||
|
||||
The version number is composed of the editor number at the time of release of the Maven artifact plus a patch number at the end. E.g. `3.5.51.3` means editor version `3.5.51`, and patch version `3` for the runtime. The editor version is updated everytime a new editor release is performed, the patch version is updated everytime a new fix or enhancement is released in the runtime.
|
||||
|
||||
|
||||
### Maven
|
||||
To add the spine-libgdx runtime to your Maven project, add this dependency:
|
||||
|
||||
```
|
||||
<depenency>
|
||||
<groupId>com.esotericsoftware.spine</groupId>
|
||||
<artifactId>spine-libgdx</artifactId>
|
||||
<version>3.5.51.1</version>
|
||||
</depenency>
|
||||
```
|
||||
|
||||
For SNAPSHOT versions, add the SonaType Snapshot repository to your `pom.xml`:
|
||||
|
||||
```
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nightlies</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
|
||||
### Gradle
|
||||
To add the spine-libgdx runtime to your libGDX Gradle project, add the following dependencies to the `core` project in the `build.gradle` file at the root of your libGDX project:
|
||||
|
||||
```
|
||||
project(":core") {
|
||||
apply plugin: "java"
|
||||
|
||||
dependencies {
|
||||
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
|
||||
|
||||
compile "com.esotericsoftware.spine:spine-libgdx:3.5.51.1"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
* [HTML5 example](http://esotericsoftware.com/files/runtimes/spine-libgdx/raptor/)
|
||||
|
||||
120
spine-libgdx/spine-libgdx/pom.xml
Normal file
120
spine-libgdx/spine-libgdx/pom.xml
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>5</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.esotericsoftware.spine</groupId>
|
||||
<artifactId>spine-libgdx</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>3.5.51.2-SNAPSHOT</version>
|
||||
|
||||
<name>spine-libgdx</name>
|
||||
<description>Spine Runtime for libGDX</description>
|
||||
<url>http://github.com/esotericsoftware/spine-runtimes</url>
|
||||
<issueManagement>
|
||||
<url>http://github.com/esotericsoftware/spine-runtimes/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Spine Runtime License v2.5</name>
|
||||
<url>https://github.com/EsotericSoftware/spine-runtimes/blob/master/LICENSE</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>Developers</id>
|
||||
<url>https://github.com/EsotericSoftware/spine-runtimes/graphs/contributors</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/EsotericSoftware/spine-runtimes.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/EsotericSoftware/spine-runtimes.git</developerConnection>
|
||||
<url>https://github.com/EsotericSoftware/spine-runtimes/</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nightlies</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<gdx.version>1.9.6</gdx.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<fork>true</fork>
|
||||
<showWarnings>true</showWarnings>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration>
|
||||
<additionalparam>-Xdoclint:none</additionalparam>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default</id>
|
||||
<goals>
|
||||
<goal>perform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<pomFile>spine-libgdx/spine-libgdx/pom.xml</pomFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.badlogicgames.gdx</groupId>
|
||||
<artifactId>gdx</artifactId>
|
||||
<version>${gdx.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -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;
|
||||
|
||||
@ -89,8 +89,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);
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,7 @@ new spine.SpineWidget("spine-widget", {
|
||||
var animIndex = 0;
|
||||
widget.canvas.onclick = function () {
|
||||
animIndex++;
|
||||
let animations = widget.skeleton.data.animations;
|
||||
var animations = widget.skeleton.data.animations;
|
||||
if (animIndex >= animations.length) animIndex = 0;
|
||||
widget.setAnimation(animations[animIndex].name);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user