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.

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.