1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6#include "Physics/BsJoint.h"
7
8namespace bs
9{
10 class PhysicsScene;
11 /** @addtogroup Physics
12 * @{
13 */
14
15 struct DISTANCE_JOINT_DESC;
16
17 /** Controls distance joint options. */
18 enum class BS_SCRIPT_EXPORT(m:Physics) DistanceJointFlag
19 {
20 MinDistance = 0x1, /**< Enables minimum distance limit. */
21 MaxDistance = 0x2, /**< Enables maximum distance limit. */
22 Spring = 0x4 /**< Enables spring when maintaining limits. */
23 };
24
25 /** A joint that maintains an upper or lower (or both) bound on the distance between two bodies. */
26 class BS_CORE_EXPORT DistanceJoint : public Joint
27 {
28 public:
29 DistanceJoint(const DISTANCE_JOINT_DESC& desc) { }
30 virtual ~DistanceJoint() = default;
31
32 /** Returns the current distance between the two joint bodies. */
33 virtual float getDistance() const = 0;
34
35 /** @copydoc setMinDistance() */
36 virtual float getMinDistance() const = 0;
37
38 /**
39 * Determines the minimum distance the bodies are allowed to be at, they will get no closer. You must enable min
40 * distance flag in order for this limit to be applied.
41 */
42 virtual void setMinDistance(float value) = 0;
43
44 /** @copydoc setMaxDistance() */
45 virtual float getMaxDistance() const = 0;
46
47 /**
48 * Determines the maximum distance the bodies are allowed to be at, they will get no further. You must enable max
49 * distance flag in order for this limit to be applied.
50 */
51 virtual void setMaxDistance(float value) = 0;
52
53 /** @copydoc setTolerance() */
54 virtual float getTolerance() const = 0;
55
56 /**
57 * Determines the error tolerance of the joint at which the joint becomes active. This value slightly extends the
58 * lower and upper limit.
59 */
60 virtual void setTolerance(float value) = 0;
61
62 /** @copydoc setSpring() */
63 virtual Spring getSpring() const = 0;
64
65 /**
66 * Determines a spring that controls how the joint responds when a limit is reached. You must enable the spring
67 * flag on the joint in order for this to be recognized.
68 *
69 * @see Spring
70 */
71 virtual void setSpring(const Spring& value) = 0;
72
73 /** Enables or disables a flag that controls joint behaviour. */
74 virtual void setFlag(DistanceJointFlag flag, bool enabled) = 0;
75
76 /** Checks whether a certain joint flag is enabled. */
77 virtual bool hasFlag(DistanceJointFlag flag) const = 0;
78
79 /**
80 * Creates a new distance joint.
81 *
82 * @param[in] scene Scene to which to add the joint.
83 * @param[in] desc Settings describing the joint.
84 */
85 static SPtr<DistanceJoint> create(PhysicsScene& scene, const DISTANCE_JOINT_DESC& desc);
86 };
87
88 /** Structure used for initializing a new DistanceJoint. */
89 struct DISTANCE_JOINT_DESC : JOINT_DESC
90 {
91 float minDistance = 0.0f;
92 float maxDistance = 0.0f;
93 float tolerance = 0.25f;
94 Spring spring;
95 DistanceJointFlag flag = (DistanceJointFlag)0;
96 };
97
98 /** @} */
99}