15

How does Matrix.setLookAtM work? I've been searching all over, and can't find an explanation. I understand that the first three coordinates are to define the location of the camera in the world space, and I take it that "center of view" means the x, y, z coordinate I'm looking at in the world space. That being the case, what does the "up vector" mean/do?

If there is a previous question or tutorial that I've overlooked, I would be happy to accept that.

0xCursor
  • 2,242
  • 4
  • 15
  • 33
xtraorange
  • 1,456
  • 1
  • 16
  • 37

1 Answers1

22

Up vector is what the camera considers "up", i.e.: If you were looking forward and held your hand up, that is your "up" vector. Just set it to 0, 1, 0. I'm not an Android developer, but I'm guessing it's similar to gluLookAt().

What the function is really doing is setting up a view matrix for you. It needs the eye position to establish where the camera will be. After that, it will subtract eye position from center and normalize it to get a forward vector. Then it will cross the forward vector with the up vector to get a right vector. After normalizing all three, it can construct a matrix from those x, y, z vectors giving you a basic model view matrix.

It just discretizes the math for you.

0xCursor
  • 2,242
  • 4
  • 15
  • 33
zero298
  • 25,467
  • 10
  • 75
  • 100
  • Ah I see, it didn't cross my mind, but I suppose the camera could be upside down or sideways or what have you, and the up vector determines that. Makes perfect sense, thanks so much for explaining that. :) – xtraorange Nov 25 '12 at 18:19
  • setLookAtM takes 9 parameters (excluding an offset value and a reference to your output matrix), i.e. eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ - Hw do these relate to your recommended setting of `0,1,0`? – JCutting8 Oct 26 '21 at 05:16
  • @JCutting8 The last 3 parameters. – m0skit0 Feb 24 '22 at 12:16