D3D translation issues in a orthogonal matrix

Started by
1 comment, last by Namethatnobodyelsetook 15 years, 10 months ago
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]
Advertisement
Found the problem, was mistakenly translating twice. :)
Just to stop the next thread before it starts. A Z near of 0 will effectively disable the Z buffer. Set a Z near of 1, and far of 21, then move your view matrix back 1 unit to -1... it's effectively the same thing, and will render anything from Z 0 to 20, but your Z buffer will work.

This topic is closed to new replies.

Advertisement