From b5d1aea3c5bf17192e5470c7249060454eab8f54 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 18 Jan 2024 18:39:54 +0100 Subject: [PATCH] [csharp] Port of commit 2563c7c. Added physics methods to apply translation and rotation forces. --- spine-csharp/src/PhysicsConstraint.cs | 22 ++++++++++++++++++++++ spine-csharp/src/Skeleton.cs | 18 ++++++++++++++++++ spine-csharp/src/package.json | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/spine-csharp/src/PhysicsConstraint.cs b/spine-csharp/src/PhysicsConstraint.cs index ec9f44dbb..7419b5a1a 100644 --- a/spine-csharp/src/PhysicsConstraint.cs +++ b/spine-csharp/src/PhysicsConstraint.cs @@ -110,6 +110,28 @@ namespace Spine { mix = data.mix; } + /// + /// Translates the physics constraint so next 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 forces are applied as if the bone rotated an additional + /// amount in world space. + /// + public void Rotate (float degrees) { + float r = degrees * MathUtils.DegRad, cos = (float)Math.Cos(r), sin = (float)Math.Sin(r); + r = tx * cos - ty * sin; + ty = tx * sin + ty * cos; + tx = r; + } + /// Applies the constraint to the constrained bones. public void Update (Physics physics) { float mix = this.mix; diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index a9e3e18a6..3a84e6ca2 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -474,6 +474,24 @@ namespace Spine { } } + /// + /// Calls for each physics constraint. + /// + public void PhysicsTranslate (float x, float y) { + PhysicsConstraint[] physicsConstraints = this.physicsConstraints.Items; + for (int i = 0, n = this.physicsConstraints.Count; i < n; i++) + physicsConstraints[i].Translate(x, y); + } + + /// + /// Calls for each physics constraint. + /// + public void PhysicsRotate (float degrees) { + PhysicsConstraint[] physicsConstraints = this.physicsConstraints.Items; + for (int i = 0, n = this.physicsConstraints.Count; i < n; i++) + physicsConstraints[i].Rotate(degrees); + } + /// Increments the skeleton's . public void Update (float delta) { time += delta; diff --git a/spine-csharp/src/package.json b/spine-csharp/src/package.json index 593dbbf90..37e4cba16 100644 --- a/spine-csharp/src/package.json +++ b/spine-csharp/src/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-csharp", "displayName": "spine-csharp Runtime", "description": "This plugin provides the spine-csharp core runtime.", - "version": "4.2.9", + "version": "4.2.10", "unity": "2018.3", "author": { "name": "Esoteric Software",