Files
o3de/Gems/PhysX/Code/Source/Joint/Configuration/PhysXJointConfiguration.cpp
T
amzn-sean 9f62d631fb Physics joints updated to the new API (#1361)
Co-authored-by: Ulugbek Adilbekov <ulugbek@amazon.com>
2021-06-17 15:52:27 +01:00

156 lines
7.0 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.
*
*/
#include <PhysX_precompiled.h>
#include <PhysX/Joint/Configuration/PhysXJointConfiguration.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>
#include <Joint/PhysXJointUtils.h>
namespace PhysX
{
JointGenericProperties::JointGenericProperties(GenericJointFlag flags, float forceMax, float torqueMax)
: m_flags(flags)
, m_forceMax(forceMax)
, m_torqueMax(torqueMax)
{
}
JointLimitProperties::JointLimitProperties(
bool isLimited, bool isSoftLimit,
float damping, float limitFirst, float limitSecond, float stiffness, float tolerance)
: m_isLimited(isLimited)
, m_isSoftLimit(isSoftLimit)
, m_damping(damping)
, m_limitFirst(limitFirst)
, m_limitSecond(limitSecond)
, m_stiffness(stiffness)
, m_tolerance(tolerance)
{
}
bool JointGenericProperties::IsFlagSet(GenericJointFlag flag) const
{
return static_cast<bool>(m_flags & flag);
}
void D6JointLimitConfiguration::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<D6JointLimitConfiguration, AzPhysics::JointConfiguration>()
->Version(1)
->Field("SwingLimitY", &D6JointLimitConfiguration::m_swingLimitY)
->Field("SwingLimitZ", &D6JointLimitConfiguration::m_swingLimitZ)
->Field("TwistLowerLimit", &D6JointLimitConfiguration::m_twistLimitLower)
->Field("TwistUpperLimit", &D6JointLimitConfiguration::m_twistLimitUpper)
;
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
{
editContext->Class<D6JointLimitConfiguration>(
"PhysX D6 Joint Configuration", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &D6JointLimitConfiguration::m_swingLimitY, "Swing limit Y",
"Maximum angle from the Y axis of the joint frame")
->Attribute(AZ::Edit::Attributes::Suffix, " degrees")
->Attribute(AZ::Edit::Attributes::Min, JointConstants::MinSwingLimitDegrees)
->Attribute(AZ::Edit::Attributes::Max, 180.0f)
->DataElement(AZ::Edit::UIHandlers::Default, &D6JointLimitConfiguration::m_swingLimitZ, "Swing limit Z",
"Maximum angle from the Z axis of the joint frame")
->Attribute(AZ::Edit::Attributes::Suffix, " degrees")
->Attribute(AZ::Edit::Attributes::Min, JointConstants::MinSwingLimitDegrees)
->Attribute(AZ::Edit::Attributes::Max, 180.0f)
->DataElement(AZ::Edit::UIHandlers::Default, &D6JointLimitConfiguration::m_twistLimitLower, "Twist lower limit",
"Lower limit for rotation about the X axis of the joint frame")
->Attribute(AZ::Edit::Attributes::Suffix, " degrees")
->Attribute(AZ::Edit::Attributes::Min, -180.0f)
->Attribute(AZ::Edit::Attributes::Max, 180.0f)
->DataElement(AZ::Edit::UIHandlers::Default, &D6JointLimitConfiguration::m_twistLimitUpper, "Twist upper limit",
"Upper limit for rotation about the X axis of the joint frame")
->Attribute(AZ::Edit::Attributes::Suffix, " degrees")
->Attribute(AZ::Edit::Attributes::Min, -180.0f)
->Attribute(AZ::Edit::Attributes::Max, 180.0f)
;
}
}
}
void JointGenericProperties::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<JointGenericProperties>()
->Version(1)
->Field("Maximum Force", &JointGenericProperties::m_forceMax)
->Field("Maximum Torque", &JointGenericProperties::m_torqueMax)
->Field("Flags", &JointGenericProperties::m_flags)
;
}
}
void JointLimitProperties::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<JointLimitProperties>()
->Version(1)
->Field("First Limit", &JointLimitProperties::m_limitFirst)
->Field("Second Limit", &JointLimitProperties::m_limitSecond)
->Field("Tolerance", &JointLimitProperties::m_tolerance)
->Field("Is Limited", &JointLimitProperties::m_isLimited)
->Field("Is Soft Limit", &JointLimitProperties::m_isSoftLimit)
->Field("Damping", &JointLimitProperties::m_damping)
->Field("Spring", &JointLimitProperties::m_stiffness)
;
}
}
void FixedJointConfiguration::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<FixedJointConfiguration, AzPhysics::JointConfiguration>()
->Version(1)
->Field("Generic Properties", &FixedJointConfiguration::m_genericProperties)
;
}
}
void BallJointConfiguration::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<BallJointConfiguration, AzPhysics::JointConfiguration>()
->Version(1)
->Field("Generic Properties", &BallJointConfiguration::m_genericProperties)
->Field("Limit Properties", &BallJointConfiguration::m_limitProperties)
;
}
}
void HingeJointConfiguration::Reflect(AZ::ReflectContext* context)
{
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<HingeJointConfiguration, AzPhysics::JointConfiguration>()
->Version(1)
->Field("Generic Properties", &HingeJointConfiguration::m_genericProperties)
->Field("Limit Properties", &HingeJointConfiguration::m_limitProperties)
;
}
}
} // namespace PhysX