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

Method GetGoodLocatorIndex

trinity/Eve/SpaceObject/EveSpaceObject2.cpp:2364–2423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2362}
2363
2364int EveSpaceObject2::GetGoodLocatorIndex( const Vector3& position, BlueSharedString locatorSetName )
2365{
2366 float minDistance = FLT_MAX;
2367 float maxDistance = FLT_MIN;
2368 float bestDirectionFit = 0.0f;
2369
2370 Vector3 posInObjectSpace = (Vector3)XMVector3Transform( position, m_invWorldTransform );
2371 auto locators = GetLocatorsForSet( locatorSetName );
2372 if( !locators )
2373 {
2374 return 0;
2375 }
2376
2377 Vector3 locatorPosition, locatorDirection;
2378
2379 for( size_t i = 0; i < locators->size(); ++i )
2380 {
2381 auto& locator = ( *locators )[i];
2382 GetLocatorInObjectSpace( locatorPosition, locatorDirection, locator );
2383 if( IsLocatorFacingPosition( locatorDirection, posInObjectSpace ) )
2384 {
2385 Vector3 v( XMVectorSubtract( locatorPosition, posInObjectSpace ) );
2386 float length = Length( v );
2387 minDistance = min( minDistance, length );
2388 maxDistance = max( maxDistance, length );
2389 v = Normalize( v );
2390 float directionFit = GetDirectionFit( locatorDirection, v );
2391 bestDirectionFit = max( bestDirectionFit, directionFit );
2392 }
2393 }
2394
2395 float desiredFit = TriRand() * ( 0.25f - ( 1.0f - bestDirectionFit ) ) + 0.75f;
2396 float bestFit = 1.0f;
2397
2398 int bestLocator = -1;
2399 for( size_t i = 0; i < locators->size(); ++i )
2400 {
2401 auto& locator = ( *locators )[i];
2402 GetLocatorInObjectSpace( locatorPosition, locatorDirection, locator );
2403 if( IsLocatorFacingPosition( locatorDirection, posInObjectSpace ) )
2404 {
2405 Vector3 v( XMVectorSubtract( locatorPosition, posInObjectSpace ) );
2406 float fitValue = GetDistanceFit( minDistance, maxDistance - minDistance, v );
2407 v = Normalize( v );
2408 fitValue *= GetDirectionFit( locatorDirection, v );
2409 if( std::abs( fitValue - desiredFit ) < bestFit )
2410 {
2411 bestFit = std::abs( fitValue - desiredFit );
2412 bestLocator = (int)i;
2413 }
2414 }
2415 }
2416
2417 if( bestLocator < 0 )
2418 {
2419 bestLocator = GetClosestLocatorIndex( &position, locatorSetName );
2420 }
2421

Callers

nothing calls this directly

Calls 6

IsLocatorFacingPositionFunction · 0.85
LengthFunction · 0.85
GetDirectionFitFunction · 0.85
TriRandFunction · 0.85
GetDistanceFitFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected