Sign in to follow this  
Marusu

Direct3D XYZ

Recommended Posts

Marusu    138
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));

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Tom KQT    1704
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

Share this post


Link to post
Share on other sites
Marusu    138
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 ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this