我写了一个在EasyAR上运行的AR应用程序。我使用OpenGL使用Objective-C code found here在检测到的标记上方渲染视频。该代码的关键部分如下。我现在正在尝试使用SCNPlane
做类似的事情,这样我就可以更轻松地将所需的UI东西放到所需的平面上。但是,该平面似乎没有正确映射(请参阅一起运行的两个渲染器的GIF)。知道为什么这不匹配吗?如何使它完美匹配?
快速SCN飞机代码
var scnView: SCNView!
@objc func render(projectionMatrix: easyar_Matrix44F, cameraView:easyar_Matrix44F, sizeObjs:easyar_Vec2F) {
var projection = [Float]()
var camera = [Float]()
let size = [sizeObjs.data[0],sizeObjs.data[0]]
for i in 0...15 {
projection.append((projectionMatrix.data![i]).floatValue)
}
for i in 0...15 {
camera.append((cameraView.data![i]).floatValue)
}
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.withAlphaComponent(0.5)
let n = SCNNode()
n.transform = SCNMatrix4FromGLKMatrix4(m)
n.geometry = plane
let scnScene = SCNScene()
overlayView.scene = scnScene
scnScene.rootNode.addChildNode(n)
}
Objective C OpenGL提取
- (void)render:(easyar_Matrix44F *)projectionMatrix cameraview:(easyar_Matrix44F *)cameraview size:(easyar_Vec2F *)size {
//...
float * cameraview_data = calloc(16, sizeof(float));
float * cameraview_data = calloc(16, sizeof(float));
float * projectionMatrix_data = calloc(16, sizeof(float));
for (int i = 0; i < 16; i++) {
cameraview_data[i] = [[cameraview.data objectAtIndex:i] floatValue];
}
for (int i = 0; i < 16; i++) {
projectionMatrix_data[i] = [[projectionMatrix.data objectAtIndex:i] floatValue];
}
glUniformMatrix4fv(pos_trans_box, 1, 0, cameraview_data);
glUniformMatrix4fv(pos_proj_box, 1, 0, projectionMatrix_data);
// ...
}
DEMO GIF