20 #include "phyuniversal.h"
21 #include "private/phyjointprivate.h"
22 #include "private/phyobjectprivate.h"
23 #include "private/worldprivate.h"
29 firstDof =
new PhyDOF(
this, firstAxis, centre,
false );
31 secondDof =
new PhyDOF(
this, secondAxis, centre,
false );
67 qWarning(
"Sanity Check Failed" );
70 qWarning(
"Sanity Check Failed" );
87 #ifdef WORLDSIM_USE_NEWTON
88 priv->joint = NewtonConstraintCreateUserJoint( worldpriv->world, 6, PhyJointPrivate::userBilateralHandler, 0,
priv->child,
priv->parent );
89 NewtonJointSetUserData(
priv->joint,
this );
103 qWarning(
"Sanity Check Failed" );
106 qWarning(
"Sanity Check Failed" );
118 real angle = atan2( sinAngle, cosAngle );
119 firstDof->setPosition( angle );
128 secondDof->setAxis( tmp.z_ax );
129 secondDof->setXAxis( tmp.x_ax );
130 secondDof->setYAxis( tmp.y_ax );
134 void PhyUniversal::updateJoint( real timestep ) {
144 qWarning(
"Sanity Check Failed" );
147 qWarning(
"Sanity Check Failed" );
158 #ifdef WORLDSIM_USE_NEWTON
165 wVector dir2 = ( dir0 * dir1 );
167 wVector dir3( dir2 * dir0 );
174 wVector q0( p0 + dir3.scale(len) );
175 wVector q1( p1 + dir1.scale(len) );
178 NewtonUserJointAddLinearRow(
priv->joint, &p0[0], &p1[0], &dir0[0] );
179 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
180 NewtonUserJointAddLinearRow(
priv->joint, &p0[0], &p1[0], &dir1[0] );
181 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
182 NewtonUserJointAddLinearRow(
priv->joint, &p0[0], &p1[0], &dir2[0] );
183 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
186 NewtonUserJointAddLinearRow(
priv->joint, &q0[0], &q1[0], &dir0[0] );
187 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
200 real angle = atan2( sinAngle, cosAngle );
201 real vel = (angle - firstDof->
position()) / timestep;
202 firstDof->setPosition( angle );
203 firstDof->setVelocity( vel );
207 firstDof->
limits( lolimit, hilimit );
208 if ( angle < lolimit ) {
209 real relAngle = lolimit - angle;
211 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
213 NewtonUserJointSetRowMinimumFriction(
priv->joint, 0.0 );
214 }
else if ( angle > hilimit ) {
215 real relAngle = hilimit - angle;
217 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
219 NewtonUserJointSetRowMaximumFriction(
priv->joint, 0.0 );
222 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
223 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
224 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
225 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
229 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
230 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
231 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
232 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
240 tmp = tmp * wMatrix( wQuaternion( tmp.x_ax, angle ), wVector(0,0,0) );
242 secondDof->setAxis( tmp.z_ax );
243 secondDof->setXAxis( tmp.x_ax );
244 secondDof->setYAxis( tmp.y_ax );
263 angle = atan2( sinAngle, cosAngle );
264 vel = (angle - secondDof->
position()) / timestep;
265 secondDof->setPosition( angle );
266 secondDof->setVelocity( vel );
270 secondDof->
limits( lolimit, hilimit );
271 if ( angle < lolimit ) {
272 real relAngle = lolimit - angle;
274 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );
276 NewtonUserJointSetRowMinimumFriction(
priv->joint, 0.0 );
277 }
else if ( angle > hilimit ) {
278 real relAngle = hilimit - angle;
280 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );
282 NewtonUserJointSetRowMaximumFriction(
priv->joint, 0.0 );
285 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
286 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
287 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
288 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );
292 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
293 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
294 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
295 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );