# glulookat replacement

hmm… okay i am writing a 3d engine(isn’t everyone?) but i am trying to stay away from glu library not glut or glaux but glu.h… and so i put together some thoughts and came up with a glulookat replacement… but it doesn’t seem to work in theory it should but maybe i am missing something small.

all the functions do what they sound like…

vec is declared as

typdef float vec;

used an array for various reasons as opposed to a struct.

the last parameter of functions is always the result… i replaced gltranslatef with just adding the values to the matrix.

Maybe someone could help me… maybe i am forgetting to set a certain modelview matrix or something…

void lookAt(float eyex, float eyey, float eyez,
float centerx,float centery,float centerz,
float upx, float upy, float upz)
{
vec F,f={0},UP, up={0},s={0},u={0};
matrix M;

``````    F=centerx-eyex;
F=centery-eyey;
F=centerz-eyez;

UP=upx;
UP=upy;
UP=upz;

NormalizeVector(F,&f);
NormalizeVector(UP,&up);

MultiplyVecs(f,up,&s);
MultiplyVecs(s,f,&u);

Reverse(f,&f);

ZeroMemory(&M,MATRIX4SIZE);

M= s;  M= s;  M= s;  M= 0;
M= u;  M= u;  M= u;  M= 0;
M= f;  M= f;  M= f;  M= 0;
M= -eyex; M= -eyey; M= -eyez; M= 1;

glMultMatrixf(M);
//glTranslatef (-eyex, -eyey, -eyez);
``````

}

thanks a ton…

Dan

I don’t know what is wrong in your code, but
there are two glu implementations I’m aware of.
MESA www.mesa3d.org and SGI OpenGL sample implementation (don’t remember url, somewhere on the www.sgi.com))
here is SGI’s code

``````[b]
void GLAPI
gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,
GLdouble upz)
{
int i;
float forward, side, up;
GLfloat m;

forward = centerx - eyex;
forward = centery - eyey;
forward = centerz - eyez;

up = upx;
up = upy;
up = 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);
m = side;
m = side;
m = side;

m = up;
m = up;
m = up;

m = -forward;
m = -forward;
m = -forward;

glMultMatrixf(&m);
glTranslated(-eyex, -eyey, -eyez);
}
``````

[/b]

And remember all matrix functions multiply generated matrix with the current(texture/projection/color/modelview…) matrix, don’t forget to load identity matrix when needed, if you want place your viewing origin in the 3d scene use

MatrixMode(MODELVIEW)