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#include "Components/BsCSphericalJoint.h"
4#include "Scene/BsSceneObject.h"
5#include "Private/RTTI/BsCSphericalJointRTTI.h"
6#include "Scene/BsSceneManager.h"
7
8namespace bs
9{
10 CSphericalJoint::CSphericalJoint()
11 : CJoint(mDesc)
12 {
13 setName("SphericalJoint");
14 }
15
16 CSphericalJoint::CSphericalJoint(const HSceneObject& parent)
17 : CJoint(parent, mDesc)
18 {
19 setName("SphericalJoint");
20 }
21
22 LimitConeRange CSphericalJoint::getLimit() const
23 {
24 return mDesc.limit;
25 }
26
27 void CSphericalJoint::setLimit(const LimitConeRange& limit)
28 {
29 if (limit == mDesc.limit)
30 return;
31
32 mDesc.limit = limit;
33
34 if (mInternal != nullptr)
35 _getInternal()->setLimit(limit);
36 }
37
38 void CSphericalJoint::setFlag(SphericalJointFlag flag, bool enabled)
39 {
40 bool isEnabled = ((UINT32)mDesc.flag & (UINT32)flag) != 0;
41 if (isEnabled == enabled)
42 return;
43
44 if (enabled)
45 mDesc.flag = (SphericalJointFlag)((UINT32)mDesc.flag | (UINT32)flag);
46 else
47 mDesc.flag = (SphericalJointFlag)((UINT32)mDesc.flag & ~(UINT32)flag);
48
49 if (mInternal != nullptr)
50 _getInternal()->setFlag(flag, enabled);
51 }
52
53 bool CSphericalJoint::hasFlag(SphericalJointFlag flag) const
54 {
55 return ((UINT32)mDesc.flag & (UINT32)flag) != 0;
56 }
57
58 SPtr<Joint> CSphericalJoint::createInternal()
59 {
60 const SPtr<SceneInstance>& scene = SO()->getScene();
61 SPtr<Joint> joint = SphericalJoint::create(*scene->getPhysicsScene(), mDesc);
62
63 joint->_setOwner(PhysicsOwnerType::Component, this);
64 return joint;
65 }
66
67 RTTITypeBase* CSphericalJoint::getRTTIStatic()
68 {
69 return CSphericalJointRTTI::instance();
70 }
71
72 RTTITypeBase* CSphericalJoint::getRTTI() const
73 {
74 return CSphericalJoint::getRTTIStatic();
75 }
76}
77