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 );
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() );
void limits(real &lo, real &hi) const
return the limits
wVector forceOnJoint
The force applied to this joint.
static wMatrix identity()
create an identity matrix
wMatrix localMatrixParent
Local frame of the joint respect to the parent matrix.
wMatrix inverse() const
calculate the inverse of transformation matrix
wVectorT & normalize()
Normalize the vector.
real position() const
return the actual position of bodies For rotational DOF is the angle of rotation For linear DOF is t...
virtual void updateJointInfo()
Update the Joint informations (each PhyDOF will be updated)
const wMatrix & matrix() const
return a reference to the transformation matrix
bool sanityCheck()
return true if the transformation matrix is valid
QVector< PhyDOF * > dofsv
vector of DOF's joint
PhyJointPrivate * priv
Engine encapsulation.
void sanitifize()
change the matrix in order to get a valid one that represent the same rotation/translation ...
real appliedForce() const
Return the Force/Torque applied using applyForce.
real stiffness() const
return the stiffness
virtual PhyObject * parent()
Return the parent object; (NULL means an object attached to static world; see Netwon Documentation) ...
void createPrivateJoint()
Engine encapsulation.
wMatrix globalMatrixParent
Global Matrix respect to Parent.
virtual wVector centre()
Return the centre of this joint in world coordinate.
PhyUniversal(const wVector &firstAxis, const wVector &secondAxis, const wVector ¢re, PhyObject *parent, PhyObject *child, bool cp=true)
Constructor.
virtual PhyObject * child()
Return the child object attached to this joint (see Newton Documentation)
wMatrix localMatrixChild
Local frame of the joint respect to the child matrix.
virtual wVector getForceOnJoint() const
Returns the force applied to this joint.
wMatrix globalMatrixChild
Global Matrix respect to Child.
bool isLimited() const
return true if rotation/translation are limited