Jump to content
  • Advertisement
Sign in to follow this  

Problems with DirectX Matrices

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

I am running an exercise after a one of the tutorials on directxtutorial.com. It's asking me to rotate and translate a triangle while having the camera follow it. I have it set up so that the camera follows the motion of the triangle, however it won't combine the rotation and the translation.
void render_frame(void)
	static float index = 0.0f; index += 0.05f;

	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);



	D3DXMATRIX matTranslateY;
	D3DXMATRIX matRotateY;

	D3DXMatrixTranslation(&matTranslateY, NULL, index, NULL);
	D3DXMatrixRotationY(&matRotateY, index);

	d3ddev->SetTransform(D3DTS_WORLD, &matRotateY);
	d3ddev->SetTransform(D3DTS_WORLD, &matTranslateY);

	D3DXMATRIX matView;

		&D3DXVECTOR3 (0.0f, 0.0f, 10.0f),    // the camera position
		&D3DXVECTOR3 (0.0f, index, 0.0f),   // the look-at position
		&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction

	d3ddev->SetTransform(D3DTS_VIEW, &matView);

	D3DXMATRIX matProjection;

		D3DXToRadian(45),    // the horizontal field of view
		1.0f,    // the near view-plane
		100.0f);    // the far view-plane

	d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);

	// select which vertex format we are using

	// select the vertex buffer to display
	d3ddev->SetStreamSource(0, t_buffer, 0, sizeof(CUSTOMVERTEX));

	// copy the vertex buffer to the back buffer
	d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);


	d3ddev->Present(NULL, NULL, NULL, NULL);


Share this post

Link to post
Share on other sites
You need to multiply matrices in order to concatenate the transformations they represent. With Direct3D the transformations will be applied in the left-to-right order that the matrices are multiplied. So rotation * translation will rotate the triangle first, then translate it (which is probably what you want).

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!