# Problem in myLookAt function

Hello all,
I am trying to create my own lookAt implementation similar to gluLookAt(). I tested some values for which the results are exactly the same as in gluLookAt function however, as i but some different values the view that my lookAt
function gives is not same as that given by gluLookAt. This is what I am doing in my implementation (Based on concepts from Computer Graphics by Hearn and Baker on page 353).

``````
MyLookAt(float ex, float ey, float ez, //Eye position
float lx, float ly, float lz, //LookAt point
float ux, float uy, float uz) //View up vector
{
float U, V, N, P;      0 -> x, 1 -> y, 2->z
float modN, modV;
flot dotUP, dotVP, dotNP;

P = ex;
P = ey;
P = ez;

N = ex - lx;
N = ey - ly;
N = ez - lz;

modN = Length(N);

N/=modN;
N/=modN;
N/=modN;

modV = Length(Vector(vx,vy,vz));

U = Cross(Vector(vx,vy,vz),N);

U/=modV;
U/=modV;
U/=modV;

V = Cross(N,U);   //Gets the cross product
dotUP = Dot(U, P);    //Gets the dot product
dotVP = Dot(V, P);    //Gets the dot product
dotNP = Dot(N, P);    //Gets the dot product

GLfloat mat;
MakeIdentity(mat);

mat = U;
mat = V;
mat = N;

mat = U;
mat = V;
mat = N;

mat = U;
mat = V;
mat = N;

mat = -dotUP;
mat = -dotVP;
mat = -dotNP;

glMultMatrixf(mat);
}
``````

First, what are vx, vy and vz ? Are they the velocity of the camera ?

And I think N should have the opposite direction.

Other things should right even if I’ve never made my own LookAt matrix.

Hope that helps.

Originally posted by jide:
[b]First, what are vx, vy and vz ? Are they the velocity of the camera ?

And I think N should have the opposite direction.

Other things should right even if I’ve never made my own LookAt matrix.

Hope that helps.[/b]
Well its a typo error vx,vy,vz should be ux,uy,uz they are the view up vector. As for N this is what has been given in the book Computer Graphics by Hearn and Baker.PLease help me out.
Thanx

I don’t know. Maybe you can have a look at the Mesa sources. Sorry.

Also try out the other forums: math & alog and advanced. They might help you more effectively than I even can.

Hello Jide
THank you very much for your help. I ran over my code again and came to realise that it had a few bugs removing which it is running ok. I even compared the output of mylookAt with the glulookat in two subwindows side by side and they work exactly the same. THe book is spot on.
MMMovania