SHARE
TWEET

Untitled

a guest Sep 19th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local QuatEpsError = 1E-2
  2.  
  3.  
  4. function SurfaceNormalToRightHanded(normal, camera)
  5.     local rotation
  6.     if math.approx(math.abs(normal.z), 1.0, QuatEpsError) then
  7.         rotation = Quaternion.LookRotation(normal, vector3.right)
  8.     else
  9.         rotation = Quaternion.LookRotation(normal, vector3.up)
  10.     end
  11.  
  12.     --[[
  13.         The surface is roughly upwards/downwards, rotate the marker in such a
  14.         way that it faces towards the specified camera.
  15.     --]]
  16.     if camera and math.approx(math.abs(normal.z), 1.0, QuatEpsError) then
  17.         local offset = math.sign(normal.z) * (camera:Rotation().z - Quaternion.ToEuler(rotation).z)
  18.         rotation = rotation * Quaternion.Euler(0.0, 0.0, offset)
  19.     elseif math.approx(normal.y, 1.0, QuatEpsError) then
  20.         rotation = rotation * Quaternion.Euler(0.0, 180.0, 0.0)
  21.     end
  22.     return rotation
  23. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top