问题
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.
回答1:
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
.
来源:https://stackoverflow.com/questions/5887995/how-do-i-convert-3d-opengl-matrix-transforms-to-coreanimation-catransform3ds