Here is our replacement for D3DXMatrixScaling:
// Procedure: dhMatrixScaling
// Whazzit:Prepares a Matrix to scale an object along the X, Y, and Z axis.
D3DXMATRIX *dhMatrixScaling(D3DXMATRIX *pOut, float sx,float sy, float sz){
pOut->_11 = sx; pOut->_12 = 0.0f; pOut->_13 = 0.0f; pOut->_14 = 0.0f;
pOut->_21 = 0.0f; pOut->_22 = sy; pOut->_23 = 0.0f; pOut->_24 = 0.0f;
pOut->_31 = 0.0f; pOut->_32 = 0.0f; pOut->_33 = sz; pOut->_34 = 0.0f;
pOut->_41 = 0.0f; pOut->_42 = 0.0f; pOut->_43 = 0.0f; pOut->_44 = 1.0f;
return pOut;
}
Here is our new render() function:
// Function: render
// Whazzit:Draws a triangle and then presents the results.
void render(void){
D3DXMATRIX matWorld;
D3DXMATRIX trans_matrix; //Our translation matrix
D3DXMATRIX scale_matrix;
//Clear the buffer to our new colour.
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
//Notify the device that we're ready to render
if(SUCCEEDED(g_d3d_device->BeginScene())){
//Vertex shaders are a complex topic, but you can do some amazing things with them
//For this example we're not creating one, so we tell Direct3D that we're just
//using a plain vertex format.
g_d3d_device->SetVertexShader(D3D8T_CUSTOMVERTEX);
//D3D's rendering functions read from streams. Here we tell D3D that the
//VB we created for our triangle is the stream it should read from.
g_d3d_device->SetStreamSource(0,g_vb,sizeof(my_vertex));
//Big triangle off to the right
dhMatrixScaling(&scale_matrix,2.0f,2.0f,2.0f);
D3DXMatrixTranslation(&trans_matrix,2.0,0.0f,0.0f);
D3DXMatrixMultiply(&matWorld,&scale_matrix,&trans_matrix);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
//Small triangle off to the left
dhMatrixScaling(&scale_matrix,0.5f,0.5f,0.5f);
D3DXMatrixTranslation(&trans_matrix,-2.0,0.0f,0.0f);
D3DXMatrixMultiply(&matWorld,&scale_matrix,&trans_matrix);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
//Normal triangle in the center
D3DXMatrixIdentity(&matWorld);
g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );
g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
//Notify the device that we're finished rendering for this frame
g_d3d_device->EndScene();
}
//Show the results
g_d3d_device->Present( NULL, NULL, NULL, NULL );
}
|