문제

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?

도움이 되었습니까?

해결책

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.

GLKMatrix4MakeLookAt(0, 0, 7,
                     center.x, center.y 0,
                     0, 1, 0);

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.

GLKMatrix4MakeLookAt(rotation.x, rotation.y, 7,
                     center.x, center.y, 0,
                     0, 1, 0);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top