Advertisement
Guest User

Untitled

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