Rancs
Rancs

Reputation: 165

Translation in opengles

  1. I translate the modelview matrix to: glTranslatef(-camerax, -cameray, -cameraz)
  2. rotate the modelview matrix to camera rotation glRotatef(camangle, camrotx, camroty, camrotz)
  3. Then i render the objects starting here between pushmatrix & popmatrix commands.

    Everything working, translating and rotating well. Until i try to move camera in the rotated modelview matrix. I want to translate the camera moves toward (int its own object space).

  4. I added this line into onKeyDown method of UP key: glTranslatef(0f, 0f, 1f);

But with this command, the cam moves toward -z axis of modelview matrix, not toward -z axis of its own space.

I could not figure out how to make the object translation in its own toward direction. Can somebody explain me how it shoud be done.

Upvotes: 0

Views: 642

Answers (2)

Rancs
Rancs

Reputation: 165

posz += (zdif * (float)(Math.cos(Math.toRadians(yrot))));
glTranslatef(0f, 0f, posz);

did make the necessary translation.

Upvotes: 0

Jonas Bötel
Jonas Bötel

Reputation: 4482

It's all about multiplication order (as matrix multiplication is not commutative). It makes a big difference do step 4 before or after step 2! One is in screen space, the other is world space.

Upvotes: 1

Related Questions