Gems/PhysX/Code/Tests/Benchmarks/PhysXCharactersBenchmarks.cpp
AZStd::vector<Physics::Character*> CreateCharacterControllers(
            int numCharacterControllers,
            CharacterConstants::CharacterSettings::ColliderType colliderType,
            AzPhysics::SceneHandle& sceneHandle,
            GenerateSpawnPositionFuncPtr* genSpawnPosFuncPtr = nullptr)
        {
            //define some common configs
            PhysX::CharacterControllerConfiguration characterConfig;
            characterConfig.m_maximumSlopeAngle = CharacterConstants::CharacterSettings::MaximumSlopeAngle;
            characterConfig.m_stepHeight = CharacterConstants::CharacterSettings::StepHeight;

            switch (colliderType)
            {
            case CharacterConstants::CharacterSettings::ColliderType::Box:
                {
                    characterConfig.m_shapeConfig = AZStd::make_shared<Physics::BoxShapeConfiguration>(
                        AZ::Vector3(CharacterConstants::CharacterSettings::CharacterBoxWidth,
                            CharacterConstants::CharacterSettings::CharacterBoxDepth,
                            CharacterConstants::CharacterSettings::CharacterBoxHeight)
                    );

                }
                break;
            case CharacterConstants::CharacterSettings::ColliderType::Capsule:
            default:
                {
                    characterConfig.m_shapeConfig = AZStd::make_shared<Physics::CapsuleShapeConfiguration>(
                        CharacterConstants::CharacterSettings::CharacterCylinderHeight,
                        CharacterConstants::CharacterSettings::CharacterCylinderRadius);
                }
                break;
            }

            auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();

            AZStd::vector<Physics::Character*> controllers;
            controllers.reserve(numCharacterControllers);
            for (int i = 0; i < numCharacterControllers; i++)
            {
                const AZ::Vector3 spawnPosition = genSpawnPosFuncPtr != nullptr ? (*genSpawnPosFuncPtr)(i) : AZ::Vector3::CreateZero();
                characterConfig.m_position = spawnPosition;
                AzPhysics::SimulatedBodyHandle newHandle = sceneInterface->AddSimulatedBody(sceneHandle, &characterConfig);
                if (newHandle != AzPhysics::InvalidSimulatedBodyHandle)
                {
                    if (auto* characterPtr = azdynamic_cast<Physics::Character*>(
                            sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, newHandle)
                        ))
                    {
                        controllers.emplace_back(characterPtr);
                    }
                }
            }

            return controllers;
        }
//! Helper function to create the requested number of character controllers and where they spawn.
//! @param numCharacterControllers, the number of character controllers to spawn
//! @param colliderType, the collider type to use
//! @param scene, the scene to spawn the characters controller into
//! @param genSpawnPosFuncPtr - [optional] function pointer to allow caller to pick the spawn position
Helper function to create the requested number of character controllers and where they spawn.
Helper function to create the requested number of character controllers and where they spawn .
AZStd::vector<Physics::Character*> CreateCharacterControllers(
            int numCharacterControllers,
            CharacterConstants::CharacterSettings::ColliderType colliderType,
            AzPhysics::SceneHandle& sceneHandle,
            GenerateSpawnPositionFuncPtr* genSpawnPosFuncPtr = nullptr)
        {
            PhysX::CharacterControllerConfiguration characterConfig;
            characterConfig.m_maximumSlopeAngle = CharacterConstants::CharacterSettings::MaximumSlopeAngle;
            characterConfig.m_stepHeight = CharacterConstants::CharacterSettings::StepHeight;
            switch (colliderType)
            {
            case CharacterConstants::CharacterSettings::ColliderType::Box:
                {
                    characterConfig.m_shapeConfig = AZStd::make_shared<Physics::BoxShapeConfiguration>(
                        AZ::Vector3(CharacterConstants::CharacterSettings::CharacterBoxWidth,
                            CharacterConstants::CharacterSettings::CharacterBoxDepth,
                            CharacterConstants::CharacterSettings::CharacterBoxHeight)
                    );
                }
                break;
            case CharacterConstants::CharacterSettings::ColliderType::Capsule:
            default:
                {
                    characterConfig.m_shapeConfig = AZStd::make_shared<Physics::CapsuleShapeConfiguration>(
                        CharacterConstants::CharacterSettings::CharacterCylinderHeight,
                        CharacterConstants::CharacterSettings::CharacterCylinderRadius);
                }
                break;
            }
            auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get();
            AZStd::vector<Physics::Character*> controllers;
            controllers.reserve(numCharacterControllers);
            for (int i = 0; i < numCharacterControllers; i++)
            {
                const AZ::Vector3 spawnPosition = genSpawnPosFuncPtr != nullptr ? (*genSpawnPosFuncPtr)(i) : AZ::Vector3::CreateZero();
                characterConfig.m_position = spawnPosition;
                AzPhysics::SimulatedBodyHandle newHandle = sceneInterface->AddSimulatedBody(sceneHandle, &characterConfig);
                if (newHandle != AzPhysics::InvalidSimulatedBodyHandle)
                {
                    if (auto* characterPtr = azdynamic_cast<Physics::Character*>(
                            sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, newHandle)
                        ))
                    {
                        controllers.emplace_back(characterPtr);
                    }
                }
            }
            return controllers;
        }
