DirectX SDK

Step 5.1: Update the Scene

[Visual Basic]

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

[C++]

Immediately after it is called, the Render3DEnvironment application-defined function in the Triangle sample calls App_FrameMove (another application-defined function). The App_FrameMove function simply updates the world matrix that Direct3D applies to the geometry to reflect a rotation around the y-axis based on an internal count value, passed to the function in the fTimeKey parameter. Because the rotation is applied once per frame, the end result looks like the model is rotating in place.

HRESULT App_FrameMove( LPDIRECT3DDEVICE7 pd3dDevice, FLOAT fTimeKey )
{
    // For this simple tutorial, we are rotating the triangle about the y-axis.
    // To do this, just set up a 4x4 matrix defining the rotation, and set it
    // as the new world transform.
    D3DMATRIX matSpin;
    matSpin._11 = matSpin._22 = matSpin._33 = matSpin._44 = 1.0f;
    matSpin._12 = matSpin._13 = matSpin._14 = matSpin._41 = 0.0f;
    matSpin._21 = matSpin._23 = matSpin._24 = matSpin._42 = 0.0f;
    matSpin._31 = matSpin._32 = matSpin._34 = matSpin._43 = 0.0f;
    
    matSpin._11 = (FLOAT)cos( fTimeKey );
    matSpin._33 = (FLOAT)cos( fTimeKey );
    matSpin._13 = -(FLOAT)sin( fTimeKey );
    matSpin._31 = (FLOAT)sin( fTimeKey );
 
    pd3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &matSpin );
 
    return S_OK;
}

In the real world, of course, your applications will do much more than apply a single rotation on a single model. (For more information rotation matrices, see Rotation in the 3-D Transformations section.)

After you update the geometry in the scene, you can render it to the render target surface, as the Triangle sample does in Step 5.2: Render the Scene.