Rotating Objects Around Origin (d3d)

Started by
0 comments, last by Spartacus 22 years, 10 months ago
Hi! How can i rotate my the objects in the scene around the origin? I have drawed a pyramide to the screen like this:
    
{
	D3DXMatrixTranslation(&matrix1, 0, 0, 10.0);	
	pD3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&matrix1);

	D3DXMatrixRotationX(&matrix1, rotationAngleX);
	D3DXMatrixRotationY(&matrix2, rotationAngleY);
	D3DXMatrixMultiply(&matrix1, &matrix1, &matrix2);
	D3DXMatrixRotationZ(&matrix2, rotationAngleZ);
	D3DXMatrixMultiply(&matrix1, &matrix1, &matrix2);
	pD3DDevice->SetTransform(D3DTS_WORLD, &matrix1);

	pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);	

	pD3DDevice->BeginScene();
	{
		pD3DDevice->SetVertexShader(D3DFVF_vertex);

		pD3DDevice->SetStreamSource(0, pD3DVBClosedCylinder, sizeof(vertex));
		pD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 4);
}
}
pD3DDevice->EndScene();
    
but the pyramid is not rotating around the origin but around it's own center. -Thanks Edited by - Spartacus on June 21, 2001 1:06:22 PM

Real programmers don't document, if it was hard to write it should be hard to understand

Advertisement
1: Remove the Second line completely. ("pD3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&matrix1);")
2: Change "D3DXMatrixRotationX(&matrix1, rotationAngleX);" to "D3DXMatrixRotationX(&matrix2, rotationAngleX);"
3: Add "D3DXMatrixMultiply(&matrix1, &matrix1, &matrix2);" after the line you added in step 2.

The problem you are having is that you are applying the translation matrix(to the wrong place, no less (D3DTS_VIEW should have been _WORLD)), then creating the rotatoin matricies, and overwriting the translation you had already set. You have to multiply the translation and the rotations together, and then set them to the World transform.

Z.
______________"Evil is Loud"

This topic is closed to new replies.

Advertisement