场景套件:对顶点应用变换



我需要对SCNNode上包含的所有顶点应用变换。每个SCNNode都包含一个 SCNMatrix4 转换属性。我还得到了SCNNode的所有顶点.

 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);

我得到了一个奇怪的结果,旋转和平移错误。我的计算,正确吗?

>SCNMatrix4是一个 4x4 矩阵,但在这里你将其用作 3x3 矩阵。您基本上删除了所有翻译,只保留旋转和比例因子。查看SCNMatrix4ToMat4SCNVector4ToFloat4w=1),并使用 SIMD 执行转换。

最新更新