Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor GetRelativeTransform(...) #2140

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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