Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SurfaceNormalToRightHanded(camera, normal)
- local rotation
- if math.approx(math.abs(normal.z), 1.0, QuatEpsError) then
- rotation = Quaternion.LookRotation(normal, vector3.right)
- else
- rotation = Quaternion.LookRotation(normal, vector3.up)
- end
- --[[
- The surface is roughly upwards/downwards, rotate the marker in such a
- way that it faces towards the specified camera.
- --]]
- if camera and math.approx(math.abs(normal.z), 1.0, QuatEpsError) then
- local offset = math.sign(normal.z) * (camera:Rotation().z - Quaternion.ToEuler(rotation).z)
- rotation = rotation * Quaternion.Euler(0.0, 0.0, offset)
- elseif math.approx(normal.y, 1.0, QuatEpsError) then
- rotation = rotation * Quaternion.Euler(0.0, 180.0, 0.0)
- end
- return rotation
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement