From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Physics2D/JointDescriptions2D.h | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Runtime/Physics2D/JointDescriptions2D.h (limited to 'Runtime/Physics2D/JointDescriptions2D.h') diff --git a/Runtime/Physics2D/JointDescriptions2D.h b/Runtime/Physics2D/JointDescriptions2D.h new file mode 100644 index 0000000..23e2062 --- /dev/null +++ b/Runtime/Physics2D/JointDescriptions2D.h @@ -0,0 +1,101 @@ +#pragma once + +#if ENABLE_2D_PHYSICS || DOXYGEN + +#include "Runtime/Physics2D/Physics2DManager.h" +#include "Runtime/Serialize/SerializeUtility.h" +#include "Runtime/Utilities/ValidateArgs.h" + +// -------------------------------------------------------------------------- + + +struct JointMotor2D +{ + float m_MotorSpeed; ///< The target motor speed in degrees/second. range { -1000000, 1000000 } + float m_MaximumMotorForce; ///< The maximum force the motor can use to achieve the desired motor speed. range { 0.0, 1000000 } + + void Initialize () + { + m_MotorSpeed = 0.0f; + m_MaximumMotorForce = 10000.0f; + } + + void CheckConsistency () + { + m_MotorSpeed = clamp (m_MotorSpeed, -PHYSICS_2D_LARGE_RANGE_CLAMP, PHYSICS_2D_LARGE_RANGE_CLAMP); + m_MaximumMotorForce = clamp (m_MaximumMotorForce, 0, PHYSICS_2D_LARGE_RANGE_CLAMP); + } + + DECLARE_SERIALIZE_OPTIMIZE_TRANSFER (JointMotor2D) +}; + +template +void JointMotor2D::Transfer (TransferFunction& transfer) +{ + TRANSFER (m_MotorSpeed); + TRANSFER (m_MaximumMotorForce); +} + + +// -------------------------------------------------------------------------- + + +struct JointAngleLimits2D +{ + float m_LowerAngle; ///< The lower angle (in degrees) limit to constrain the joint to. range { -359.9999, 359.9999 } + float m_UpperAngle; ///< The upper angle (in degrees) limit to constrain the joint to. range { -359.9999, 359.9999 } + + void Initialize () + { + m_LowerAngle = 0.0f; + m_UpperAngle = 359.0f; + } + + void CheckConsistency () + { + m_LowerAngle = clamp (m_LowerAngle, -359.9999f, 359.9999f); + m_UpperAngle = clamp (m_UpperAngle, -359.9999f, 359.9999f); + } + + DECLARE_SERIALIZE_OPTIMIZE_TRANSFER (JointAngleLimit2D) +}; + +template +void JointAngleLimits2D::Transfer (TransferFunction& transfer) +{ + TRANSFER (m_LowerAngle); + TRANSFER (m_UpperAngle); +} + + +// -------------------------------------------------------------------------- + + +struct JointTranslationLimits2D +{ + float m_LowerTranslation; ///< The lower translation limit to constrain the joint to. range { -1000000, 1000000 } + float m_UpperTranslation; ///< The upper translation limit to constrain the joint to. range { -1000000, 1000000 } + + void Initialize () + { + m_LowerTranslation = 0.0f; + m_UpperTranslation = 0.0f; + } + + void CheckConsistency () + { + m_LowerTranslation = clamp (m_LowerTranslation, -PHYSICS_2D_LARGE_RANGE_CLAMP, PHYSICS_2D_LARGE_RANGE_CLAMP); + m_UpperTranslation = clamp (m_UpperTranslation, -PHYSICS_2D_LARGE_RANGE_CLAMP, PHYSICS_2D_LARGE_RANGE_CLAMP); + } + + DECLARE_SERIALIZE_OPTIMIZE_TRANSFER (JointTranslationLimits2D) +}; + +template +void JointTranslationLimits2D::Transfer (TransferFunction& transfer) +{ + TRANSFER (m_LowerTranslation); + TRANSFER (m_UpperTranslation); +} + +#endif -- cgit v1.1-26-g67d0