diff --git a/jme3-core/src/main/java/com/jme3/animation/Bone.java b/jme3-core/src/main/java/com/jme3/animation/Bone.java index 819a77383..a78b4b931 100644 --- a/jme3-core/src/main/java/com/jme3/animation/Bone.java +++ b/jme3-core/src/main/java/com/jme3/animation/Bone.java @@ -313,6 +313,26 @@ public final class Bone implements Savable { return modelBindInverseScale; } + public Transform getModelBindInverseTransform() { + Transform t = new Transform(); + t.setTranslation(modelBindInversePos); + t.setRotation(modelBindInverseRot); + if (modelBindInverseScale != null) { + t.setScale(modelBindInverseScale); + } + return t; + } + + public Transform getBindInverseTransform() { + Transform t = new Transform(); + t.setTranslation(bindPos); + t.setRotation(bindRot); + if (bindScale != null) { + t.setScale(bindScale); + } + return t.invert(); + } + /** * @deprecated use {@link #getBindPosition()} */ diff --git a/jme3-core/src/main/java/com/jme3/math/FastMath.java b/jme3-core/src/main/java/com/jme3/math/FastMath.java index 5e230dabb..d9d944057 100644 --- a/jme3-core/src/main/java/com/jme3/math/FastMath.java +++ b/jme3-core/src/main/java/com/jme3/math/FastMath.java @@ -902,6 +902,25 @@ final public class FastMath { return clamp(input, 0f, 1f); } + /** + * Determine if two floats are approximately equal. + * This takes into account the magnitude of the floats, since + * large numbers will have larger differences be close to each other. + * + * Should return true for a=100000, b=100001, but false for a=10000, b=10001. + * + * @param a The first float to compare + * @param b The second float to compare + * @return True if a and b are approximately equal, false otherwise. + */ + public static boolean approximateEquals(float a, float b) { + if (a == b) { + return true; + } else { + return (abs(a - b) / Math.max(abs(a), abs(b))) <= 0.00001f; + } + } + /** * Converts a single precision (32 bit) floating point value * into half precision (16 bit). diff --git a/jme3-core/src/main/java/com/jme3/math/Transform.java b/jme3-core/src/main/java/com/jme3/math/Transform.java index 79992ed2b..ac7a324d0 100644 --- a/jme3-core/src/main/java/com/jme3/math/Transform.java +++ b/jme3-core/src/main/java/com/jme3/math/Transform.java @@ -259,6 +259,26 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable return store; } + public Matrix4f toTransformMatrix() { + Matrix4f trans = new Matrix4f(); + trans.setTranslation(translation); + trans.setRotationQuaternion(rot); + trans.setScale(scale); + return trans; + } + + public void fromTransformMatrix(Matrix4f mat) { + translation.set(mat.toTranslationVector()); + rot.set(mat.toRotationQuat()); + scale.set(mat.toScaleVector()); + } + + public Transform invert() { + Transform t = new Transform(); + t.fromTransformMatrix(toTransformMatrix().invertLocal()); + return t; + } + /** * Loads the identity. Equal to translation=0,0,0 scale=1,1,1 rot=0,0,0,1. */