我嘗試了@ omz的想法。但出現一些相互矛盾的結果,所以我更深入地挖掘了一些有趣的結果。
答案是主軸的倒數作爲主變換的子元素應用。這提供了與提供中間父節點完全不同的語義。具體來說,如果我從具有變換P的父節點和具有變換C的子節點開始,它們組合起來進行世界變換W = CATransform3DConcat(C,P)。相同的世界變換W通過將父節點的樞軸設置爲C的倒數來獲得,而不是在子節點上設置變換。
這種方法似乎提供了一些額外的實用性,因爲它不能通過插入中間節點來複制,也不能在應用之前反轉。正如Hal Mueller指出的那樣,文件確實表明這個關鍵點會影響旋轉和縮放以及位置,但是對影響的性質沒有提及。
下面是測試這個結論的結果:
Set parent rotation and node position.
Transform:
{ 1.00, 0.00, 0.00, 0.00 }
{ 0.00, 1.00, 0.00, 0.00 }
{ 0.00, 0.00, 1.00, 0.00 }
{ 1.00, 2.00, 3.00, 1.00 }
Pivot:
{ 1.00, 0.00, 0.00, 0.00 }
{ 0.00, 1.00, 0.00, 0.00 }
{ 0.00, 0.00, 1.00, 0.00 }
{ 0.00, 0.00, 0.00, 1.00 }
World Transform:
{ 1.00, 0.00, 0.00, 0.00 }
{ 0.00, 0.00, 1.00, 0.00 }
{ 0.00, -1.00, 0.00, 0.00 }
{ 1.00, -3.00, 2.00, 1.00 }
2013-04-04 13:49:55.453 Model Importer[43504:303]
CATransform3DConcat(node.transform, node.parentNode.transform)]
{ 1.00, 0.00, 0.00, 0.00 }
{ 0.00, 0.00, 1.00, 0.00 }
{ 0.00, -1.00, 0.00, 0.00 }
{ 1.00, -3.00, 2.00, 1.00 }
2013-04-04 13:49:55.454 Model Importer[43504:303]
Set parent rotation and parent.pivot to inverse position.
Transform:
{ 1.00, 0.00, 0.00, 0.00 }
{ 0.00, 1.00, 0.00, 0.00 }
{ 0.00, 0.00, 1.00, 0.00 }
{ 0.00, 0.00, 0.00, 1.00 }
Pivot:
{ 1.00, 0.00, 0.00, 0.00 }
{ 0.00, 1.00, 0.00, 0.00 }
{ 0.00, 0.00, 1.00, 0.00 }
{ 0.00, 0.00, 0.00, 1.00 }
World Transform:
{ 1.00, 0.00, 0.00, 0.00 }
{ 0.00, 0.00, 1.00, 0.00 }
{ 0.00, -1.00, 0.00, 0.00 }
{ 1.00, -3.00, 2.00, 1.00 }
下面的代碼:
// Verification
SCNVector3 v3 = {1.0, 2.0, 3.0};
SCNVector4 v4 = {1.0, 0, 0, M_PI/2.0};
node.parentNode.rotation = v4;
node.position = v3;
NSLog(@"\n\nSet parent rotation and node position.%@",
[self transformsForNodeToString:node]);
//
// Verify match with CATransform3DConcat
NSLog(@"\n\nCATransform3DConcat(node.transform, node.parentNode.transform)]%@",
[self transformToString:CATransform3DConcat(node.transform, node.parentNode.transform)]);
//
// Clear the child node transform and put the inverse in the parent's pivot.
CATransform3D position = node.transform;
CATransform3D inversePosition = CATransform3DInvert(position);
node.transform = CATransform3DIdentity;
node.parentNode.pivot = inversePosition;
NSLog(@"\n\nSet parent rotation and parent.pivot to inverse position.%@",
[self transformsForNodeToString:node]);
node.parentNode.pivot = CATransform3DIdentity;
node.parentNode.transform = CATransform3DIdentity;
+ (NSString*)transformsForNodeToString: (SCNNode*)node {
NSString* result = @"\n";
result = [result stringByAppendingFormat:
@"\nTransform:%@\nPivot:%@\nWorld Transform:%@",
[self transformToString:node.transform],
[self transformToString:node.pivot],
[self transformToString:[node worldTransform]]];
return result;
}
+ (NSString*)transformToString: (CATransform3D)transform {
NSString* result = @"\n";
result = [result stringByAppendingFormat:
@"{ % .2f, % .2f, % .2f, % .2f }\n", transform.m11, transform.m12, transform.m13, transform.m14];
result = [result stringByAppendingFormat:
@"{ % .2f, % .2f, % .2f, % .2f }\n", transform.m21, transform.m22, transform.m23, transform.m24];
result = [result stringByAppendingFormat:
@"{ % .2f, % .2f, % .2f, % .2f }\n", transform.m31, transform.m32, transform.m33, transform.m34];
result = [result stringByAppendingFormat:
@"{ % .2f, % .2f, % .2f, % .2f }\n", transform.m41, transform.m42, transform.m43, transform.m44];
return result;
}
歡迎評論!
感謝您的回覆!儘管如此,我仍然對語義感到困惑,因爲pivot指定了一個完整的矩陣。我嘗試在定位器上進行搜索,但與pivot相似,該術語的用法似乎不明確,沒有與您描述的內容匹配,或者我在Scene Kit中看到的內容。你有沒有可能知道任何鏈接或參考? –
我根據你的回覆編輯了我的問題。 –
看到我的編輯,我希望這使事情更清晰。 – omz