如何将3D OpenGL矩阵转换为CoreAnimation CATransform3Ds? [英] How do I convert 3D OpenGL matrix transforms to CoreAnimation CATransform3Ds?

查看:136
本文介绍了如何将3D OpenGL矩阵转换为CoreAnimation CATransform3Ds?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将OpenGL ES 1.1呈现表面与同一框架的透明CALayer以及其上方的边界进行图片化。 OpenGL场景中的对象使用4x4矩阵进行变换(平移和旋转)。重叠的CALayer使用CATransform3D(这是恰好是一个4x4矩阵)转换子图层,与用于OpenGL变换的相同)。

Picture an OpenGL ES 1.1 rendering surface with a transparent CALayer of the same frame and bounds directly above it. Objects in the OpenGL scene are transformed (translated and rotated) using a 4x4 matrix. The overlayed CALayer transforms sublayers with a CATransform3D (which happens to be a 4x4 matrix, identical to ones used for OpenGL transforms).

OpenGL矩阵以我想要的方式变换场景对象。然后,我想对场景对象采用相同的矩阵变换,并将CALayer应用于子图层,以使子图层与场景对象的位置和方向完全相同。

The OpenGL matrices transform the scene objects in exactly the manner I would like them to. I would then like to take the same matrix transform used on the scene object and have the CALayer apply it to a sublayer such that the sublayer is in the exact same position and orientation as the scene object.

问题是(我认为)我的OpenGL场景和CALayer的场景不同意任意场景单元的定义,这种不一致表现为翻译中的差异的子层与场景对象的平移(旋转是精细的)。具体来说,CALayer似乎在理解场景单元非常接近屏幕像素的情况下工作,而我的OpenGL场景使用更大的单位,这意味着CALayer只翻译场景对象的一小部分。

The problem is (I think) that my OpenGL scene and the "scene" of the CALayer don't agree on definition of the arbitrary "scene-unit", and this disagreement manifests itself as discrepancies in the translation of the sub-layer vs. the translation of the scene object (The rotations are fine). Specifically, the CALayer seems to operate with the understanding that a scene unit corresponds very closely to a screen pixel, whereas my OpenGL scene uses much larger units, meaning the CALayer translates only a small fraction of what a scene object does.

所以我要找的是一种将OpenGL场景单元中指定的矩阵变换数学转换为CALayer-scene-unit中指定的功能等效矩阵变换的方法。我需要能够在我的OpenGL场景单元中定义一个CALayer-scene-unit,但我不知道CALayer如何在后台与OpenGL连接。

So what I'm looking for is a way to mathematically convert a matrix transform specified in my OpenGL scene-units to a functionally equivalent matrix transform specified in the CALayer-scene-unit. I need to be able to define a CALayer-scene-unit in terms of my OpenGL scene unit, but I have no idea how the CALayer is interfacing with OpenGL behind the scenes.

是否可以用这种方式计算转换?如果没有,还有其他方法可能有帮助吗?

Is it possible to calculate the conversion in such a way? If not, are there other approaches that may help?

注意:我已经能够补救这个问题,一个纯粹的经验方法,基本上归结为注意到什么调整需要对CATransform3D进行,使其在几个位置工作,并外推。

NOTE: I've been able to remedy the issue with a purely empirical approach that basically comes down to noting what adjustment needs to be made to the CATransform3D to make it work in a couple positions, and extrapolating. I'm hoping for something more precise.

推荐答案

我猜这些问题是由OpenGL视图的投影矩阵引起的。请记住,从世界到视图的转换是 view_point = projection x modelview x world_point

I’m guessing the problems is caused by the OpenGL view’s projection matrix. Remember that the transformation from world to view is view_point = projection x modelview x world_point.

这篇关于如何将3D OpenGL矩阵转换为CoreAnimation CATransform3Ds?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