The values in the matrix, however, represent the position and orientation of the camera (because we are using the same matrix as the model). These values are the same values as the eye, center, and up values which would be used in a call to gluLookAt. If we were drawing the camera as an object in the scene, we would use this matrix. But we are trying to set the viewing transform, which is the inverse of a modeling transform (see pg. 100 in the Red Book for a discussion). So before we can use the matrix we must invert it. (The Push/Pop stuff is how the Matrix saves and restores its current matrix when making temporary changes to it.)

Public Sub Draw()

 Matrix.Push

 Matrix.Invert

 Matrix.Apply

 Matrix.Pop

End Sub

The effect of this is to transform the entire scene (all subsequent commands) by the opposite of the camera position. For example, if we are starting from 0,0,0, and we want the camera to be at 0,0,10, we move the entire scene by 0,0,-10. (The 'camera' is a fiction which just describes this matrix which is placed on the stack before the scene is drawn.)

The camera has a second drawing routine which it uses when it is not active. In this case, it behaves like the model except that its orientation must be reversed to reflect the viewing characteristics of the camera. I did this by just rotating 180 degrees. (This has the side-effect of reversing the sense of the keys, perhaps the Matrix class needs 'reflect' routine for this.)

Public Sub DrawIcon()

 glPushMatrix

  Matrix.Apply

  'draw the box for the camera

  glRotatef 180, 0, 1, 0

  glCallList ListID

  'draw the axes



3 из 4