Ckef01

Node rotation via quaternions

Aug 7th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. //-----------------------------------------------------------------------
  2. void Node::rotate(const quaternion &quat, const TransformSpace::TransformSpace &space)
  3. {
  4.     // Skip if no rotation
  5.     if(quat == quaternion::IDENTITY) return;
  6.  
  7.         // Apply in correct space
  8.     switch(space)
  9.     {
  10.         // Frist rotate, then apply current
  11.         case TransformSpace::LOCAL :
  12.                 _orientation *= quat;
  13.                 break;
  14.  
  15.             // First apply current, then rotate
  16.             case TransformSpace::PARENT :
  17.                 _orientation = quat * _orientation;
  18.                 break;
  19.     }
  20.  
  21.     // Normalize quaternion
  22.     _orientation = _orientation.normalize();
  23.  
  24.     // Set update flag
  25.     _update = true;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment