Advertisement
Guest User

Untitled

a guest
Aug 11th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.62 KB | None | 0 0
  1. $Z_EPSILON = 1      ; точность, достигая которую, прекращаем поиск
  2. $MAX_PROBES = 16    ; сюда пишем достаточное число шагов: 2 в степени $MAX_PROBES должно получить не больше $zFar - $zNear
  3.  
  4.     $searchedPoint = 28251      ;; Что ищем?
  5.  
  6. $zNear = 0
  7. $zFar = 65535
  8.  
  9. $probeCount = 0
  10. $foundPoint = -1    ; -1 is not found
  11. $dir = 1
  12. $curPoint = $zNear
  13. $delta = ($zNear + $zFar) * 0.5
  14. While 1
  15.     $nextPoint = $curPoint + $dir * $delta
  16.  
  17.     $d = $nextPoint - $searchedPoint
  18.  
  19.     if abs($d) < $Z_EPSILON then
  20.         $foundPoint = $nextPoint
  21.         ExitLoop    ; Found it!
  22.     endif
  23.  
  24.     if $d > 0 then
  25.         $dir = -1
  26.     else
  27.         $dir = 1
  28.     endif
  29.  
  30.     $delta *= 0.5
  31. ;;;; Этого не произойдет, т.к. в буфере глубины значения между 0 и 1, нормализованные zNear и zFar.
  32. ;   if $delta < 1 then
  33. ;       $foundPoint = -1
  34. ;       ExitLoop    ; Delta is too small, but not found :(
  35. ;   endif
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37.  
  38.     $probeCount += 1
  39.     if $probeCount == $MAX_PROBES then
  40.         ExitLoop    ; Not found :(
  41.     endif
  42.  
  43.     $curPoint = $nextPoint
  44.  
  45. ;;  MSGBOX(64, '', 'nextPoint: ' & $nextPoint & @CRLF & 'd: ' & $d & @CRLF & 'dir: ' & -$dir & @CRLF & 'delta: ' & $delta)      ;; DEBUG STUFF
  46. Wend
  47.  
  48. if $foundPoint == -1 then
  49.     MSGBOX(64, 'Искали ' & $searchedPoint & ', не нашли', '    :(')
  50. else
  51.     MSGBOX(64, 'Искали ' & $searchedPoint & ', нашли: ' & $foundPoint, 'Число шагов: ' & $probeCount & @CRLF & 'Погрешность: ' & $d)
  52. endif
  53. EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement