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/BsCD6Joint.h"
4#include "Scene/BsSceneObject.h"
5#include "Private/RTTI/BsCD6JointRTTI.h"
6#include "Scene/BsSceneManager.h"
7
8namespace bs
9{
10 CD6Joint::CD6Joint()
11 : CJoint(mDesc)
12 {
13 setName("D6Joint");
14 }
15
16 CD6Joint::CD6Joint(const HSceneObject& parent)
17 : CJoint(parent, mDesc)
18 {
19 setName("D6Joint");
20 }
21
22 D6JointMotion CD6Joint::getMotion(D6JointAxis axis) const
23 {
24 return mDesc.motion[(int)axis];
25 }
26
27 void CD6Joint::setMotion(D6JointAxis axis, D6JointMotion motion)
28 {
29 if (mDesc.motion[(int)axis] == motion)
30 return;
31
32 mDesc.motion[(int)axis] = motion;
33
34 if (mInternal != nullptr)
35 _getInternal()->setMotion(axis, motion);
36 }
37
38 Radian CD6Joint::getTwist() const
39 {
40 if (mInternal == nullptr)
41 return Radian(0.0f);
42
43 return _getInternal()->getTwist();
44 }
45
46 Radian CD6Joint::getSwingY() const
47 {
48 if (mInternal == nullptr)
49 return Radian(0.0f);
50
51 return _getInternal()->getSwingY();
52 }
53
54 Radian CD6Joint::getSwingZ() const
55 {
56 if (mInternal == nullptr)
57 return Radian(0.0f);
58
59 return _getInternal()->getSwingZ();
60 }
61
62 LimitLinear CD6Joint::getLimitLinear() const
63 {
64 return mDesc.limitLinear;
65 }
66
67 void CD6Joint::setLimitLinear(const LimitLinear& limit)
68 {
69 if (mDesc.limitLinear == limit)
70 return;
71
72 mDesc.limitLinear = limit;
73
74 if (mInternal != nullptr)
75 _getInternal()->setLimitLinear(limit);
76 }
77
78 LimitAngularRange CD6Joint::getLimitTwist() const
79 {
80 return mDesc.limitTwist;
81 }
82
83 void CD6Joint::setLimitTwist(const LimitAngularRange& limit)
84 {
85 if (mDesc.limitTwist == limit)
86 return;
87
88 mDesc.limitTwist = limit;
89
90 if (mInternal != nullptr)
91 _getInternal()->setLimitTwist(limit);
92 }
93
94 LimitConeRange CD6Joint::getLimitSwing() const
95 {
96 return mDesc.limitSwing;
97 }
98
99 void CD6Joint::setLimitSwing(const LimitConeRange& limit)
100 {
101 if (mDesc.limitSwing == limit)
102 return;
103
104 mDesc.limitSwing = limit;
105
106 if (mInternal != nullptr)
107 _getInternal()->setLimitSwing(limit);
108 }
109
110 D6JointDrive CD6Joint::getDrive(D6JointDriveType type) const
111 {
112 return mDesc.drive[(int)type];
113 }
114
115 void CD6Joint::setDrive(D6JointDriveType type, const D6JointDrive& drive)
116 {
117 if (mDesc.drive[(int)type] == drive)
118 return;
119
120 mDesc.drive[(int)type] = drive;
121
122 if (mInternal != nullptr)
123 _getInternal()->setDrive(type, drive);
124 }
125
126 Vector3 CD6Joint::getDrivePosition() const
127 {
128 return mDesc.drivePosition;
129 }
130
131 Quaternion CD6Joint::getDriveRotation() const
132 {
133 return mDesc.driveRotation;
134 }
135
136 void CD6Joint::setDriveTransform(const Vector3& position, const Quaternion& rotation)
137 {
138 if (mDesc.drivePosition == position && mDesc.driveRotation == rotation)
139 return;
140
141 mDesc.drivePosition = position;
142 mDesc.driveRotation = rotation;
143
144 if (mInternal != nullptr)
145 _getInternal()->setDriveTransform(position, rotation);
146 }
147
148 Vector3 CD6Joint::getDriveLinearVelocity() const
149 {
150 return mDesc.driveLinearVelocity;
151 }
152
153 Vector3 CD6Joint::getDriveAngularVelocity() const
154 {
155 return mDesc.driveAngularVelocity;
156 }
157
158 void CD6Joint::setDriveVelocity(const Vector3& linear, const Vector3& angular)
159 {
160 if (mDesc.driveLinearVelocity == linear && mDesc.driveAngularVelocity == angular)
161 return;
162
163 mDesc.driveLinearVelocity = linear;
164 mDesc.driveAngularVelocity = angular;
165
166 if (mInternal != nullptr)
167 _getInternal()->setDriveVelocity(linear, angular);
168 }
169
170 SPtr<Joint> CD6Joint::createInternal()
171 {
172 const SPtr<SceneInstance>& scene = SO()->getScene();
173 SPtr<Joint> joint = D6Joint::create(*scene->getPhysicsScene(), mDesc);
174
175 joint->_setOwner(PhysicsOwnerType::Component, this);
176 return joint;
177 }
178
179 RTTITypeBase* CD6Joint::getRTTIStatic()
180 {
181 return CD6JointRTTI::instance();
182 }
183
184 RTTITypeBase* CD6Joint::getRTTI() const
185 {
186 return CD6Joint::getRTTIStatic();
187 }
188}
189