# gluLookAt

Trying to use gluLookAt. Im rotating around like rhe camera is on an sphere with an radius from the center of the object:
void calculateAndLook(){
//regner ut posisjon i kuleskallet
M_PI/180) * sin(yrotM_PI/180);
M_PI/180) * cos(yrot*M_PI/180);

``````//renger ut hva som er opp, tangenten til kuleskallet
up[Y] = 1.0 * sin(xzrot*M_PI/180);
up[X] = 1.0 * cos(yrot*M_PI/180);
up[Z] = 1.0 * sin(yrot*M_PI/180);

//center er i origo
center[X] = 0.0f;
center[Y] = 0.0f;
center[Z] = 0.0f;
printf("X:%f Y:%f Z:%f
``````

",eye[X],eye[Y],eye[Z]);
float length = sqrt(eye[X]eye[X] + (eye[Z])(eye[Z]) + eye[Y]*eye[Y]);
printf("length: %f
", length);

``````//ser
gluLookAt(eye[X],eye[Y],eye[Z],center[X],center[Y],center[Z],up[X],up[Y],up[Z]);
``````

}

but this dousnt work right.Im inside the box when i start the program. But when i change center[Z] to -7, the rotation goes completly amok.

I have now solved the problem with the gluLookAt like this:

void calculateAndLook(){
//regner ut posisjon i kuleskallet
M_PI/180) * sin(yrotM_PI/180);
M_PI/180) * cos(yrot*M_PI/180));

``````//renger ut hva som er opp, tangenten til kuleskallet
up[Y] = 1.0 * sin(xzrot*M_PI/180 + (M_PI/2));
up[X] = 0.0;
up[Z] = 0.0;

//center er i origo
center[X] = 0.0f;
center[Y] = 0.0f;
center[Z] = 0.0f;

//ser
gluLookAt(eye[X],eye[Y],eye[Z],center[X],center[Y],center[Z],up[X],up[Y],up[Z]);
``````

}

this works great.

I now want to use a rotation matrix instead. either using glRotate*() og building a matrix bottom up. How can i go from the vectors computed for gluLookAt to a rotation matrix?

thorsan