Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rotates the vector around another vector by a given angle.
- void rotate(vec3 around, float angle) {
- // http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/
- float u, v, w, d, c, ci, s;
- vec3 newVector(0, 0, 0);
- u = around.x;
- v = around.y;
- w = around.z;
- d = x * around.x + y * around.y + z * around.z;
- c = dcos(angle); ci = 1 - c;
- s = dsin(angle);
- newVector = vec3(
- u * d * ci + x * c + (-w * y + v * z) * s,
- v * d * ci + y * c + (w * x - u * z) * s,
- w * d * ci + z * c + (-v * x + u * y) * s
- );
- x = newVector.x;
- y = newVector.y;
- z = newVector.z;
- }
Advertisement
Add Comment
Please, Sign In to add comment