Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the method Matrix.setLookAtM work in OpenGL ES?

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.

like image 347
xtraorange Avatar asked Nov 25 '12 03:11

xtraorange


1 Answers

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.

like image 77
zero298 Avatar answered Oct 23 '22 10:10

zero298