View Full Version : What is the definition of gluLookAt?

wangyubuct

05-14-2013, 05:57 AM

The description of the gluLookAt is as follows:

Let

F=centerX-eyeXcenterY-eyeYcenterZ-eyeZ

Let UP be the vector upXupYupZ.

Then normalize as follows:

f=FF

UP″=UPUP

Finally, let s=f×UP″, and u=s×f.

M is then constructed as follows:

M=s0s1s20u0u1u20-f0-f1-f200001 //??????

gluLookAt is equivalent to

glMultMatrixf(M);

glTranslated(-eyex, -eyey, -eyez);

Can you explain the description above?Especially the define of M,the line with ????.

Thank you very much.

tonyo_au

05-14-2013, 06:09 PM

Have a read of this

http://www.songho.ca/opengl/gl_transform.html

gluLookAt is just a shorthand to create the view model matrix

wangyubuct

05-15-2013, 04:37 AM

Thank you for your help,but I have to use gluLookAt in my program.Can you explain the function?

Alfonse Reinheart

05-15-2013, 06:03 AM

He just linked you to a very detailed explanation of how transforms work and what it does.

And no, you don't "have to use gluLookAt".

thokra

05-15-2013, 06:52 AM

It would be interesting to know what exactly the OP doesn't get about the function. Any specific questions or are you just not understanding anything at all?

Aleksandar

05-15-2013, 07:48 AM

I hope a concrete implementation (from MESA3D) would help

gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,

GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,

GLdouble upz)

{

float forward[3], side[3], up[3];

GLfloat m[4][4];

forward[0] = centerx - eyex;

forward[1] = centery - eyey;

forward[2] = centerz - eyez;

up[0] = upx;

up[1] = upy;

up[2] = upz;

normalize(forward);

/* Side = forward x up */

cross(forward, up, side);

normalize(side);

/* Recompute up as: up = side x forward */

cross(side, forward, up);

__gluMakeIdentityf(&m[0][0]);

m[0][0] = side[0];

m[1][0] = side[1];

m[2][0] = side[2];

m[0][1] = up[0];

m[1][1] = up[1];

m[2][1] = up[2];

m[0][2] = -forward[0];

m[1][2] = -forward[1];

m[2][2] = -forward[2];

glMultMatrixf(&m[0][0]);

glTranslated(-eyex, -eyey, -eyez);

}

thokra

05-15-2013, 07:52 AM

The thing is, Alfonse is right in saying you don't need to use gluLookAt, because if you get the math behind it, you can write up a function yourself. I suspect the OP doesn't have a sufficient mathematical basis.

wangyubuct

05-15-2013, 10:06 PM

This is exactly what I need!!!Thank you so much!

鄙视狗眼看人低。

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.