Files
o3de/Gems/PhysX/Code/Tests/Benchmarks/PhysXBenchmarkWashingMachine.h
T
2021-04-07 14:03:29 -07:00

78 lines
2.7 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#ifdef HAVE_BENCHMARK
#include <AzCore/Math/Random.h>
#include <AzCore/Math/Vector3.h>
#include <AzFramework/Physics/Common/PhysicsEvents.h>
#include <AzFramework/Physics/Common/PhysicsTypes.h>
namespace AzPhysics
{
class Scene;
}
namespace PhysX::Benchmarks
{
//! Helper to create a cylinder and place a spinning 'blade' inside
class WashingMachine
{
public:
WashingMachine();
~WashingMachine();
//! Create the washing machine.
//! @param sceneHandle A handle to the physics scene to create the washing machine in.
//! @param cylinderRadius Inside radius of the cylinder.
//! @param cylinderHeight How tall to make the cylinder.
//! @param position Where to position the cylinder.
//! @param RPM How fast to spin the 'blade' in rotations per minute.
void SetupWashingMachine(AzPhysics::SceneHandle sceneHandle, float cylinderRadius, float cylinderHeight,
const AZ::Vector3& position, float RPM);
//! Clean up the machine.
void TearDownWashingMachine();
private:
void UpdateBlade(float fixedDeltaTime);
//! Helper to animate the 'blade'.
struct BladeAnimation
{
//! Initialize the animation at the given RPM.
//! @param RPM - how fast to spin the 'blade' in rotations per minute.
void Init(float RPM);
//! Step the animation by the given time and return a quaternion of the new rotation.
//! @param deltaTime - time since last step of the animation.
//! @return AZ::Quaternion - new rotation after updating.
AZ::Quaternion StepAnimation(float deltaTime);
private:
float m_angularVelocity;
float m_angularPosition;
};
static const int NumCylinderSide = 12;
AZStd::array<AzPhysics::SimulatedBodyHandle, NumCylinderSide> m_cylinder;
AzPhysics::SimulatedBodyHandle m_blade;
AzPhysics::SceneHandle m_sceneHandle = AzPhysics::InvalidSceneHandle;
BladeAnimation m_bladeAnimation;
AzPhysics::SceneEvents::OnSceneSimulationStartHandler m_sceneStartSimHandler;
};
} // namespace PhysX::Benchmarks
#endif //HAVE_BENCHMARK