Archived

This topic is now archived and is closed to further replies.

IFooBar

i need help dith d3d matrix stacks

Recommended Posts

hi i am trying to use the ID3DXMatrixStack interface, but im doing something wrong and i dunno what. heres what im doing
  
//create teh thing like this and set an identity matrix

//this happens in initialization

if(FAILED(D3DXCreateMatrixStack(0, &m_pMatrixStack)))
   return FALSE;
m_pMatrixStack->LoadIdentity();

//This is what me render code looks like

D3DXMatrixRotationX(&matX, timeGetTime()/2000.0f);
D3DXMatrixRotationY(&matY, timeGetTime()/2000.0f);	
D3DXMatrixRotationZ(&matZ, timeGetTime()/2000.0f);	
D3DXMatrixTranslation(&matT, 0.0f, 0.0f, 0.0f);

m_worldMat = matT * matY * matY * matZ;
m_pMatrixStack->LoadMatrix(&m_worldMat);
Draw();
m_d3d.getD3DDevice()->SetTransform(D3DTS_WORLD, m_pMatrixStack->GetTop());

m_pMatrixStack->Push();
m_pMatrixStack->TranslateLocal(1.0f, 0.0f, 0.0f);
Draw();
m_d3d.getD3DDevice()->SetTransform(D3DTS_WORLD, m_pMatrixStack->GetTop());

m_pMatrixStack->Pop();
m_pMatrixStack->LoadIdentity();
  
the first square renders ok, but the second one is no where around. and the first one flickers when i try to render the second one. am i doing something wrong? thanks for any help
"I know sometimes I ask stupid questions...but i mean well " [Triple Buffer-My home]|[SCRIPTaGAME]|[My Old Site]

Share this post


Link to post
Share on other sites
Yo..For some reason it seems to me that your are not in the rihgt backbuffer format. Make sure you swap the front and back buffers, that''s what usually causes flickering.

//this is during initialization
d3dpp.BackBufferFormat=d3dmm.Format; //set the right backbuffer

// this is in last lines of render()
if(FAILED(g_pD3DDevice->Present(NULL, NULL, NULL, NULL)))
//error

Share this post


Link to post
Share on other sites
I am swapping teh buffers. if i wasnt swapping, then the screen would never update. the screen is updating.

The flickering is happening because of the second square im rendering. it dosnt flicker unless i render teh second square. my best guess is that the second square is being rendered in the exact position as the first, that causes the flickering.

the thing is that it shouldnt be in the same posityion, because i pushed a translation matrix on the stack, so it should inherit the first quads transformations, and be translated 2 units along the x axis, but it''s not working.

I just made my own d3dstack interface thingy, it kinda works. my new render code is like this.


  
D3DXMATRIX matT, matX, matY, matZ;
m_d3d.enableCulling(0);

//draw the front

D3DXMatrixRotationX(&matX, timeGetTime()/2000.0f);
D3DXMatrixRotationY(&matY, timeGetTime()/2000.0f);
D3DXMatrixRotationZ(&matZ, timeGetTime()/2000.0f);

m_worldMat = matY * matY * matZ;
m_stack.loadMatrix(m_worldMat);
Draw();
m_d3d.getD3DDevice()->SetTransform(D3DTS_WORLD, &m_stack.getCurrent());

D3DXMatrixTranslation(&matT, 2.0f, 0.0f, 0.0f);
m_worldMat = matT * m_stack.getCurrent();
m_stack.pushL(matT);
Draw();
m_d3d.getD3DDevice()->SetTransform(D3DTS_WORLD, &m_stack.getCurrent());

m_stack.popAll();


so i made my own stack thing and it works, but the funny thing is that if I comment out this line

m_worldMat = matT * m_stack.getCurrent();

then it dosnt work again. same flickering problem. the whole point of the stack is so i dont have to keep track of the world matrix. now why is it that this only works if i do the stack multiplation, and the world matrix multiplication? (im talking about the stuff before the second Draw() call



"I know sometimes I ask stupid questions...but i mean well "
[Triple Buffer-My home]|[SCRIPTaGAME]|[My Old Site]

Share this post


Link to post
Share on other sites