void Octree::Query_Region(const AABB ®ion, std::vector<OctreeOccupant*> &result) const { // Query outside root elements for(std::unordered_set<OctreeOccupant*>::iterator it = m_outsideRoot.begin(); it != m_outsideRoot.end(); it++) { OctreeOccupant* pOc = *it; if(region.Intersects(pOc->m_aabb)) { // Intersects, add to list result.push_back(pOc); } } std::list<OctreeNode*> open; open.push_back(m_pRootNode.get()); while(!open.empty()) { // Depth-first (results in less memory usage), remove objects from open list OctreeNode* pCurrent = open.back(); open.pop_back(); if(region.Intersects(pCurrent->m_region)) { for(std::unordered_set<OctreeOccupant*>::iterator it = pCurrent->m_pOccupants.begin(); it != pCurrent->m_pOccupants.end(); it++) { OctreeOccupant* pOc = *it; if(region.Intersects(pOc->m_aabb)) { // Visible, add to list result.push_back(pOc); } } // Add children to open list if they intersect the region if(pCurrent->m_hasChildren) { for(int x = 0; x < 2; x++) for(int y = 0; y < 2; y++) for(int z = 0; z < 2; z++) { if((*pCurrent->m_children)[x][y][z].GetNumOccupantsBelow() != 0) open.push_back(&(*pCurrent->m_children)[x][y][z]); } } } } }
bool Ellipsoid::SweepAgainst(const CollisionTriangle& t, const Vector& v, const AABB& SweepAABB, CollisionInfo* const pInfo) const { if (SweepAABB.Intersects(t.m_AABB)) // Broad phase: test sweep bounds against // precomputed triangle bounds { const Vector InvExtents = 1.0f / m_Extents; const Triangle ESpaceTri(t.m_Triangle.m_Vec1 * InvExtents, t.m_Triangle.m_Vec2 * InvExtents, t.m_Triangle.m_Vec3 * InvExtents); const Sphere UnitSphere(m_Center * InvExtents, 1.0f); const Vector ESpaceOffset = v * InvExtents; if (UnitSphere.SweepAgainst(ESpaceTri, ESpaceOffset, pInfo)) { if (pInfo) { pInfo->m_Intersection *= m_Extents; pInfo->m_Plane = Plane((pInfo->m_Plane.m_Normal * InvExtents).GetNormalized(), pInfo->m_Intersection); } return true; } } return false; }
_Use_decl_annotations_ void BIH::Query(const AABB& test, uint32_t* numTriangles) { *numTriangles = 0; if (!test.Intersects(_bounds)) { return; } Query(test, _root, numTriangles); }
MATH_IGNORE_UNUSED_VARS_WARNING RANDOMIZED_TEST(AABBPBVolumeIntersect) { vec pt = vec::RandomBox(rng, POINT_VEC_SCALAR(-SCALE), POINT_VEC_SCALAR(SCALE)); Frustum b = RandomFrustumContainingPoint(pt); AABB a = RandomAABBContainingPoint(pt, 10.f); assert(a.Intersects(b)); assert(b.Intersects(a)); bool contained = b.Contains(a); vec centerPoint = b.CenterPoint(); assert(b.Contains(b.CenterPoint())); PBVolume<6> pbVolume = ToPBVolume(b); assert(pbVolume.Contains(b.CenterPoint())); CullTestResult r = pbVolume.InsideOrIntersects(a); assert(r == TestInside || r == TestNotContained); if (contained) assert(r == TestInside); }
inline bool Intersects(PhysicsObject Other) { if (Other._id == _parentID || Other._parentID == _id) return false; return _aabb.Intersects(Other._aabb); }
bool Polygon::Intersects(const AABB &aabb) const { return aabb.Intersects(*this); }
bool Sphere::Intersects(const AABB &aabb, vec *closestPointOnAABB) const { return aabb.Intersects(*this, closestPointOnAABB); }
bool Ray::Intersects(const AABB &aabb, float *dNear, float *dFar) const { return aabb.Intersects(*this, dNear, dFar); }
bool Ray::Intersects(const AABB &aabb) const { return aabb.Intersects(*this); }
/*virtual*/ void WBCompEldIcicles::Tick( float DeltaTime ) { XTRACE_FUNCTION; PROFILE_FUNCTION; Unused( DeltaTime ); WBEntity* const pEntity = GetEntity(); ASSERT( pEntity ); WBCompEldAnchor* const pAnchor = GET_WBCOMP( pEntity, EldAnchor ); ASSERT( pAnchor ); if( !pAnchor->IsAnchored() ) { return; } WBEntity* const pPlayer = EldritchGame::GetPlayer(); if( !pPlayer ) { return; } WBCompStatMod* const pPlayerStatMod = GET_WBCOMP( pPlayer, StatMod ); ASSERT( pPlayerStatMod ); WB_MODIFY_FLOAT( IgnoreIcicles, 0.0f, pPlayerStatMod ); const bool IgnoreIcicles = ( WB_MODDED( IgnoreIcicles ) != 0.0f ); if( IgnoreIcicles ) { return; } EldritchWorld* const pWorld = GetWorld(); ASSERT( pWorld ); WBCompEldTransform* const pTransform = pEntity->GetTransformComponent<WBCompEldTransform>(); ASSERT( pTransform ); WBCompEldCollision* const pCollision = GET_WBCOMP( pEntity, EldCollision ); ASSERT( pCollision ); WBCompEldTransform* const pPlayerTransform = pPlayer->GetTransformComponent<WBCompEldTransform>(); ASSERT( pPlayerTransform ); WBCompEldCollision* const pPlayerCollision = GET_WBCOMP( pPlayer, EldCollision ); ASSERT( pPlayerCollision ); const Vector CheckOffset = Vector( 0.0f, 0.0f, -m_CheckDistance ); const Vector TraceStart = pTransform->GetLocation(); Vector TraceEnd = TraceStart + CheckOffset; // Early out if player doesn't intersect the trace bounds. Vector EntityExtents = pCollision->GetExtents(); EntityExtents.z = 0.0f; const AABB TraceBox = AABB( TraceEnd - EntityExtents, TraceStart + EntityExtents ); const AABB PlayerBox = pPlayerCollision->GetBounds(); if( !TraceBox.Intersects( PlayerBox ) ) { return; } // Move trace up to the top of player so we don't check occlusion beyond player. const float PlayerTopZ = PlayerBox.m_Max.z; TraceEnd.z = PlayerTopZ; // Do an occlusion test to make sure there's nothing blocking the trace. CollisionInfo Info; Info.m_CollideWorld = true; Info.m_CollideEntities = true; Info.m_CollidingEntity = pEntity; Info.m_UserFlags = EECF_Occlusion; Info.m_StopAtAnyCollision = true; const bool Occluded = pWorld->LineCheck( TraceStart, TraceEnd, Info ); if( Occluded ) { return; } // All checks passed. Unanchor to initiate falling sequence WB_MAKE_EVENT( Unanchor, pEntity ); WB_DISPATCH_EVENT( GetEventManager(), Unanchor, pEntity ); }
bool Line::Intersects(const AABB &aabb, float &dNear, float &dFar) const { return aabb.Intersects(*this, dNear, dFar); }