Tradurre con GLKMatrix4Translate sembra muoversi riguardanti la fotocamera, non la provenienza

StackOverflow https://stackoverflow.com/questions/8824234

Domanda

Sto cercando di consentire ad un utente di eseguire una panoramica su / giù e sinistra / destra un oggetto in OpenGL ES. Sto usando GLKit per tutti del disegno e del movimento. Ho attivato gli eventi touch per tenere traccia di come l'utente vuole spostare l'oggetto. Sto usando GLKMatrix4Translate di far scorrere il tegame l'oggetto, ma ha una componente rotazionale ad esso pure, per qualche motivo.

Mi sembra di capire i punti di traduzione dal tocco dell'utente e memorizzarli in un CGPoint:

CGPoint center;

Io uso center.x e center.y per le posizioni X e Y che voglio tradurre in. Eseguo la traduzione con questa linea:

GLKMatrix4 modelViewMatrix = GLKMatrix4Translate(GLKMatrix4Identity, center.x, center.y, 0.0f);

Tutte le idee?

È stato utile?

Soluzione

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top