Hi,
I have a weird issue while translating polygons in my program.
I set the view as follows:
inline void View2D() {
D3DXMATRIX matOrtho;
D3DXMATRIX matIdentity;
//Setup the orthogonal projection matrix and the default world/view matrix
D3DXMatrixOrthoLH(&matOrtho, (float)g_width, (float)g_height, 0.0f, 20.0f);
D3DXMatrixIdentity(&matIdentity);
D3DXMatrixIdentity(&g_d3dWorldMatrix);
g_d3dDevice->SetTransform(D3DTS_PROJECTION, &matOrtho);
g_d3dDevice->SetTransform(D3DTS_WORLD, &g_d3dWorldMatrix);
g_d3dDevice->SetTransform(D3DTS_VIEW, &matIdentity);
//Make sure that the z-buffer and lighting are disabled
g_d3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
g_d3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
}
But when I translate one of my polygons, it moves twice as far as it should. So if I want an object which is at the origin to move to a location 256 pixel to the right, I need to translate it by 128 instead of 256.
inline void D3DTranslate(float x, float y, float z) {
D3DXMATRIX translationMatrix;
D3DXMatrixTranslation(&translationMatrix, x, y, z);
D3DXMatrixMultiply(&g_d3dWorldMatrix, &translationMatrix, &g_d3dWorldMatrix);
D3DSetWorldMatrix();
}
inline
void D3DSetWorldMatrix()
{
g_d3dDevice->SetTransform(D3DTS_WORLD, &g_d3dWorldMatrix);
}
Can anyone help me out as to why this is happening?
Thanks.
[Edited by - nitzan on June 20, 2008 1:19:55 AM]