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 );
68 qWarning(
"Sanity Check Failed" );
71 qWarning(
"Sanity Check Failed" );
93 #ifdef WORLDSIM_USE_NEWTON
94 priv->joint = NewtonConstraintCreateUserJoint( worldpriv->world, 6, PhyJointPrivate::userBilateralHandler, 0,
priv->child,
priv->parent );
95 NewtonJointSetUserData(
priv->joint,
this );
109 qWarning(
"Sanity Check Failed" );
112 qWarning(
"Sanity Check Failed" );
124 real angle = atan2( sinAngle, cosAngle );
125 firstDof->setPosition( angle );
134 secondDof->setAxis( tmp.z_ax );
135 secondDof->setXAxis( tmp.x_ax );
136 secondDof->setYAxis( tmp.y_ax );
140 void PhyUniversal::updateJoint( real timestep ) {
150 qWarning(
"Sanity Check Failed" );
153 qWarning(
"Sanity Check Failed" );
164 #ifdef WORLDSIM_USE_NEWTON
171 wVector dir2 = ( dir0 * dir1 );
173 wVector dir3( dir2 * dir0 );
180 wVector q0( p0 + dir3.scale(len) );
181 wVector q1( p1 + dir1.scale(len) );
184 NewtonUserJointAddLinearRow(
priv->joint, &p0[0], &p1[0], &dir0[0] );
185 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
186 NewtonUserJointAddLinearRow(
priv->joint, &p0[0], &p1[0], &dir1[0] );
187 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
188 NewtonUserJointAddLinearRow(
priv->joint, &p0[0], &p1[0], &dir2[0] );
189 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
192 NewtonUserJointAddLinearRow(
priv->joint, &q0[0], &q1[0], &dir0[0] );
193 NewtonUserJointSetRowStiffness(
priv->joint, 1.0 );
206 real angle = atan2( sinAngle, cosAngle );
207 real vel = (angle - firstDof->
position()) / timestep;
208 firstDof->setPosition( angle );
209 firstDof->setVelocity( vel );
213 firstDof->
limits( lolimit, hilimit );
214 if ( angle < lolimit ) {
215 real relAngle = lolimit - angle;
217 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
219 NewtonUserJointSetRowMinimumFriction(
priv->joint, 0.0 );
220 }
else if ( angle > hilimit ) {
221 real relAngle = hilimit - angle;
223 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
225 NewtonUserJointSetRowMaximumFriction(
priv->joint, 0.0 );
228 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
229 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
230 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
231 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
235 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
236 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
237 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
238 NewtonUserJointSetRowStiffness(
priv->joint, firstDof->
stiffness() );
246 tmp = tmp * wMatrix( wQuaternion( tmp.x_ax, angle ), wVector(0,0,0) );
248 secondDof->setAxis( tmp.z_ax );
249 secondDof->setXAxis( tmp.x_ax );
250 secondDof->setYAxis( tmp.y_ax );
269 angle = atan2( sinAngle, cosAngle );
270 vel = (angle - secondDof->
position()) / timestep;
271 secondDof->setPosition( angle );
272 secondDof->setVelocity( vel );
276 secondDof->
limits( lolimit, hilimit );
277 if ( angle < lolimit ) {
278 real relAngle = lolimit - angle;
280 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );
282 NewtonUserJointSetRowMinimumFriction(
priv->joint, 0.0 );
283 }
else if ( angle > hilimit ) {
284 real relAngle = hilimit - angle;
286 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );
288 NewtonUserJointSetRowMaximumFriction(
priv->joint, 0.0 );
291 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
292 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
293 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
294 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );
298 NewtonUserJointSetRowMinimumFriction(
priv->joint, -force );
299 NewtonUserJointSetRowMaximumFriction(
priv->joint, +force );
300 NewtonUserJointSetRowAcceleration(
priv->joint, accel );
301 NewtonUserJointSetRowStiffness(
priv->joint, secondDof->
stiffness() );