Return the current translation value of the joint * @return The current translation distance of the joint (in meters) */
| 127 | * @return The current translation distance of the joint (in meters) |
| 128 | */ |
| 129 | decimal SliderJoint::getTranslation() const { |
| 130 | |
| 131 | // TODO : Check if we need to compare rigid body position or center of mass here |
| 132 | |
| 133 | // Get the bodies entities |
| 134 | const Entity body1Entity = mWorld.mJointsComponents.getBody1Entity(mEntity); |
| 135 | const Entity body2Entity = mWorld.mJointsComponents.getBody2Entity(mEntity); |
| 136 | |
| 137 | // Get the bodies positions and orientations |
| 138 | const Transform& transform1 = mWorld.mTransformComponents.getTransform(body1Entity); |
| 139 | const Transform& transform2 = mWorld.mTransformComponents.getTransform(body2Entity); |
| 140 | |
| 141 | const Vector3& x1 = transform1.getPosition(); |
| 142 | const Vector3& x2 = transform2.getPosition(); |
| 143 | const Quaternion& q1 = transform1.getOrientation(); |
| 144 | const Quaternion& q2 = transform2.getOrientation(); |
| 145 | |
| 146 | // Compute the two anchor points in world-space coordinates |
| 147 | const Vector3 anchorBody1 = x1 + q1 * mWorld.mSliderJointsComponents.getLocalAnchorPointBody1(mEntity); |
| 148 | const Vector3 anchorBody2 = x2 + q2 * mWorld.mSliderJointsComponents.getLocalAnchorPointBody2(mEntity); |
| 149 | |
| 150 | // Compute the vector u (difference between anchor points) |
| 151 | const Vector3 u = anchorBody2 - anchorBody1; |
| 152 | |
| 153 | // Compute the slider axis in world-space |
| 154 | Vector3 sliderAxisWorld = q1 * mWorld.mSliderJointsComponents.getSliderAxisBody1(mEntity); |
| 155 | sliderAxisWorld.normalize(); |
| 156 | |
| 157 | // Compute and return the translation value |
| 158 | return u.dot(sliderAxisWorld); |
| 159 | } |
| 160 | |
| 161 | // Set the minimum translation limit |
| 162 | /** |
nothing calls this directly
no test coverage detected