// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "Joint.h"
#include "Limits.h"
///
/// Controls distance joint options.
///
API_ENUM(Attributes="Flags") enum class DistanceJointFlag
{
///
/// The none limits.
///
None = 0,
///
/// The minimum distance limit.
///
MinDistance = 0x1,
///
/// Uses the maximum distance limit.
///
MaxDistance = 0x2,
///
/// Uses the spring when maintaining limits
///
Spring = 0x4,
};
DECLARE_ENUM_OPERATORS(DistanceJointFlag);
///
/// Physics joint that maintains an upper or lower (or both) bound on the distance between two bodies.
///
///
API_CLASS(Attributes="ActorContextMenu(\"New/Physics/Joints/Distance Joint\"), ActorToolbox(\"Physics\")")
class FLAXENGINE_API DistanceJoint : public Joint
{
DECLARE_SCENE_OBJECT(DistanceJoint);
private:
DistanceJointFlag _flags;
float _minDistance;
float _maxDistance;
float _tolerance;
SpringParameters _spring;
public:
///
/// Gets the joint mode flags. Controls joint behaviour.
///
API_PROPERTY(Attributes="EditorOrder(100), DefaultValue(DistanceJointFlag.MinDistance | DistanceJointFlag.MaxDistance)")
FORCE_INLINE DistanceJointFlag GetFlags() const
{
return _flags;
}
///
/// Sets the joint mode flags. Controls joint behaviour.
///
API_PROPERTY() void SetFlags(DistanceJointFlag value);
///
/// Gets the allowed minimum distance for the joint.
///
/// Used only when DistanceJointFlag.MinDistance flag is set. The minimum distance must be no more than the maximum distance. Default: 0, Range: [0, float.MaxValue].
API_PROPERTY(Attributes="EditorOrder(110), DefaultValue(0.0f), Limit(0.0f), EditorDisplay(\"Joint\")")
FORCE_INLINE float GetMinDistance() const
{
return _minDistance;
}
///
/// Sets the allowed minimum distance for the joint.
///
/// Used only when DistanceJointFlag.MinDistance flag is set. The minimum distance must be no more than the maximum distance. Default: 0, Range: [0, float.MaxValue].
API_PROPERTY() void SetMinDistance(float value);
///
/// Gets the allowed maximum distance for the joint.
///
/// Used only when DistanceJointFlag.MaxDistance flag is set. The maximum distance must be no less than the minimum distance. Default: 0, Range: [0, float.MaxValue].
API_PROPERTY(Attributes="EditorOrder(120), DefaultValue(10.0f), Limit(0.0f), EditorDisplay(\"Joint\")")
FORCE_INLINE float GetMaxDistance() const
{
return _maxDistance;
}
///
/// Sets the allowed maximum distance for the joint.
///
/// Used only when DistanceJointFlag.MaxDistance flag is set. The maximum distance must be no less than the minimum distance. Default: 0, Range: [0, float.MaxValue].
API_PROPERTY() void SetMaxDistance(float value);
///
/// Gets the error tolerance of the joint.
///
/// The distance beyond the joint's [min, max] range before the joint becomes active. Default: 25, Range: [0.1, float.MaxValue].
API_PROPERTY(Attributes="EditorOrder(130), DefaultValue(25.0f), Limit(0.0f), EditorDisplay(\"Joint\")")
FORCE_INLINE float GetTolerance() const
{
return _tolerance;
}
///
/// Sets the error tolerance of the joint.
///
/// The distance beyond the joint's [min, max] range before the joint becomes active. Default: 25, Range: [0.1, float.MaxValue].
API_PROPERTY() void SetTolerance(float value);
///
/// Gets the spring parameters.
///
API_PROPERTY(Attributes="EditorOrder(140), EditorDisplay(\"Joint\")")
FORCE_INLINE SpringParameters GetSpringParameters() const
{
return _spring;
}
///
/// Sets the spring parameters.
///
API_PROPERTY() void SetSpringParameters(const SpringParameters& value);
public:
///
/// Gets the current distance of the joint.
///
API_PROPERTY() float GetCurrentDistance() const;
public:
// [Joint]
#if USE_EDITOR
void OnDebugDrawSelected() override;
#endif
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
protected:
// [Joint]
void* CreateJoint(const PhysicsJointDesc& desc) override;
};