Another step in setting up a simple scene involved setting the world, view, and projection matrices. The system applies these matrices to geometry to place it in the scene, adjust for the camera's location and orientation, and scale vertex data to make distant objects appear smaller than near objects. (For a conceptual overview, see The Geometry Pipeline.)
The Triangle sample starts by creating an identity matrix in a D3DMATRIX structure, then it manipulates the matrix to produce the desired transformations. Once a matrix is ready, the code assigns it to the device by calling the IDirect3DDevice3::SetTransform method with the D3DTRANSFORMSTATE_WORLD, D3DTRANSFORMSTATE_VIEW, or D3DTRANSFORMSTATE_PROJECTION values:
// Start by setting up an identity matrix.
D3DMATRIX mat;
mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
// The world matrix controls the position and orientation
// of the polygons in world space. We'll use it later to
// spin the triangle.
D3DMATRIX matWorld = mat;
pd3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &matWorld );
// The view matrix defines the position and orientation of
// the camera. Here, we are just moving it back along the z-
// axis by 10 units.
D3DMATRIX matView = mat;
matView._43 = 10.0f;
pd3dDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView );
// The projection matrix defines how the 3-D scene is "projected"
// onto the 2-D render target surface. For more information,
// see "What Is the Projection Transformation?"
// Set up a very simple projection that scales x and y
// by 2, and translates z by -1.0.
D3DMATRIX matProj = mat;
matProj._11 = 2.0f;
matProj._22 = 2.0f;
matProj._34 = 1.0f;
matProj._43 = -1.0f;
matProj._44 = 0.0f;
pd3dDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj );
After setting the transformations, Triangle is done setting up the scene. The App_InitDeviceObjects application-defined function returns S_OK to the caller, the Initialize3DEnvironment application-defined function. The Initialize3DEnvironment function then returns that value to WinMain, which moves on to process system messages, as discussed in Step 4: Monitor System Messages.