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 | |
8 | namespace bs |
9 | { |
10 | class PhysicsScene; |
11 | /** @addtogroup Physics |
12 | * @{ |
13 | */ |
14 | |
15 | struct SPHERICAL_JOINT_DESC; |
16 | |
17 | /** Flags that control options for the spherical joint */ |
18 | enum class BS_SCRIPT_EXPORT(m:Physics) SphericalJointFlag |
19 | { |
20 | Limit = 0x1 /**< Enables the cone range limit. */ |
21 | }; |
22 | |
23 | /** |
24 | * A spherical joint removes all translational degrees of freedom but allows all rotational degrees of freedom. |
25 | * Essentially this ensures that the anchor points of the two bodies are always coincident. Bodies are allowed to |
26 | * rotate around the anchor points, and their rotatation can be limited by an elliptical cone. |
27 | */ |
28 | class BS_CORE_EXPORT SphericalJoint : public Joint |
29 | { |
30 | public: |
31 | SphericalJoint(const SPHERICAL_JOINT_DESC& desc) { } |
32 | virtual ~SphericalJoint() = default; |
33 | |
34 | /** @copydoc setLimit() */ |
35 | virtual LimitConeRange getLimit() const = 0; |
36 | |
37 | /** |
38 | * Determines the limit of the joint. This clamps the rotation inside an eliptical angular cone. You must enable |
39 | * limit flag on the joint in order for this to be recognized. |
40 | */ |
41 | virtual void setLimit(const LimitConeRange& limit) = 0; |
42 | |
43 | /** Enables or disables a flag that controls the joint's behaviour. */ |
44 | virtual void setFlag(SphericalJointFlag flag, bool enabled) = 0; |
45 | |
46 | /** Checks is the specified flag enabled. */ |
47 | virtual bool hasFlag(SphericalJointFlag flag) const = 0; |
48 | |
49 | /** |
50 | * Creates a new spherical joint. |
51 | * |
52 | * @param[in] scene Scene to which to add the joint. |
53 | * @param[in] desc Settings describing the joint. |
54 | */ |
55 | static SPtr<SphericalJoint> create(PhysicsScene& scene, const SPHERICAL_JOINT_DESC& desc); |
56 | }; |
57 | |
58 | /** Structure used for initializing a new SphericalJoint. */ |
59 | struct SPHERICAL_JOINT_DESC : JOINT_DESC |
60 | { |
61 | LimitConeRange limit; |
62 | SphericalJointFlag flag = (SphericalJointFlag)0; |
63 | }; |
64 | |
65 | /** @} */ |
66 | } |