Advertisement
ProzacR

3d vector rotation

May 15th, 2013
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. void CVector3D::Rotate(double rotx, double roty, double rotz)
  2.     {
  3.     CVector3D result(x, y, z);
  4.  
  5.     if (rotx)
  6.         {
  7.                 result.y += (double)(y*cos(rotx) - z*sin(rotx));
  8.         result.z += (double)(y*sin(rotx) + z*cos(rotx));
  9.         }
  10.     if (roty)
  11.         {
  12.         result.x += (double)(x*cos(roty) + z*sin(roty));
  13.         result.z += (double)(- x*sin(roty) + z*cos(roty));
  14.         }
  15.     if (rotz)
  16.         {
  17.         result.x += (double)(x*cos(rotz) - y*sin(rotz));
  18.         result.y += (double)(x*sin(rotz) + y*cos(rotz));
  19.         }
  20.  
  21.     *this = result;
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement