1 voidAhud::getactorsinselectionrectangle (tsubclassof<classAactor> Classfilter,Constfvector2d& Firstpoint,Constfvector2d& Secondpoint, tarray<aactor*>& outactors,BOOLBincludenoncollidingcomponents,BOOLbactormustbefullyenclosed)2 {3 //Because This is a HUD function it's likely to get called each tick,4 //So make sure any previous contents of the An Out actor array has been cleared!5 outactors.empty ();6 7 //Create Selection Rectangle from Points8Fbox2d Selectionrectangle (0);9 Ten //This method ensures a appropriate rectangle is generated, One //no matter what is the coordinates of first and second point actually is. ASelectionrectangle + =Firstpoint; -Selectionrectangle + =Secondpoint; - the - //The Actor Bounds point Mapping - ConstFvector boundspointmapping[8] = - { +Fvector (1,1,1), -Fvector (1,1, -1), +Fvector (1, -1,1), AFvector (1, -1, -1), atFvector (-1,1,1), -Fvector (-1,1, -1), -Fvector (-1, -1,1), -Fvector (-1, -1, -1) - }; - in //~~~ - to //For each Actor of the Class Filter Type + for(Tactoriterator<aactor> Itr (Getworld (), classfilter); ITR; ++Itr) - { theaactor* eachactor = *Itr; * $ //Get Actor Bounds//casting to base class, checked by template in the. hPanax Notoginseng ConstFbox eachactorbounds = cast<aactor> (eachactor)->getcomponentsboundingbox (bIncludeNonCollidingComponents) ;/*All components ?*/ - the //Center + ConstFvector Boxcenter =Eachactorbounds.getcenter (); A the //extents + ConstFvector boxextents =eachactorbounds.getextent (); - $ //Build 2D bounding box of actor in screen space $Fbox2d actorbox2d (0); - for(Uint8 Boundspointitr =0; Boundspointitr <8; boundspointitr++) - { the //Project vert into screen space. - ConstFvector projectedworldlocation = Project (Boxcenter + (BOUNDSPOINTMAPPING[BOUNDSPOINTITR] *boxextents));Wuyi //Add to 2D bounding box theactorbox2d + =fvector2d (projectedworldlocation.x, PROJECTEDWORLDLOCATION.Y); - } Wu - //Selection Box must fully enclose the projected Actor Bounds About if(bactormustbefullyenclosed) $ { - if(Selectionrectangle.isinside (actorbox2d)) - { -Outactors.add (cast<aactor>(Eachactor)); A } + } the //Partial intersection with projected Actor Bounds - Else $ { the if(Selectionrectangle.intersect (actorbox2d)) the { theOutactors.add (cast<aactor>(Eachactor)); the } - } in } the}
The box function in Ue4