Jump to content

  • Log In with Google      Sign In   
  • Create Account


Rotation in a sub node.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 cathode26   Members   -  Reputation: 134

Like
0Likes
Like

Posted 03 May 2013 - 03:40 PM

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.

 

 

 



Sponsor:

#2 cathode26   Members   -  Reputation: 134

Like
0Likes
Like

Posted 03 May 2013 - 04:24 PM

This is the code I tried to use for the world rotation of the sub nodes but this gives similar results to the parent code,  but worse because there is eventually some distortion and my axes eventually stops being world for the child node when the parent has not even been rotated.  

 

D3DXMATRIX worldRotation(*(node->rn_worldMatrix));
D3DXMATRIX worldTranslation; D3DXMatrixIdentity(&worldTranslation);
worldTranslation(3,0) = worldRotation(3,0);  
worldTranslation(3,1) = worldRotation(3,1);  
worldTranslation(3,2) = worldRotation(3,2);

worldRotation(3,0) = 0;  
worldRotation(3,1) = 0;  
worldRotation(3,2) = 0;

D3DXMATRIX worldTransformation = rotationMat*worldRotation*worldTranslation;

//I need to convert it to local

FLOAT determinant;
D3DXMATRIX parentInverseWorld;
D3DXMatrixInverse(&parentInverseWorld, &determinant, &parentWorldTransform);

localTransformation = worldTransformation*parentInverseWorld;

 

 

I also tried changing the coordinate space of the rotation into the local coordinate space and applying the rotation there.  With similar results, I can rotate the child in world space if the parent is not rotated.

 

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;

D3DXMATRIX deltaRotationLocal = rotationMat*parentInverseWorld;
localTransformation = localRotation*deltaRotationLocal*localTranslation;

Edited by cathode26, 03 May 2013 - 08:13 PM.


#3 cathode26   Members   -  Reputation: 134

Like
1Likes
Like

Posted 03 May 2013 - 08:11 PM

The actual solution...  I solved it..  This is how  you rotate properly in world space.  If you look closely I had switched the order of the multiplication during the calculation of the world transform.

 

D3DXMATRIX worldRotation(*(node->rn_worldMatrix));
D3DXMATRIX worldTranslation; D3DXMatrixIdentity(&worldTranslation);
worldTranslation(3,0) = worldRotation(3,0);  
worldTranslation(3,1) = worldRotation(3,1);  
worldTranslation(3,2) = worldRotation(3,2);

worldRotation(3,0) = 0;
worldRotation(3,1) = 0;
worldRotation(3,2) = 0;

D3DXMATRIX worldTransformation = worldRotation*rotationMat*worldTranslation;
localTransformation = worldTransformation*parentInverseWorld;

Edited by cathode26, 03 May 2013 - 08:14 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS