Skip to content

Commit

Permalink
MySkeleton: add descendsFrom() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 20, 2017
1 parent 14c3b3e commit 12313e0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions heart/src/main/java/jme3utilities/MySkeleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ public static Transform copyBindTransform(Bone bone,
return storeResult;
}

/**
* Test whether the indexed bone descends from the indexed ancestor in the
* specified skeleton.
*
* @param boneIndex index of bone to test (≥0)
* @param ancestorIndex index of ancestor bone (≥0)
* @param skeleton (not null, unaffected)
* @return true if descended from the parent, otherwise false
*/
public static boolean descendsFrom(int boneIndex, int ancestorIndex,
Skeleton skeleton) {
Validate.nonNegative(boneIndex, "bone index");
Validate.nonNegative(ancestorIndex, "ancestor index");

Bone bone = skeleton.getBone(boneIndex);
Bone ancestor = skeleton.getBone(ancestorIndex);
while (bone != null) {
bone = bone.getParent();
if (bone == ancestor) {
return true;
}
}

return false;
}

/**
* Find a named bone in a skeletonized spatial.
*
Expand Down

0 comments on commit 12313e0

Please sign in to comment.