Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
GenericOctree.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 GenericOctree.inl: Generic octree implementation.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreTypes.h"
10#include "CoreFwd.h"
11#include "Logging/LogMacros.h"
12
17struct FMath;
18
19
20FORCEINLINE bool FOctreeChildNodeSubset::Contains(FOctreeChildNodeRef ChildRef) const
21{
22 // This subset contains the child if it has all the bits set that are set for the subset containing only the child node.
23 const FOctreeChildNodeSubset ChildSubset(ChildRef);
24 return (ChildBits & ChildSubset.ChildBits) == ChildSubset.ChildBits;
25}
26
27FORCEINLINE FOctreeChildNodeSubset FOctreeNodeContext::GetIntersectingChildren(const FBoxCenterAndExtent& QueryBounds) const
28{
29 FOctreeChildNodeSubset Result;
30
31 // Load the query bounding box values as VectorRegisters.
32 const VectorRegister QueryBoundsCenter = VectorLoadAligned(&QueryBounds.Center);
33 const VectorRegister QueryBoundsExtent = VectorLoadAligned(&QueryBounds.Extent);
34 const VectorRegister QueryBoundsMax = VectorAdd(QueryBoundsCenter,QueryBoundsExtent);
35 const VectorRegister QueryBoundsMin = VectorSubtract(QueryBoundsCenter,QueryBoundsExtent);
36
37 // Compute the bounds of the node's children.
38 const VectorRegister BoundsCenter = VectorLoadAligned(&Bounds.Center);
39 const VectorRegister BoundsExtent = VectorLoadAligned(&Bounds.Extent);
40 const VectorRegister PositiveChildBoundsMin = VectorSubtract(
41 VectorAdd(BoundsCenter,VectorLoadFloat1(&ChildCenterOffset)),
42 VectorLoadFloat1(&ChildExtent)
43 );
44 const VectorRegister NegativeChildBoundsMax = VectorAdd(
45 VectorSubtract(BoundsCenter,VectorLoadFloat1(&ChildCenterOffset)),
46 VectorLoadFloat1(&ChildExtent)
47 );
48
49 // Intersect the query bounds with the node's children's bounds.
50 Result.PositiveChildBits = VectorMaskBits(VectorCompareGT(QueryBoundsMax, PositiveChildBoundsMin)) & 0x7;
51 Result.NegativeChildBits = VectorMaskBits(VectorCompareLE(QueryBoundsMin, NegativeChildBoundsMax)) & 0x7;
52 return Result;
53}
54
55FORCEINLINE FOctreeChildNodeRef FOctreeNodeContext::GetContainingChild(const FBoxCenterAndExtent& QueryBounds) const
56{
57 FOctreeChildNodeRef Result;
58
59 // Load the query bounding box values as VectorRegisters.
60 const VectorRegister QueryBoundsCenter = VectorLoadAligned(&QueryBounds.Center);
61 const VectorRegister QueryBoundsExtent = VectorLoadAligned(&QueryBounds.Extent);
62
63 // Compute the bounds of the node's children.
64 const VectorRegister BoundsCenter = VectorLoadAligned(&Bounds.Center);
65 const VectorRegister ChildCenterOffsetVector = VectorLoadFloat1(&ChildCenterOffset);
66 const VectorRegister NegativeCenterDifference = VectorSubtract(QueryBoundsCenter,VectorSubtract(BoundsCenter,ChildCenterOffsetVector));
67 const VectorRegister PositiveCenterDifference = VectorSubtract(VectorAdd(BoundsCenter,ChildCenterOffsetVector),QueryBoundsCenter);
68
69 // If the query bounds isn't entirely inside the bounding box of the child it's closest to, it's not contained by any of the child nodes.
70 const VectorRegister MinDifference = VectorMin(PositiveCenterDifference,NegativeCenterDifference);
71 if(VectorAnyGreaterThan(VectorAdd(QueryBoundsExtent,MinDifference),VectorLoadFloat1(&ChildExtent)))
72 {
73 Result.SetNULL();
74 }
75 else
76 {
77 // Return the child node that the query is closest to as the containing child.
78 Result.Index = VectorMaskBits(VectorCompareGT(QueryBoundsCenter, BoundsCenter)) & 0x7;
79 }
80
81 return Result;
82}
#define FORCEINLINE
Definition Platform.h:644