SHARE
TWEET

Untitled

a guest Sep 19th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top