X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fz_aabbtree.pas;h=88c7b8862aee31067522d79fd922d20d980e8fb2;hb=6a553cae9dbb5171d17826cfd19dd0a0b7c0ed8c;hp=86e05680340dfa2af06d8c4fee175a4f48e80083;hpb=6eab64d006f1081bc5096507bb634928cadd6d66;p=d2df-sdl.git diff --git a/src/game/z_aabbtree.pas b/src/game/z_aabbtree.pas index 86e0568..88c7b88 100644 --- a/src/game/z_aabbtree.pas +++ b/src/game/z_aabbtree.pas @@ -235,7 +235,6 @@ type chkAABB: AABB2D; // for checkers qSRes: PSegmentQueryResult; // for queries // for segment query - maxFraction: Single; curax, curay: Single; curbx, curby: Single; dirx, diry: Single; @@ -319,7 +318,7 @@ type function aabbQuery (ax, ay, aw, ah: TreeNumber; cb: TQueryOverlapCB; tagmask: Integer=-1): TTreeFlesh; function pointQuery (ax, ay: TreeNumber; cb: TQueryOverlapCB; tagmask: Integer=-1): TTreeFlesh; - function segmentQuery (out qr: TSegmentQueryResult; ax, ay, bx, by: TreeNumber; cb: TSegQueryCallback; tagmask: Integer=-1): Boolean; + function segmentQuery (out qr: TSegmentQueryResult; const ax, ay, bx, by: TreeNumber; cb: TSegQueryCallback; tagmask: Integer=-1): Boolean; function computeTreeHeight (): Integer; // compute the height of the tree @@ -1680,8 +1679,7 @@ end; function TDynAABBTreeBase.checkerRay (node: PTreeNode): Boolean; -var - tmin: Single = 0; +//var tmin: Single = 0; begin {$IF FALSE} result := node.aabb.intersects(curax, curay, curbx, curby, @tmin); @@ -1696,7 +1694,10 @@ begin Integer(result), ]), MSG_NOTIFY); {$ELSE} - result := node.aabb.intersects(traceRay, maxFraction, @tmin); + result := false; + if (node.aabb.maxX < minSingle(curax, curbx)) or (node.aabb.maxY < minSingle(curay, curby)) then exit; + if (node.aabb.minX > maxSingle(curax, curbx)) or (node.aabb.minY > maxSingle(curay, curby)) then exit; + result := node.aabb.intersects(traceRay, qSRes.time{, @tmin}); { e_WriteLog(Format('intersect: (%f,%f)-(%f,%f) (%d,%d)-(%d,%d) tmin=%f res=%d frac=%f', [ curax, curay, curbx, curby, @@ -1704,7 +1705,7 @@ begin node.aabb.maxX, node.aabb.maxY, tmin, Integer(result), - maxFraction + qSRes.time ]), MSG_NOTIFY); } {$ENDIF} @@ -1733,9 +1734,8 @@ begin if (hitFraction > 0.0) then begin // we update the maxFraction value and the ray AABB using the new maximum fraction - if (hitFraction < maxFraction) then + if (hitFraction < qSRes.time) then begin - maxFraction := hitFraction; qSRes.time := hitFraction; qSRes.flesh := flesh; // fix curb here @@ -1749,9 +1749,8 @@ end; // segment querying method -function TDynAABBTreeBase.segmentQuery (out qr: TSegmentQueryResult; ax, ay, bx, by: TreeNumber; cb: TSegQueryCallback; tagmask: Integer=-1): Boolean; +function TDynAABBTreeBase.segmentQuery (out qr: TSegmentQueryResult; const ax, ay, bx, by: TreeNumber; cb: TSegQueryCallback; tagmask: Integer=-1): Boolean; var - oldmaxFraction: Single; oldcurax, oldcuray: Single; oldcurbx, oldcurby: Single; olddirx, olddiry: Single; @@ -1764,7 +1763,6 @@ begin if (ax = bx) and (ay = by) then begin result := false; exit; end; - oldmaxFraction := maxFraction; oldcurax := curax; oldcuray := curay; oldcurbx := curbx; @@ -1773,7 +1771,8 @@ begin olddiry := diry; oldray := traceRay; - maxFraction := 1.0e100; // infinity + qr.time := 1.0e100; // infinity + //qr.time := sqrt((bx-ax)*(bx-ax)+(by-ay)*(by-ay))+1.0; curax := ax; curay := ay; curbx := bx; @@ -1806,10 +1805,17 @@ begin curby := oldcurby; dirx := olddirx; diry := olddiry; - maxFraction := oldmaxFraction; traceRay := oldray; - result := qr.valid; + if qr.valid and (qr.time <= (bx-ax)*(bx-ax)+(by-ay)*(by-ay)) then + begin + result := true; + end + else + begin + result := false; + qr.flesh := nil; + end; end;