我有一些格式为
的矩阵数据float * projection = calloc(16, sizeof(float));
它非常适合
glUniformMatrix4fv(pos_proj_box, 1, 0, projection);
如何转换此矩阵(长度为16的基本float数组)以适合SCNMatrix4
?
如果执行此操作,则会显示错误的位置:
n.transform = SCNMatrix4(m11: projection[0], m12: projection[1], m13: projection[2], m14: projection[3], m21: projection[4], m22: projection[5], m23: projection[6], m24: projection[7], m31: projection[8], m32: projection[9], m33: projection[10], m34: projection[11], m41: projection[12], m42: projection[13], m43: projection[14], m44: projection[15])
编辑
所以现在我认为转换可以,但是我的代码有其他问题。似乎平面始终是正方形,而不是更改为矩阵中输入的大小。好像它与正确的位置成一定角度也无法正确匹配...
let m = GLKMatrix4(m: (projection[0],projection[1],projection[2],projection[3],projection[4],projection[5],projection[6],projection[7], projection[8],projection[9],projection[10],projection[11],projection[12],projection[13],projection[14],projection[15]))
let plane = SCNPlane()
plane.firstMaterial?.diffuse.contents = UIColor.blue
let n = SCNNode()
n.transform = SCNMatrix4FromGLKMatrix4(m)
n.geometry = plane
let scnScene = SCNScene()
overlayView.scene = scnScene
scnScene.rootNode.addChildNode(n)