Physics joints updated to the new API (#1361)

Co-authored-by: Ulugbek Adilbekov <ulugbek@amazon.com>
This commit is contained in:
amzn-sean
2021-06-17 15:52:27 +01:00
committed by GitHub
parent c46a17f3a6
commit 9f62d631fb
90 changed files with 2792 additions and 1665 deletions
+23 -45
View File
@@ -16,8 +16,10 @@
#include <PhysX/MathConversion.h>
#include <PhysX/PhysXLocks.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Interface/Interface.h>
#include <AzFramework/Physics/SimulatedBodies/RigidBody.h>
#include <AzFramework/Physics/RigidBodyBus.h>
#include <AzFramework/Physics/PhysicsScene.h>
#include <PxPhysicsAPI.h>
@@ -33,15 +35,17 @@ namespace PhysX
}
}
BallJointComponent::BallJointComponent(const GenericJointConfiguration& config
, const GenericJointLimitsConfiguration& swingLimit)
: JointComponent(config, swingLimit)
BallJointComponent::BallJointComponent(
const JointComponentConfiguration& configuration,
const JointGenericProperties& genericProperties,
const JointLimitProperties& limitProperties)
: JointComponent(configuration, genericProperties, limitProperties)
{
}
void BallJointComponent::InitNativeJoint()
{
if (m_joint)
if (m_jointHandle != AzPhysics::InvalidJointHandle)
{
return;
}
@@ -52,50 +56,24 @@ namespace PhysX
{
return;
}
PHYSX_SCENE_READ_LOCK(leadFollowerInfo.m_followerActor->getScene());
m_joint = AZStd::make_shared<BallJoint>(physx::PxSphericalJointCreate(
PxGetPhysics(),
leadFollowerInfo.m_leadActor,
leadFollowerInfo.m_leadLocal,
leadFollowerInfo.m_followerActor,
leadFollowerInfo.m_followerLocal),
leadFollowerInfo.m_leadBody,
leadFollowerInfo.m_followerBody);
InitSwingLimits();
}
BallJointConfiguration configuration;
configuration.m_parentLocalPosition = leadFollowerInfo.m_leadLocal.GetTranslation();
configuration.m_parentLocalRotation = leadFollowerInfo.m_leadLocal.GetRotation();
configuration.m_childLocalPosition = leadFollowerInfo.m_followerLocal.GetTranslation();
configuration.m_childLocalRotation = leadFollowerInfo.m_followerLocal.GetRotation();
void BallJointComponent::InitSwingLimits()
{
if (!m_joint)
configuration.m_genericProperties = m_genericProperties;
configuration.m_limitProperties = m_limits;
if (auto* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get())
{
return;
m_jointHandle = sceneInterface->AddJoint(
leadFollowerInfo.m_followerBody->m_sceneOwner,
&configuration,
leadFollowerInfo.m_leadBody->m_bodyHandle,
leadFollowerInfo.m_followerBody->m_bodyHandle);
m_jointSceneOwner = leadFollowerInfo.m_followerBody->m_sceneOwner;
}
physx::PxSphericalJoint* ballJointNative = static_cast<physx::PxSphericalJoint*>(m_joint->GetNativePointer());
if (!ballJointNative)
{
return;
}
if (!m_limits.m_isLimited)
{
ballJointNative->setSphericalJointFlag(physx::PxSphericalJointFlag::eLIMIT_ENABLED, false);
return;
}
// Hard limit uses a tolerance value (distance to limit at which limit becomes active).
// Soft limit allows angle to exceed limit but springs back with configurable spring stiffness and damping.
physx::PxJointLimitCone swingLimit(AZ::DegToRad(m_limits.m_limitFirst)
, AZ::DegToRad(m_limits.m_limitSecond)
, m_limits.m_tolerance);
if (m_limits.m_isSoftLimit)
{
swingLimit.stiffness = m_limits.m_stiffness;
swingLimit.damping = m_limits.m_damping;
}
ballJointNative->setLimitCone(swingLimit);
ballJointNative->setSphericalJointFlag(physx::PxSphericalJointFlag::eLIMIT_ENABLED, true);
}
} // namespace PhysX