透视投影矩阵
在ARFrame可以获取衬着须要的纹理和摄像机矩阵,除了这些,和真实摄像头匹配的透视投影矩阵也是必须的。它可以或许让衬着出来的3D物体透视看起来很天然。
- (void)session:(ARSession *)session cameraDidChangeTrackingState:(ARCamera *)camera { matrix_float4x4 projectionMatrix = [camera projectionMatrixWithViewportSize:self.viewport.size orientation:UIInterfaceOrientationPortrait zNear:0.1 zFar:1000]; GLKMatrix4 newWorldProjectionMatrix = GLKMatrix4Identity; for (int col = 0; col < 4; ++col) { for (int row = 0; row < 4; ++row) { newWorldProjectionMatrix.m[col * 4 + row] = projectionMatrix.columns[col][row]; } } self.worldProjectionMatrix = newWorldProjectionMatrix;}膳绫擎的代码演示了若何经由过程ARKit获取3D透视投影矩阵,有了透视投影矩阵和摄像机矩阵,就可以很便利的应用OpenGL衬着物体了。
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { [super glkView:view drawInRect:rect]; [self.objects enumerateObjectsUsingBlock:^(GLObject *obj, NSUInteger idx, BOOL *stop) { [obj.context active]; [obj.context setUniform1f:@"elapsedTime" value:(GLfloat)self.elapsedTime]; [obj.context setUniformMatrix4fv:@"projectionMatrix" value:self.worldProjectionMatrix]; [obj.context setUniformMatrix4fv:@"cameraMatrix" value:self.cameraMatrix]; [obj.context setUniform3fv:@"lightDirection" value:self.lightDirection]; [obj draw:obj.context]; }];}本文重要介绍了OpenGL ES衬着ARKit的根本思路,没有对OpenGL ES技巧细节描述太多。如不雅你有兴趣,可以直接clone Github上的代码深刻懂得。
【编辑推荐】
- 若何应用Xcode的Targets来治理开辟和临盆版本的构建
- 为什么 Linus Torvalds 偏爱x86而不是ARM架构
- 挨踢部落第一期:Spark离线分析维度
- Google要逆天!Google Wear 2.0 最新离线AI技巧解析
- 我的深度进修开辟情况详解:TensorFlow + Docker + PyCharm等,你的呢?
推荐阅读
【51CTO.com快译】 有些开辟团队十分推许主动化测试,弗成否定,主动化测试在回归测试和检查冗余组件方面不掉>>>详细阅读
本文标题:ARKit & OpenGL ES - ARKit 原理及实现
地址:http://www.17bianji.com/lsqh/36017.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示