Direct3D XYZ

Started by
3 comments, last by Marusu 13 years, 11 months ago
Hi, I'm experiencing some problems with coordinate system. I've loaded mesh. When I move it left by writing: D3DXMatrixTranslation(&translateA, -100.0f, 1.0f, 0.0f); it goes right. What I might be doing wrong? Another problem is with rotating, when I place mesh somewhere far from center on x axis and make it rotate, it rotates around 0;0;0. What function should I use to make it spin around it's own center instead of center of coordinate system?

	static float index = 0.0f; index += 0.01f;
	D3DXMATRIX translateA;
	D3DXMatrixTranslation(&translateA, 0.0f, 1.0f 0.0f);
	D3DXMATRIX rotate;
	D3DXMatrixRotationY(&rotate, index);
	m_lpd3dDevice->SetTransform(D3DTS_WORLD, &(translateA * rotate));

Advertisement
Do rotation before translation. That way object will rotate around its center instead of world center. As for D3DXMatrixTranslation(&translateA, -100.0f, 1.0f, 0.0f); part of the code, this will place your mesh on -100, 1, 0 coordinate in your world space, it will not "move" it -100 along x axis each time you do this translation.
Regarding your first question, what is your camera? Think about it: an object might always move in the same direction, but depending on where you're standing, it will look as if it's moving to the left, right, forward, back, etc. So make sure your camera is where you expect the object to move to the left.
Quote:Original post by SIIYA
Do rotation before translation.

Which means you just have to swap the matrices in the multiplication, so replace
translateA * rotate
with
rotate * translateA
Thank you.
Now I finally understand why one page stated that "In Direct3D you must combine your matrix in SRT order (scale * rotation * translation)."
It also seems that I was using 200.0f in z axis instead of -200.0f, so camera was positioned behind the cube, not in front.
All rated as extremely helpful ;)

This topic is closed to new replies.

Advertisement