Public Matrix As CMatrix

Public Sub Draw()

 glPushMatrix

  Matrix.Apply 'call glMultMatrix

  glCallList ListID 'draw the model

  Matrix.Draw 'draw the axes

 glPopMatrix

End Sub

The camera drawing is a bit more complex, because it has 2 ways to draw – it can either 'draw' itself as the 'active camera' (i.e. as the viewing transform) or it can draw an icon of itself in the scene (when we are actually viewing from somewhere else). Let's look at the more typical case – drawing itself as the active camera – since this is what a camera is for.

The following code is (a somewhat edited version of) the main drawing routine in the 'CXXX' class:

Public Sub Draw()

Dim m!(0 To 15)

 glPushMatrix

  'draw camera

  Camera.Draw

  'draw grids

  With gCtl

   If m_Grids Then .DrawGrids

  End With

  'draw model

  Model.Draw

 glPopMatrix

 CheckError

End Sub

The camera matrix will provide the viewing transformation by multiplying the current gl matrix (which at this point happens to be the identity matrix) by its own matrix. This operation is equivalent to calling gluLookAt. If you look at the source for gluLookAt in the Mesa library, you will see that gluLookAt builds a transformation matrix m and then calls glMultMatrixd(m), which is exactly what our camera will do.



2 из 4