MCPcopy Create free account
hub / github.com/carbonengine/trinity / GetClosestLocatorIndex

Method GetClosestLocatorIndex

trinity/Eve/SpaceObject/EveSpaceObject2.cpp:2264–2296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2262}
2263
2264int EveSpaceObject2::GetClosestLocatorIndex( const Vector3* position, BlueSharedString locatorSetName )
2265{
2266 auto locators = GetLocatorsForSet( locatorSetName );
2267 if( !locators )
2268 {
2269 return 0;
2270 }
2271
2272 // Run a single pass on the transformed locator positions and select the closest
2273 float closestLength = std::numeric_limits<float>::max();
2274 int closestIndex = -1;
2275
2276 Vector3 posInObjectSpace = (Vector3)XMVector3Transform( *position, m_invWorldTransform );
2277
2278 Vector3 locatorPosition, locatorDirection;
2279
2280 for( unsigned int i = 0; i < locators->size(); ++i )
2281 {
2282 auto& locator = ( *locators )[i];
2283 GetLocatorInObjectSpace( locatorPosition, locatorDirection, locator );
2284 if( IsLocatorFacingPosition( locatorDirection, posInObjectSpace ) )
2285 {
2286 auto distanceFromLocator = LengthSq( locatorPosition - posInObjectSpace );
2287 if( distanceFromLocator < closestLength )
2288 {
2289 closestIndex = int( i );
2290 closestLength = distanceFromLocator;
2291 }
2292 }
2293 }
2294
2295 return closestIndex;
2296}
2297
2298// Function to find closest locator without worrying about direction of the locator
2299int EveSpaceObject2::GetCloseLocatorIndex( const Vector3& position, BlueSharedString locatorSetName )

Callers

nothing calls this directly

Calls 3

IsLocatorFacingPositionFunction · 0.85
LengthSqFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected