MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / getTranslation

Method getTranslation

src/constraint/SliderJoint.cpp:129–159  ·  view source on GitHub ↗

Return the current translation value of the joint * @return The current translation distance of the joint (in meters) */

Source from the content-addressed store, hash-verified

127 * @return The current translation distance of the joint (in meters)
128 */
129decimal 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/**

Callers

nothing calls this directly

Calls 4

getBody1EntityMethod · 0.80
getBody2EntityMethod · 0.80
normalizeMethod · 0.45
dotMethod · 0.45

Tested by

no test coverage detected