Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Z_EPSILON = 1 ; точность, достигая которую, прекращаем поиск
- $MAX_PROBES = 16 ; сюда пишем достаточное число шагов: 2 в степени $MAX_PROBES должно получить не больше $zFar - $zNear
- $searchedPoint = 28251 ;; Что ищем?
- $zNear = 0
- $zFar = 65535
- $probeCount = 0
- $foundPoint = -1 ; -1 is not found
- $dir = 1
- $curPoint = $zNear
- $delta = ($zNear + $zFar) * 0.5
- While 1
- $nextPoint = $curPoint + $dir * $delta
- $d = $nextPoint - $searchedPoint
- if abs($d) < $Z_EPSILON then
- $foundPoint = $nextPoint
- ExitLoop ; Found it!
- endif
- if $d > 0 then
- $dir = -1
- else
- $dir = 1
- endif
- $delta *= 0.5
- ;;;; Этого не произойдет, т.к. в буфере глубины значения между 0 и 1, нормализованные zNear и zFar.
- ; if $delta < 1 then
- ; $foundPoint = -1
- ; ExitLoop ; Delta is too small, but not found :(
- ; endif
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- $probeCount += 1
- if $probeCount == $MAX_PROBES then
- ExitLoop ; Not found :(
- endif
- $curPoint = $nextPoint
- ;; MSGBOX(64, '', 'nextPoint: ' & $nextPoint & @CRLF & 'd: ' & $d & @CRLF & 'dir: ' & -$dir & @CRLF & 'delta: ' & $delta) ;; DEBUG STUFF
- Wend
- if $foundPoint == -1 then
- MSGBOX(64, 'Искали ' & $searchedPoint & ', не нашли', ' :(')
- else
- MSGBOX(64, 'Искали ' & $searchedPoint & ', нашли: ' & $foundPoint, 'Число шагов: ' & $probeCount & @CRLF & 'Погрешность: ' & $d)
- endif
- EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement