Why does the whole world translate instead of just the object?

66 Views Asked by At

I have not been able to translate my object alone, when I try to do that, the whole world would translate instead.

Anyone have any ideas why this is happening?

d3ddev->SetStreamSource(0, v_buffer[2], 0, sizeof(CUSTOMVERTEX));       
d3ddev->SetIndices(i_buffer[2]);                                        
d3ddev->SetTexture(0, texture[1]);

D3DXMATRIX matTranslate;
D3DXMatrixTranslation(&matTranslate, 30.0f, 0.0f, 30.0f);
d3ddev->SetTransform(D3DTS_WORLD, &matTranslate);
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12);
1

There are 1 best solutions below

0
megadan On

The D3D device acts as a state machine. Whenever you set some state on the device, like the world transform matrix, it will persist between multiple draw calls. After you draw your object, you must reset the world transform back to the identity matrix before drawing the rest of the scene to prevent it from being translated.

D3DXMATRIX matIdentity;
D3DXMatrixIdentity(&matIdentity);
d3ddev->SetTransform(D3DTS_WORLD, &matIdentity);