I am making a tool that rotates a model. This tool needs to not care which direction the model is facing. It just needs to rotate on world coordinate. Like a rotate tool you would use in 3d studio max. The problem comes up after the parent node has been rotated. When the parent is not aligned with the world the children rotate on a different axis.
Rotating the parent is fine. Rotating just the child is fine.
But if the parent is not on the identity for the axis then the child is rotated incorrectly.
This is the code I use on the parent.
if(dz == 0 && dy == 0)
D3DXMatrixRotationX(&rotationMat, D3DXToRadian(node->rn_eulerOffset->x));
else if(dx == 0 && dz == 0)
D3DXMatrixRotationY(&rotationMat, D3DXToRadian(node->rn_eulerOffset->y));
else if(dx == 0 && dy == 0)
D3DXMatrixRotationZ(&rotationMat, D3DXToRadian(node->rn_eulerOffset->z));
if(node->parent == NULL)
{
D3DXMATRIX localRotation(*node->rn_matrix);
D3DXMATRIX localTranslation;
D3DXMatrixIdentity(&localTranslation);
localTranslation(3,0) = localRotation(3,0);
localTranslation(3,1) = localRotation(3,1);
localTranslation(3,2) = localRotation(3,2);
localRotation(3,0) = 0;
localRotation(3,1) = 0;
localRotation(3,2) = 0;
localTransformation = localRotation*rotationMat*localTranslation;
}
I tried to remove the parent rotation from the child before rotating and to use world space but I didnt have much luck.
Thanks ahead of time for any help.