hi i have some problems to correctly rotate a cube to the other.
i have one cube that i can move and i need the other cube to rotate in his direction when its moving
when run program, the cube rotates some in the dircection but when i go behind or under it changes direction.
i think it has somthing to do whit the direction of the cube ,or the angle or the rotation direction
this is the code dat i update:
translationform1 =XMVectorSet (xaxis1, 0.0f, zaxis1,0.0f);
cube1transform = XMVectorSet(3.0f, 0.0f, 4.5f, 0.0f);
cube2transform = XMVectorSet(-5.0f , 0.0f, 4.5f, 0.0f);
directioncube = cube1transform - cube2transform;
cubetranslation1 = D3DXVECTOR3(xaxis1, 0.0f, zaxis1);
cubelocation1 = D3DXVECTOR3(3.0f, 0.0f, 4.5f);
cube2position = D3DXVECTOR3(-5.0f, 0.0f, 4.5f);
cubeposition = cube1transform + translationform1;
cubepos1 = cubelocation1 + cubetranslation1;
cubeoldpos = cubepos1 - cubetranslation1;
*//direction2=0.0f,0.0f,1.0f)
direction2 = direction2; // i also tried cubeoldposition-cube2position "to get the new direction whit eache update"..
direction1 = cubepos1 - cube2position;
D3DXVec3Normalize(&direction2Norm, &direction2);
D3DXVec3Normalize(&direction1Norm, &direction1);
directioncubeNorm = XMVector3Normalize(directioncube);
renderrotate = D3DXVec3Dot(&direction1Norm, &direction2Norm);
dot = renderrotate;
renderrotate = (acos(renderrotate));
if (dot < 0)
renderrotate *=-1;
else
renderrotate *=1;
rotation = XMMatrixRotationY(renderrotate);
translation1 = XMMatrixTranslationFromVector(cubeposition);
cubeworld1 = translation1;
forwardcube = cube2transform + directioncubeNorm ;
translation2 = XMMatrixTranslation(-5.0f,0.0f,4.5f);
cubeworld2 = rotation*translation2;