Jump to content
  • Advertisement
Sign in to follow this  
nitzan

D3D translation issues in a orthogonal matrix

This topic is 3656 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

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!