Difference between revisions of "GetNClosestObjsFromArray"
From scripting
(Created page with " global proc string[] GetNClosestObjsFromArray(string $MainObj, string $OtherArr[], int $NCount) { //Author Nick Pisca 0001d 2009 string $ClosestArr[]; float $Clos...") |
(No difference)
|
Latest revision as of 05:58, 22 April 2017
global proc string[] GetNClosestObjsFromArray(string $MainObj, string $OtherArr[], int $NCount) { //Author Nick Pisca 0001d 2009 string $ClosestArr[]; float $ClosestDistArr[]; clear($ClosestDistArr); float $LocArr[] = `getAttr($MainObj+".translate")`; vector $LocVec = <<$LocArr[0], $LocArr[1], $LocArr[2]>>; for($e=0;$e<$NCount;$e++) { $ClosestDistArr[$e] = 999999999; } for ($xx=0;$xx<size($OtherArr);$xx++) { float $OppArr[] = `getAttr($OtherArr[$xx]+".translate")`; vector $OppVec = <<$OppArr[0], $OppArr[1], $OppArr[2]>>; vector $Diff = $LocVec - $OppVec; float $DiffDist = mag($Diff); int $BiggestIndex = GetBiggestFloatIndex($ClosestDistArr); if ($DiffDist < $ClosestDistArr[$BiggestIndex] && $DiffDist != 0) { $ClosestDistArr[$BiggestIndex] = $DiffDist; $ClosestArr[$BiggestIndex] = $OtherArr[$xx]; } } return $ClosestArr; }
More information on vector calculations and retrieving location attributes, read pages 14-16, 20, 90-101 in YSYT.