Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. function SurfaceNormalToRightHanded(camera, normal)
  2. local rotation
  3. if math.approx(math.abs(normal.z), 1.0, QuatEpsError) then
  4. rotation = Quaternion.LookRotation(normal, vector3.right)
  5. else
  6. rotation = Quaternion.LookRotation(normal, vector3.up)
  7. end
  8.  
  9. --[[
  10. The surface is roughly upwards/downwards, rotate the marker in such a
  11. way that it faces towards the specified camera.
  12. --]]
  13. if camera and math.approx(math.abs(normal.z), 1.0, QuatEpsError) then
  14. local offset = math.sign(normal.z) * (camera:Rotation().z - Quaternion.ToEuler(rotation).z)
  15. rotation = rotation * Quaternion.Euler(0.0, 0.0, offset)
  16. elseif math.approx(normal.y, 1.0, QuatEpsError) then
  17. rotation = rotation * Quaternion.Euler(0.0, 180.0, 0.0)
  18. end
  19. return rotation
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement