PDA

View Full Version : Problem in myLookAt function



MMMovania
04-11-2005, 04:35 AM
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[3], V[3], N[3], P[3]; 0 -> x, 1 -> y, 2->z
float modN, modV;
flot dotUP, dotVP, dotNP;

P[0] = ex;
P[1] = ey;
P[2] = ez;

N[0] = ex - lx;
N[1] = ey - ly;
N[2] = ez - lz;

modN = Length(N);

N[0]/=modN;
N[1]/=modN;
N[2]/=modN;

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

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

U[0]/=modV;
U[1]/=modV;
U[2]/=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[16];
MakeIdentity(mat);

mat[0] = U[0];
mat[1] = V[0];
mat[2] = N[0];

mat[4] = U[1];
mat[5] = V[1];
mat[6] = N[1];

mat[8] = U[2];
mat[9] = V[2];
mat[10] = N[2];

mat[12] = -dotUP;
mat[13] = -dotVP;
mat[14] = -dotNP;

glMultMatrixf(mat);
}Thanx in advance help me out please.

jide
04-11-2005, 08:15 AM
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.

MMMovania
04-11-2005, 06:36 PM
Originally posted by jide:
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.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

jide
04-12-2005, 06:51 AM
I don't know. Maybe you can have a look at the Mesa sources. Sorry.

jide
04-12-2005, 06:52 AM
Also try out the other forums: math & alog and advanced. They might help you more effectively than I even can.

MMMovania
04-12-2005, 07:16 PM
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