DirectX SDK

Step 2.1: Define the Viewpoint

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See Direct3D Immediate Mode Visual Basic Tutorials.

[C++]

This tutorial uses the application-defined subroutine App_FrameMove to rotate the viewpoint around in a circle. The viewpoint is most conveniently defined by three D3DVECTOR structures: an eye point, a look-at point, and a vector defining the up direction:

HRESULT App_FrameMove( LPDIRECT3DDEVICE7 pd3dDevice, FLOAT fTimeKey )
{
    D3DVECTOR vEyePt    = D3DVECTOR( 5*sinf( fTimeKey), 3, 5*cosf( fTimeKey ) );
    D3DVECTOR vLookatPt = D3DVECTOR( 4*sinf( fTimeKey+0.1f), 2.5, 4*cosf( fTimeKey+0.1f ) );
    D3DVECTOR vUpVec    = D3DVECTOR( 0, 1, 0 );

You use the three vectors to create a new view matrix:

    D3DMATRIX matView;
    SetViewMatrix( matView, vEyePt, vLookatPt, vUpVec );

The preceding code creates a new view matrix for the device by passing the eye point, the look-at point, and the vector defining the up direction to the programmer-defined SetViewMatrix method, which is explained in Step 2.2: Create and Set the View Matrix.