index 86e05680340dfa2af06d8c4fee175a4f48e80083..88c7b8862aee31067522d79fd922d20d980e8fb2 100644 (file)
--- a/src/game/z_aabbtree.pas
+++ b/src/game/z_aabbtree.pas
chkAABB: AABB2D; // for checkers
qSRes: PSegmentQueryResult; // for queries
// for segment query
- maxFraction: Single;
curax, curay: Single;
curbx, curby: Single;
dirx, diry: Single;
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
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);
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,
node.aabb.maxX, node.aabb.maxY,
tmin,
Integer(result),
- maxFraction
+ qSRes.time
]), MSG_NOTIFY);
}
{$ENDIF}
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
// 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;
if (ax = bx) and (ay = by) then begin result := false; exit; end;
- oldmaxFraction := maxFraction;
oldcurax := curax;
oldcuray := curay;
oldcurbx := curbx;
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;
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;