Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. def look_at(u, v):
  2. u.normalize()
  3. v.normalize()
  4. dot = u.dot(v)
  5. cross = u.cross(v)
  6. q = mathutils.Quaternion()
  7. q.x = cross.x
  8. q.y = cross.y
  9. q.z = cross.z
  10. q.w = math.sqrt(u.length_squared*v.length_squared) + dot
  11. q.normalize()
  12. print(q)
  13. return q
  14.  
  15. def look_at(u, v):
  16. u.normalize()
  17. v.normalize()
  18. dot = u.dot(v)
  19. cross = u.cross(v)
  20. q = mathutils.Quaternion()
  21.  
  22. if dot >= 1.0:
  23. print("Case 1")
  24. return q.identity()
  25. elif dot < 0.000001 - 1.0:
  26. print("Case 2")
  27. else:
  28. print("Case 3")
  29. s = math.sqrt((1+dot)*2)
  30. invis = 1/s
  31. q.x = cross.x * invis
  32. q.y = cross.x * invis
  33. q.z = cross.x * invis
  34. q.w = s * 0.5
  35. q.normalize()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement