From d65311dba0423f9b3124316df081ee284822db7e Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sun, 2 Jul 2023 18:30:01 -0400 Subject: [PATCH] [libgdx] Added worldToParent and parentToWorld so application code doesn't need to check the parent for null (when it is the root). --- .../src/com/esotericsoftware/spine/Bone.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java index ad7da5ecd..ec2fc0a01 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -590,6 +590,18 @@ public class Bone implements Updatable { return local; } + /** Transforms a point from world coordinates to the parent bone's local coordinates. */ + public Vector2 worldToParent (Vector2 world) { + if (world == null) throw new IllegalArgumentException("world cannot be null."); + return parent == null ? world : parent.worldToLocal(world); + } + + /** Transforms a point from the parent bone's coordinates to world coordinates. */ + public Vector2 parentToWorld (Vector2 world) { + if (world == null) throw new IllegalArgumentException("world cannot be null."); + return parent == null ? world : parent.localToWorld(world); + } + /** Transforms a world rotation to a local rotation. */ public float worldToLocalRotation (float worldRotation) { worldRotation *= degRad;