lkang2 / glmatrix

Automatically exported from code.google.com/p/glmatrix
0 stars 0 forks source link

lookat Function #51

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I had a trouble with the function mat4.LookAt(). This function work 
strangely,so I can’t understand how to set up this function.
this is the way I set up the function :

mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix);
mat4.lookAt([0, 0, 0], [0, 0, -100], [0, 1, 0], pMatrix);
mat4.identity(mvMatrix);

In that function,the eye postion is [0,0,0], look at the point [0,0,-100] (Deep 
inside the monitor), and UP vector is [0,1,0]. but it didn’t work as I 
Expected, and i tried some circumstances but all of them also don't work as i 
expected. If you see any mistake, please let me know.
Sorry about my annoy. I’m just a beginer ^^.

Original issue reported on code.google.com by dragon8xa2@gmail.com on 11 Apr 2011 at 3:07

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
leave projection matrix alone and pass your modelview matrix to lookat. lookat 
overwrites target matrix ;)
and this is desired behavior since it should be your first call while drawing.

mvMatrix = mat4.lookAt([0, 0, 1], [0, 0, 0], [0, 1, 0]);

above gives you "default" opengl camera setup.

-- UPDATE:

Just in case someone might find it useful in the future, here's detailed 
projection/modelview howto:
http://www.opengl.org/resources/faq/technical/projection_abuse.php
http://www.opengl.org/resources/faq/technical/viewing.htm

In short: use only mat4.identity and mat4.perspective on projection matrix and 
everything else goes in modelview matrix (and camera setup with lookat should 
be the very first thing).

BTW - if camera-stationary object is needed - draw it with identity modelview 
matrix or (in case a scene tree / matrix stack is in question) use inverse of 
lookat matrix (so when multiplied - gives identity)

Original comment by arturczajka@gmail.com on 3 May 2011 at 8:28