AZStd :: vector < Physics :: Character * > CreateCharacterControllers ( int numCharacterControllers , CharacterConstants :: CharacterSettings :: ColliderType colliderType , AzPhysics :: SceneHandle & sceneHandle , GenerateSpawnPositionFuncPtr * genSpawnPosFuncPtr = nullptr ) { PhysX :: CharacterControllerConfiguration characterConfig ; characterConfig . m_maximumSlopeAngle = CharacterConstants :: CharacterSettings :: MaximumSlopeAngle ; characterConfig . m_stepHeight = CharacterConstants :: CharacterSettings :: StepHeight ; switch ( colliderType ) { case CharacterConstants :: CharacterSettings :: ColliderType :: Box : { characterConfig . m_shapeConfig = AZStd :: make_shared < Physics :: BoxShapeConfiguration > ( AZ :: Vector3 ( CharacterConstants :: CharacterSettings :: CharacterBoxWidth , CharacterConstants :: CharacterSettings :: CharacterBoxDepth , CharacterConstants :: CharacterSettings :: CharacterBoxHeight ) ) ; } break ; case CharacterConstants :: CharacterSettings :: ColliderType :: Capsule : default : { characterConfig . m_shapeConfig = AZStd :: make_shared < Physics :: CapsuleShapeConfiguration > ( CharacterConstants :: CharacterSettings :: CharacterCylinderHeight , CharacterConstants :: CharacterSettings :: CharacterCylinderRadius ) ; } break ; } auto * sceneInterface = AZ :: Interface < AzPhysics :: SceneInterface > :: Get ( ) ; AZStd :: vector < Physics :: Character * > controllers ; controllers . reserve ( numCharacterControllers ) ; for ( int i = 0 ; i < numCharacterControllers ; i ++ ) { const AZ :: Vector3 spawnPosition = genSpawnPosFuncPtr != nullptr ? ( * genSpawnPosFuncPtr ) ( i ) : AZ :: Vector3 :: CreateZero ( ) ; characterConfig . m_position = spawnPosition ; AzPhysics :: SimulatedBodyHandle newHandle = sceneInterface -> AddSimulatedBody ( sceneHandle , & characterConfig ) ; if ( newHandle != AzPhysics :: InvalidSimulatedBodyHandle ) { if ( auto * characterPtr = azdynamic_cast < Physics :: Character * > ( sceneInterface -> GetSimulatedBodyFromHandle ( sceneHandle , newHandle ) ) ) { controllers . emplace_back ( characterPtr ) ; } } } return controllers ; }
Helper function to create the requested number of character controllers and where they spawn.
Helper function to create the requested number of character controllers and where they spawn .
//define some common configs