• Advertisement

Archived

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

Rotating Objects Around Origin (d3d)

This topic is 6086 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! 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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement