Contact Me

In Association with
In Association with

$5 via PayPal

Translations without D3DX

Translations without D3DX
Here is our replacement for D3DXMatrixTranslation:
// Procedure: dhMatrixTranslation
// Whazzit:Given x,y,z produces a matrx to perform the appropriate translation
D3DXMATRIX *dhMatrixTranslation(D3DXMATRIX *pOut,float x,float y,float z){

   pOut->_11 = 1.0f;    pOut->_12 = 0.0f;    pOut->_13 = 0.0f;    pOut->_14 = 0.0f;
   pOut->_21 = 0.0f;    pOut->_22 = 1.0f;    pOut->_23 = 0.0f;    pOut->_24 = 0.0f;
   pOut->_31 = 0.0f;    pOut->_32 = 0.0f;    pOut->_33 = 1.0f;    pOut->_34 = 0.0f;
   pOut->_41 = x;       pOut->_42 = y;       pOut->_43 = z;       pOut->_44 = 1.0f;

   return pOut;

Here is our new render() function which shows that our function produces results identical to the D3DX version. The important bits are in red:
void render(void){
D3DXMATRIX matWorld;

   //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

      //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.

      //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.

      //Set up the translation matrix (move it over to the left a bit)

      //Set our World Matrix
      g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );

      //After all that setup, actually drawing the triangle is pretty easy.
      //We tell it what we're giving it (a Triangle List), where it should
      //start reading (0, the beginning), and how many triangles we're drawing(1)

      //Move this one a bit to the right

      g_d3d_device->SetTransform(D3DTS_WORLD,&matWorld );


      //Notify the device that we're finished rendering for this frame

   //Show the results
   g_d3d_device->Present( NULL, NULL, NULL, NULL );