Nicolas Gauvin (nicolas++at++cae.ca)
Mon, 8 Apr 1996 11:57:11 -0400
> How can I simulate gluLookAt with Performer calls ?
You need to compute a pfMatrix containing the correct rotations and
translations. Then you set this matrix as the viewing matrix of your pfChannel
via the C pfChanSetViewMat or C++ pfChannel::setViewMat call.
Here is an implementation of a function that will create this matrix for you:
Note that the restriction that the up vector must not be parallel to
the viewing direction still holds.
/* C version */
void pfMakeLookAtMat( pfMatrix mat, pfVec3 eye, pfVec3 center, pfVec3 up )
{
/* row unit vectors representing axis rotations */
pfVec3 x,y,z;
/* Y vector points from eye to center */
y[PF_X] = center[PF_X] - eye[PF_X];
y[PF_Y] = center[PF_Y] - eye[PF_Y];
y[PF_Z] = center[PF_Z] - eye[PF_Z];
pfNormalizeVec3(y);
/* Z vector is UP */
z[PF_X] = up[PF_X];
z[PF_Y] = up[PF_Y];
z[PF_Z] = up[PF_Z];
/* X vector = Y cross Z */
pfCrossVec3(x, y, z);
pfNormalizeVec3(x);
/* Recompute Z = X cross Y to make it perpendicular to the others */
pfCrossVec3(z, x, y);
pfNormalizeVec3(z);
/* create final matrix */
/* first set translation */
pfMakeTransMat(mat,eye[PF_X],eye[PF_Y],eye[PF_Z]);
/* then set normalized axis rotation row vectors */
pfSetMatRowVec3(mat,0,x);
pfSetMatRowVec3(mat,1,y);
pfSetMatRowVec3(mat,2,z);
}
/* C++ version */
void pfMakeLookAtMat( pfMatrix& mat, pfVec3& eye, pfVec3& center, pfVec3& up )
{
// row unit vectors representing axis rotations
pfVec3 x,y,z;
// Y vector points from eye to center
y = center - eye;
y.normalize();
// Z vector is UP
z = up;
// X vector = Y cross Z
x.cross(y,z);
x.normalize();
// Recompute Z vector = X cross Y to make it perpendicular to the others
z.cross(x,y);
z.normalize();
// create final matrix
// first set translation
mat.makeTrans(eye[PF_X],eye[PF_Y],eye[PF_Z]);
// then set normalized axis rotation row vectors
mat.setRow(0,x);
mat.setRow(1,y);
mat.setRow(2,z);
}
For the Performer team:
How about adding a similar pfMatrix function in a future Performer release?
Something like pfMatrix::makeLookAt would be nice.
--
___/ | ___/ Nicolas Gauvin e-mail: nicolas++at++cae.ca
/ / | / Software Developper voice: (514) 341-2000 x2275
/ / | __/ CAE Electronics Ltd. fax: (514) 340-5496
/ ___ | / 8585 Cote De Liesse, P.O. Box 1800
_____/ _/ _| _____/ Saint-Laurent, Quebec, Canada, H4L-4X4
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:41 PDT