2015-04-17 68 views
0

我需要对包含在SCNNode中的所有顶点应用转换。 每个SCNNode包含一个SCNMatrix4变换属性。 我也得到了我的所有顶点SCNNodeSceneKit:在顶点上应用转换

Vertex *currentVertex = [self.vectrices objectAtIndex:buff[index]]; 
SCNNode *currentChildren = myNode;  
Vertex *new = [Vertex new]; 

new.x = (currentChildren.transform.m11 * currentVertex.x) + (currentChildren.transform.m12 * currentVertex.y) + (currentChildren.transform.m13 * currentVertex.z); 
new.y = (currentChildren.transform.m21 * currentVertex.x) + (currentChildren.transform.m22 * currentVertex.y) + (currentChildren.transform.m23 * currentVertex.z); 
new.z = (currentChildren.transform.m31 * currentVertex.x) + (currentChildren.transform.m32 * currentVertex.y) + (currentChildren.transform.m33 * currentVertex.z); 

我得到了一个奇怪的结果与错误的旋转和翻译。 我的计算结果是否正确?

回答

2

SCNMatrix4是一个4x4的矩阵,但在这里你使用它作为3x3矩阵。您基本上删除所有翻译,并保持旋转和缩放因子。 看看SCNMatrix4ToMat4SCNVector4ToFloat4(取w=1)并使用SIMD执行转换。

+0

float w =(currentChildren.transform.m41 * currentVertex.x)+(currentChildren.transform.m42 * currentVertex.y)+(currentChildren.transform.m43 * currentVertex.z)+ currentChildren.transform.m44; new.x = new.x/w; new.y = new.y/w; new.z = new.z/w;上面的 – user2724028

+0

,你可以看到我是怎么做的。你有任何例子如何使用这些方法?谢谢 – user2724028

+0

我创建了一个SCNVector4,我有一个SCNMatrix4。现在我怎么做这个操作:SCNMatrix4 * SCNVector4? – user2724028