- static TVector viewdir;
- static TVector viewup;
- static TPoint viewpos;
- void CalcViewMatrix () {
- TMatrix viewmat, vmat;
- TVector vx, vy, vz;
- TPoint vpoint;
- vz = ScaleVector (-1, viewdir);
- vx = CrossProduct (viewup, vz);
- vy = CrossProduct (vz, vx);
- NormalizeVector (&vz);
- NormalizeVector (&vx);
- NormalizeVector (&vy);
- MakeIdentityMatrix (viewmat);
- viewmat[0][0] = vx.x;
- viewmat[0][1] = vx.y;
- viewmat[0][2] = vx.z;
- viewmat[1][0] = vy.x;
- viewmat[1][1] = vy.y;
- viewmat[1][2] = vy.z;
- viewmat[2][0] = vz.x;
- viewmat[2][1] = vz.y;
- viewmat[2][2] = vz.z;
- viewmat[3][0] = viewpos.x;
- viewmat[3][1] = viewpos.y;
- viewmat[3][2] = viewpos.z;
- viewmat[3][3] = 1;
- TransposeMatrix (viewmat, vmat);
- vmat[0][3] = 0;
- vmat[1][3] = 0;
- vmat[2][3] = 0;
- vpoint = TransformPoint (vmat, viewpos);
- vmat[3][0] = -vpoint.x;
- vmat[3][1] = -vpoint.y;
- vmat[3][2] = -vpoint.z;
- glLoadIdentity();
- glMultMatrixd ((double*)vmat);
- }