a problem with rotation for my game , DX

Started by
2 comments, last by Anddos 15 years, 5 months ago
ok i am still learning DX but i am making a game based on the CreateTeapot meshs i have rendered 2 meshs to screen and set mesh teapot -10 z on that axis what i do next is use Vec3Add to find the distance from teapot1 to teapot2 now i have the distance which is -10.0f , but what i am want todo is give the teapot some AI so it will rotate to the teapots 1 postion but if i put SetTransform Trans * Rot , the mesh decides to rot in a big circle and i just want it to rotate to the postion the other teapot is facing , ive tried many things with SetTransform and if i try with just rot then i cant postion it at -10.0f , ive heard if you call transform on the same matrix it overwrites it , so i how do i place the teampot -10.0f on z axis as well as rotate depending on what the ADD.z returns, i can do a diagram if you need one
:)
Advertisement
Rotation is always around the origin. If you just want the object to "spin", rotate before you move it away from the origin.
Rotate the teapot first, and then translate.

In matrix multiplication, order matters. If you translated first, and then rotated, the teapot will move in a big circle because you're always rotating around the origin after translating it.

But, if you rotate first and then translate, then the teapot will change it's facing first and then move into the new location.

If you keep in mind you're doing everything with respect to the origin, and order matters, you'll be fine. It takes a while to "get it" though, and it's tricky to visualize the first time around.
hey thanks alot , so i understand is

d3ddev->SetTransform(D3DTS_WORLD , &(rot *TeapotMatrix2));

what ever order that is in it has to be in the same order in code

rotation then translation

now what i need todo is work out the current angle the teapot is at and rotate to face the other teapot ,

D3DXVECTOR3 vec3Add;
D3DXVec3Add(&vec3Add,&Teapot1Controls , &Teapot2Controls);
sprintf(gbuffer,"%s %f\n" , "vec3Add.z", vec3Add.z); //backbuffer desc
WriteConsole(Console , gbuffer, strlen(gbuffer),NULL,NULL); //output mouse

if(vec3Add.z < -10.0f)
{
sprintf(gbuffer,"%s\n" , "less"); //backbuffer desc
WriteConsole(Console , gbuffer, strlen(gbuffer),NULL,NULL); //output mouse
rotate = 6.0f; //i need to find the exact value to rotate to :D
}
else
{
rotate = 0.0f;
}


[Edited by - Anddos on November 14, 2008 5:19:29 AM]
:)

This topic is closed to new replies.

Advertisement