DavidNorgren

Untitled

May 28th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1.  
  2.     // Rotates the vector around another vector by a given angle.
  3.     void rotate(vec3 around, float angle) {
  4.         // http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/
  5.         float u, v, w, d, c, ci, s;
  6.         vec3 newVector(0, 0, 0);
  7.         u = around.x;
  8.         v = around.y;
  9.         w = around.z;
  10.         d = x * around.x + y * around.y + z * around.z;
  11.         c = dcos(angle); ci = 1 - c;
  12.         s = dsin(angle);
  13.         newVector = vec3(
  14.             u * d * ci + x * c + (-w * y + v * z) * s,
  15.             v * d * ci + y * c + (w * x - u * z) * s,
  16.             w * d * ci + z * c + (-v * x + u * y) * s
  17.         );
  18.         x = newVector.x;
  19.         y = newVector.y;
  20.         z = newVector.z;
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment