The only change we need to make to the code given in Lesson3 is in the render() function.
I've included the whole function, with changes marked in red.
void render(void){
D3DXMATRIX matWorld;
D3DXMATRIX rot_matrix; //Our rotation matrix
D3DXMATRIX trans_matrix; //Our translation matrix
static float rot_triangle=0; //Tracks rotation for our triangle
static float rot_square=0; //Tracks rotation for our square
rot_triangle+=0.004f;
rot_square+=0.007f;
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
if(SUCCEEDED(g_d3d_device->BeginScene())){
g_d3d_device->SetVertexShader(D3D8T_CUSTOMVERTEX);
g_d3d_device->SetStreamSource(0,g_vb,sizeof(my_vertex));
//Set up the rotation matrix for the triangle
D3DXMatrixRotationX(&rot_matrix,rot_triangle);
//Translate (move) it 1 unit to the left
D3DXMatrixTranslation(&trans_matrix,-1.0,0.0f,0.0f);
//Combine the 2 matrices to get our final World Matrix
D3DXMatrixMultiply(&matWorld,&rot_matrix,&trans_matrix);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
//Set up the rotation matrix for the square
D3DXMatrixRotationY(&rot_matrix,rot_square);
//Set up the World Matrix for the square
D3DXMatrixTranslation(&trans_matrix,1.0,0.0f,0.0f);
//Combine the 2 matrices to get our final World Matrix
D3DXMatrixMultiply(&matWorld,&rot_matrix,&trans_matrix);
g_d3d_device->SetTransform( D3DTS_WORLD, &matWorld );
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP,3,2);
g_d3d_device->EndScene();
}
g_d3d_device->Present( NULL, NULL, NULL, NULL );
}
|