Skip to content

Commit

Permalink
refactor GetRelativeTransform(...) (#2140)
Browse files Browse the repository at this point in the history
* rename ancestorNode

* convert to for loop
  • Loading branch information
nkast authored Dec 24, 2024
1 parent 0bf91a8 commit 1d55ae5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Xna.Framework.Content.Pipeline.Graphics/OpenAssetImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,27 +954,29 @@ private static void GetSubtree(Node aiNode, List<Node> list)
/// Gets the transform of node relative to a specific ancestor node.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="ancestor">The ancestor node. Can be <see langword="null"/>.</param>
/// <param name="ancestorNode">The ancestor node. Can be <see langword="null"/>.</param>
/// <returns>
/// The relative transform. If <paramref name="ancestor"/> is <see langword="null"/> the
/// The relative transform. If <paramref name="ancestorNode"/> is <see langword="null"/> the
/// absolute transform of <paramref name="node"/> is returned.
/// </returns>
private static Matrix4x4 GetRelativeTransform(Node node, Node ancestor)
private static Matrix4x4 GetRelativeTransform(Node node, Node ancestorNode)
{
Debug.Assert(node != null);

// Get transform of node relative to ancestor.
Matrix4x4 transform = node.Transform;
Node parent = node.Parent;
while (parent != null && parent != ancestor)
for (Node parent = node.Parent; parent != ancestorNode; parent = parent.Parent)
{
if (parent == null)
{
if (ancestorNode != null)
throw new ArgumentException(String.Format("Node \"{0}\" is not an ancestor of \"{1}\".", ancestorNode.Name, node.Name));
break;
}

transform = transform * parent.Transform;
parent = parent.Parent;
}

if (parent == null && ancestor != null)
throw new ArgumentException(String.Format("Node \"{0}\" is not an ancestor of \"{1}\".", ancestor.Name, node.Name));

return transform;
}

Expand Down

0 comments on commit 1d55ae5

Please sign in to comment.