PDA

View Full Version : gluLookAt



thorsan
02-23-2004, 03:43 AM
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
eye[Y] = radius * sin(xzrot*M_PI/180);
eye[X] = radius * cos(xzrot*M_PI/180) * sin(yrot*M_PI/180);
eye[Z] = radius * cos(xzrot*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 \n",eye[X],eye[Y],eye[Z]);
float length = sqrt(eye[X]*eye[X] + (eye[Z])*(eye[Z]) + eye[Y]*eye[Y]);
printf("length: %f \n", 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.

thorsan
02-23-2004, 05:13 AM
I have now solved the problem with the gluLookAt like this:

void calculateAndLook(){
//regner ut posisjon i kuleskallet
eye[Y] = radius * sin(xzrot*M_PI/180);
eye[X] = radius * cos(xzrot*M_PI/180) * sin(yrot*M_PI/180);
eye[Z] = (radius * cos(xzrot*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