使用 GLKMatrix4Translate 进行平移似乎是围绕相机移动,而不是原点移动
我试图让用户能够在 OpenGL ES 中向上/向下和向左/向右平移对象。我使用 GLKit 进行所有绘图和移动。我已启用触摸事件来跟踪用户想要如何移动对象。我正在使用 GLKMatrix4Translate 来滑动对象的平移,但由于某种原因它也有一个旋转组件。
我从用户的触摸中收集翻译点并将它们存储在 CGPoint 中:
CGPoint center;
我使用 center.x 和 center.y 作为我想要翻译到的 X 和 Y 位置。我用这句话进行翻译:
GLKMatrix4 modelViewMatrix = GLKMatrix4Translate(GLKMatrix4Identity, center.x, center.y, 0.0f);
有什么想法吗?
I'm trying to enable a user to pan up/down and left/right an object in OpenGL ES. I'm using GLKit for all of the drawing and movement. I've enabled touch events to track how the user wants to move the object. I'm using GLKMatrix4Translate to slide the pan the object, but it has a rotational component to it as well for some reason.
I gather the translation points from the user's touch and store them in a CGPoint:
CGPoint center;
I use center.x and center.y for the X and Y positions I want to translate to. I perform the translation with this line:
GLKMatrix4 modelViewMatrix = GLKMatrix4Translate(GLKMatrix4Identity, center.x, center.y, 0.0f);
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我明白问题出在哪里了。我停止使用 GLKMatrix4Translate 并将其替换为 GLKMatrix4MakeLookAt。 GLKMatrix4MakeLookAt 允许您移动相机,这给出了我正在寻找的效果。
简单地使用这段代码会导致我已经看到的相同问题。模型在平移时旋转。
这意味着您希望相机始终注视 (0,0,7),中心位于 (center.x, center.y, 0),y 轴朝上。眼睛的指向就是问题。如果模型正在旋转(事实确实如此),您需要将眼睛指向新旋转的点。
用下面的代码替换上面的代码似乎可以解决问题。
I figured out what the problem was here. I stopped using GLKMatrix4Translate and replaced that with GLKMatrix4MakeLookAt. GLKMatrix4MakeLookAt allows you to move the camera around which gives the effect I was looking for.
Simply using this code results in the same problem I was already seeing. The model rotates as it pans.
What this is saying is that you want the camera to always look at (0,0,7) with the center at (center.x, center.y, 0) with the y-axis pointing up. The pointing of the eye is the problem. If the model is rotating (which it is), you need to point the eye at the newly rotated point.
Replacing the above with the code below seems to do the trick.