如何将 3D OpenGL 矩阵变换转换为 CoreAnimation CATransform3D?

发布于 2024-11-05 02:55:03 字数 820 浏览 1 评论 0原文

想象一个 OpenGL ES 1.1 渲染表面,具有同一帧的透明 CALayer 并直接位于其上方。 OpenGL 场景中的对象使用 4x4 矩阵进行变换(平移和旋转)。覆盖的 CALayer 使用 CATransform3D 变换子层(它恰好是一个 4x4 矩阵,与用于 OpenGL 变换的相同)。

OpenGL 矩阵完全按照我希望的方式变换场景对象。然后,我想采用在场景对象上使用的相同矩阵变换,并让 CALayer 将其应用到子图层,以便子图层与场景对象处于完全相同的位置和方向。

问题是(我认为)我的 OpenGL 场景和 CALayer 的“场景”在任意“场景单元”的定义上不一致,这种分歧表现为子层与. 场景对象的平移(旋转很好)。具体来说,CALayer 的运行似乎是基于这样的理解:场景单元与屏幕像素非常接近,而我的 OpenGL 场景使用更大的单元,这意味着 CALayer 只转换场景对象所做的一小部分。

因此,我正在寻找一种方法,以数学方式将 OpenGL 场景单元中指定的矩阵变换转换为 CALayer 场景单元中指定的功能等效的矩阵变换。我需要能够根据我的 OpenGL 场景单元定义 CALayer 场景单元,但我不知道 CALayer 如何在幕后与 OpenGL 交互。

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

注意:我已经能够用纯粹的经验方法来解决这个问题,基本上可以归结为注意需要对 CATransform3D 进行哪些调整才能使其在几个位置上工作,并进行推断。我希望有更精确的东西。

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

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.

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.

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2024-11-12 02:55:03

我猜测问题是由 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文