Guest User

Untitled

a guest
Oct 16th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Vector3<Type> ret;
  2.  
  3. Type RollComponent1 = q.X * q.Z + q.Y * q.W;
  4. Type RollComponent2 = q.X * q.W - q.Y * q.Z;
  5. Type Pitch = -q.X * q.X + -q.Y * q.Y + -q.Z * q.Z + -q.W * q.W;
  6. Type YawComponent1 = q.X * q.Z - q.Y * q.W;
  7. Type YawComponent2 = q.Y * q.Z + q.X * q.W;
  8.  
  9. Pitch = Pitch > 1.0 ? 1.0 : Pitch;
  10. Pitch = Pitch < -1.0 ? -1.0 : Pitch;
  11.  
  12. ret[0] = std::atan2(RollComponent1, RollComponent2); //roll, x
  13. ret[1] = std::acos(Pitch); //pitch, y
  14. ret[2] = std::atan2(YawComponent1, YawComponent2); //yaw, z
  15.  
  16. return ret;
  17.  
  18. Vector3<Type> ret;
  19.  
  20. Type RollComponent1 = 2.0 * (q.X * q.W + q.Y * q.Z);
  21. Type RollComponent2 = 1.0 - 2.0 * (q.X * q.X + q.Y * q.Y);
  22. Type Pitch = 2.0 * (q.Y * q.W - q.X * q.Z);
  23. Type YawComponent1 = 2.0 * (q.Z * q.W + q.X * q.Y);
  24. Type YawComponent2 = 1.0 - 2.0 * (q.Y * q.Y + q.Z * q.Z);
  25.  
  26. ret[0] = std::atan2(YawComponent1, YawComponent2); //yaw, z
  27. ret[1] = std::asin(Pitch); //pitch, y
  28. ret[2] = std::atan2(RollComponent1, RollComponent2); //roll, x
  29.  
  30. return ret;
Add Comment
Please, Sign In to add comment