Advertisement Jump to content
Sign in to follow this  

Translation Problem

This topic is 4984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working with vertex buffers in DX8 and the buffer is drawn however it is not translated when I set the world matrix for the device to a translated location. The code used for rendering is as follows:
void RenderWindow::RenderVertexBuffer( VertexBuffer *buffer, int firstVertex )
    mDevice->SetStreamSource( 0, buffer->mBuffer, buffer->mVertSize );
    mDevice->SetVertexShader( buffer->mFVF );
    if ( typeid( *buffer ) == typeid( Sprite ) )
      D3DXMATRIX matWorld;
      Sprite *sprite = (Sprite*)buffer;
      mRaster->setPosition( sprite->x, sprite->y, sprite->z );
      mRaster->setRotation( sprite->rx, sprite->ry, sprite->rz );
      mRaster->getWorldMatrix( &matWorld );
      mDevice->SetTransform( D3DTS_WORLD, &matWorld );
    mDevice->SetTexture( 0, LoadCreateTexture( buffer->getValue() )->DXTexture );
    mDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, buffer->mNumPolys );
    mDevice->SetStreamSource( 0, NULL, 0 );
    mDevice->SetTexture( 0, NULL );
And the function call made to acquire the world matrix is defined as:
void Raster::getWorldMatrix( D3DXMATRIX *matrix )
    D3DXMATRIX matWorld;
    D3DXMATRIX matTranslate;
    D3DXMATRIX matRotx;
    D3DXMATRIX matRoty;
    D3DXMATRIX matRotz;
    D3DXMatrixIdentity( &matWorld );
    D3DXMatrixTranslation( &matTranslate, mX, mY, mZ );
    D3DXMatrixRotationX( &matRotx, mRotx );
    D3DXMatrixRotationX( &matRoty, mRoty );
    D3DXMatrixRotationX( &matRotz, mRotz );
    D3DXMatrixMultiply( &matWorld, &matWorld, &matRotx );
    D3DXMatrixMultiply( &matWorld, &matWorld, &matRoty );
    D3DXMatrixMultiply( &matWorld, &matWorld, &matRotz );
    D3DXMatrixMultiply( &matWorld, &matWorld, &matTranslate );
    *matrix = matWorld;

Share this post

Link to post
Share on other sites
Are you sure the buffer is in fact a Sprite -- because you set the world matrix only when the typeid's match; otherwise nothing is set for a world matrix.



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!