OMK::Iii::HingeSlideJoint Class Reference

#include <OMKJoint.h>

Inheritance diagram for OMK::Iii::HingeSlideJoint:

Inheritance graph
[legend]
Collaboration diagram for OMK::Iii::HingeSlideJoint:

Collaboration graph
[legend]
List of all members.

Protected Member Functions

virtual void establishLink ()
 Initialises the link reference positions.
virtual bool retroPropagation ()
 Calculates the ideal position of the reference point.
virtual void currentObjectPosition ()
 Calculates the current position of the object.
virtual bool computeConstraints (float &angle, float &currentSlide, Wm4::Matrix3f &overRotationMatrix, float &overSlide, Wm4::Vector3f &newOrientation, const Wm4::Vector3f &refOrientation, const Wm4::Vector3f &axis)

Protected Attributes

OMK::Type::Transform _newObjectPosition
OMK::Type::Transform _refObjectOffset
bool _alreadyKnow
Initialisation.
float _radius
float _refSlide
Parameters.
float _minSlide
float _maxSlide
bool _minSlideEnable
bool _maxSlideEnable
float _minAngle
float _maxAngle
bool _angleEnable
bool _rotateOnly
bool _ignoreTranslate

Private Member Functions

 DECLARE_JOINT_FACTORY (HingeSlideJoint)

Detailed Description

Definition at line 311 of file OMKJoint.h.


Member Function Documentation

OMK::Iii::HingeSlideJoint::DECLARE_JOINT_FACTORY ( HingeSlideJoint   )  [private]

void OMK::Iii::HingeSlideJoint::establishLink (  )  [protected, virtual]

Initialises the link reference positions.

Reimplemented from OMK::Iii::Joint.

Reimplemented in OMK::Iii::ScrewJoint.

Definition at line 229 of file OMKJoint.cpp.

References _ignoreTranslate, OMK::Iii::Joint::_jointPosition, OMK::Iii::Joint::_objectOffset, OMK::Iii::Joint::_objectPosition, _radius, _refObjectOffset, _refSlide, _rotateOnly, OMK::Iii::Joint::establishLink(), OMK::IAccessorT< T >::get(), OMK::Type::Transform::getTranslate(), and OMK::Type::Transform::getUp().

Referenced by OMK::Iii::ScrewJoint::establishLink().

00230 {
00231   Joint::establishLink() ;
00232   // Get the joint plane
00233   Wm4::Vector3f axis( _jointPosition->get().getUp() ) ;
00234   axis.Normalize() ;
00235   Wm4::Plane3f plane( axis, _jointPosition->get().getTranslate() ) ;
00236   // The reference slide position
00237     // projection of the current position over the plane perpendicular to the joint axis
00238     Wm4::IntrLine3Plane3f objectOnPlane( Wm4::Line3f( _objectPosition->get().getTranslate(), axis ), plane ) ;
00239     objectOnPlane.Find() ;
00240     // to get the reference slide position
00241     _refSlide = objectOnPlane.GetLineT() ;
00242     // to get the radius on the plane
00243     Wm4::Vector3f projection( _objectPosition->get().getTranslate() + _refSlide * axis ) ;
00244     Wm4::Vector3f radiusVector( projection - _jointPosition->get().getTranslate() ) ;
00245     _radius = radiusVector.Length() ;
00246     _ignoreTranslate = ( _radius < Wm4::Math<float>::ZERO_TOLERANCE ) || _rotateOnly ;
00247 
00248     // stores the reference offset
00249     _refObjectOffset = _objectOffset ;
00250 }

bool OMK::Iii::HingeSlideJoint::retroPropagation (  )  [protected, virtual]

Calculates the ideal position of the reference point.

Reimplemented from OMK::Iii::Joint.

Definition at line 252 of file OMKJoint.cpp.

References _alreadyKnow, _ignoreTranslate, OMK::Iii::Joint::_jointOffsetInverse, OMK::Iii::Joint::_jointPosition, _newObjectPosition, OMK::Iii::Joint::_objectOffset, OMK::Iii::Joint::_objectOffsetInverse, OMK::Iii::Joint::_objectPosition, _radius, OMK::Iii::Joint::_referencePosition, _refObjectOffset, _refSlide, computeConstraints(), OMK::IAccessorT< T >::get(), OMK::Type::Transform::getRight(), OMK::Type::Transform::getRotate(), OMK::Type::Transform::getTranslate(), OMK::Type::Transform::getUp(), OMK::Type::Transform::inverse(), OMK::Type::product(), OMK::IAccessorT< T >::set(), OMK::Type::Transform::setRotate(), OMK::Type::Transform::setTranslate(), and OMK::Type::Transform::updateFlags().

00253 {
00254   // Get the joint axis and perpendicular plane
00255   Wm4::Vector3f axis( _jointPosition->get().getUp() ) ;
00256   axis.Normalize() ;
00257   Wm4::Plane3f plane( axis, _jointPosition->get().getTranslate() ) ;
00258   // the reference position according to the position of the joint and the reference offset
00259   OMK::Type::Transform refObjectPosition( product( _jointPosition->get(), _refObjectOffset ) ) ;
00260   float currentSlide = 0.0f ;
00261   Wm4::Vector3f refOrientation ;
00262   Wm4::Vector3f newOrientation ;
00263   
00264   if( _ignoreTranslate )
00265   { // The axis is on the object position, only rotate
00266     // get a reference position over the joint plane
00267     refOrientation = _jointPosition->get().getRight() ;
00268     // get the new orientation
00269     newOrientation = _objectPosition->get().getRotate() * ( refObjectPosition.getRotate().Transpose() * _jointPosition->get().getRight() ) ;
00270     
00271     // the new slide offset
00272     currentSlide = axis.Dot( _jointPosition->get().getTranslate() - _objectPosition->get().getTranslate() ) - _refSlide ;
00273     
00274   }
00275   else
00276   { // The axis is far of the object position, only translate
00277     
00278     // projection of the reference position over the joint plane
00279     Wm4::Vector3f refIntersection( refObjectPosition.getTranslate() + _refSlide * axis ) ;
00280     // reference orientation
00281     refOrientation = refIntersection - _jointPosition->get().getTranslate() ;
00282     refOrientation.Normalize() ;
00283     
00284     // projection of the current position over the joint plane
00285     Wm4::IntrLine3Plane3f objectOnPlane( Wm4::Line3f( _objectPosition->get().getTranslate(), axis ), plane ) ;
00286     objectOnPlane.Find() ;
00287     // the new slide offset
00288     float currentSlideOverThePlane = objectOnPlane.GetLineT() ;
00289     
00290     // The new orientation
00291     Wm4::Vector3f projection( _objectPosition->get().getTranslate() + currentSlideOverThePlane * axis ) ;
00292     newOrientation = projection - _jointPosition->get().getTranslate() ;
00293     newOrientation.Normalize() ;
00294     
00295     // the new slide offset
00296     currentSlide = currentSlideOverThePlane - _refSlide ;
00297   }  
00298   
00299   // Compute the angle between the reference and the new orientation
00300   float angle = Wm4::Math<float>::ACos( newOrientation.Dot( refOrientation ) ) 
00301       * ( axis.Dot( newOrientation.Cross( refOrientation ) ) < 0.0f ? 1.0f : -1.0f ) ;
00302   
00303   Wm4::Matrix3f overRotationMatrix( Wm4::Matrix3f::IDENTITY ) ;
00304   float overSlide = 0.0f ;
00305   bool isConstraint = computeConstraints( angle, currentSlide, 
00306                                           overRotationMatrix, overSlide, newOrientation, 
00307                                           refOrientation, axis ) ; 
00308   
00309   // The new object position
00310   // = the position of the joint
00311   // + the position on the plane of the joint
00312   // + the position along the axis
00313   _newObjectPosition.setTranslate( _jointPosition->get().getTranslate() + newOrientation * _radius - ( _refSlide + currentSlide ) * axis ) ;
00314   // the rotation of the object compared to the position of reference
00315   Wm4::Matrix3f rotationMatrix( axis, angle ) ;
00316   _newObjectPosition.setRotate( rotationMatrix * refObjectPosition.getRotate() ) ;
00317   _alreadyKnow = true ;
00318   // update the current object offset
00319   _objectOffset = product( _jointPosition->get().inverse(), _newObjectPosition ) ;
00320   _objectOffset.updateFlags() ;
00321   _objectOffsetInverse = _objectOffset.inverse() ;
00322   _objectOffsetInverse.updateFlags() ;
00323 
00324   if( isConstraint )
00325   {
00326     // Calculates the optimal position of the reference position to retro-propagates
00327     OMK::Type::Transform newJointPosition( _jointPosition->get().getTranslate() - overSlide * axis, overRotationMatrix * _jointPosition->get().getRotate() ) ;
00328     _referencePosition->set( product( newJointPosition, _jointOffsetInverse ) ) ;
00329   }
00330 
00331   return isConstraint ;
00332 }

void OMK::Iii::HingeSlideJoint::currentObjectPosition (  )  [protected, virtual]

Calculates the current position of the object.

Reimplemented from OMK::Iii::Joint.

Definition at line 379 of file OMKJoint.cpp.

References _alreadyKnow, OMK::Iii::Joint::_jointPosition, _newObjectPosition, OMK::Iii::Joint::_objectOffset, OMK::Iii::Joint::_objectPosition, OMK::IAccessorT< T >::get(), OMK::Type::product(), and OMK::IAccessorT< T >::set().

00380 {
00381   if( _alreadyKnow )
00382   {
00383     _alreadyKnow = false ;
00384     _objectPosition->set( _newObjectPosition ) ;
00385   }
00386   else
00387   {
00388     // calculates the new object position
00389     _objectPosition->set( product( _jointPosition->get(), _objectOffset ) ) ;
00390   }
00391 }

bool OMK::Iii::HingeSlideJoint::computeConstraints ( float &  angle,
float &  currentSlide,
Wm4::Matrix3f &  overRotationMatrix,
float &  overSlide,
Wm4::Vector3f &  newOrientation,
const Wm4::Vector3f &  refOrientation,
const Wm4::Vector3f &  axis 
) [protected, virtual]

Reimplemented in OMK::Iii::ScrewJoint.

Definition at line 334 of file OMKJoint.cpp.

References _angleEnable, _maxAngle, _maxSlide, _maxSlideEnable, _minAngle, _minSlide, and _minSlideEnable.

Referenced by retroPropagation().

00338 {
00339   bool isConstraint = false ; 
00340   overRotationMatrix.MakeIdentity() ;
00341   overSlide = 0.0f ;
00342   // Compute the constraint
00343   if( _angleEnable )
00344   {
00345     if( angle < _minAngle )
00346     {
00347       overRotationMatrix.FromAxisAngle( axis, angle - _minAngle ) ;
00348       angle = _minAngle ;
00349       isConstraint = true ;
00350     }
00351     else if( _maxAngle < angle )
00352     {
00353       overRotationMatrix.FromAxisAngle( axis, angle - _maxAngle ) ;
00354       angle = _maxAngle ;
00355       isConstraint = true ;
00356     }
00357     if( isConstraint )
00358     {
00359       newOrientation = Wm4::Matrix3f( axis, angle ) * refOrientation ;
00360     }
00361   }
00362     
00363   // Compute the constraint
00364   if( _minSlideEnable && ( currentSlide < _minSlide ) )
00365   {
00366     overSlide = currentSlide - _minSlide ;
00367     currentSlide = _minSlide ;
00368     isConstraint = true ;
00369   }
00370   else if( _maxSlideEnable && ( _maxSlide < currentSlide ) )
00371   {
00372     overSlide = currentSlide - _maxSlide ;
00373     currentSlide = _maxSlide ;
00374     isConstraint = true ;
00375   }
00376   return isConstraint ;
00377 }


Member Data Documentation

OMK::Type::Transform OMK::Iii::HingeSlideJoint::_newObjectPosition [protected]

Definition at line 322 of file OMKJoint.h.

Referenced by currentObjectPosition(), and retroPropagation().

OMK::Type::Transform OMK::Iii::HingeSlideJoint::_refObjectOffset [protected]

Definition at line 323 of file OMKJoint.h.

Referenced by establishLink(), and retroPropagation().

bool OMK::Iii::HingeSlideJoint::_alreadyKnow [protected]

Definition at line 324 of file OMKJoint.h.

Referenced by currentObjectPosition(), and retroPropagation().

float OMK::Iii::HingeSlideJoint::_radius [protected]

Definition at line 327 of file OMKJoint.h.

Referenced by establishLink(), and retroPropagation().

float OMK::Iii::HingeSlideJoint::_refSlide [protected]

Definition at line 328 of file OMKJoint.h.

Referenced by establishLink(), and retroPropagation().

float OMK::Iii::HingeSlideJoint::_minSlide [protected]

Definition at line 332 of file OMKJoint.h.

Referenced by OMK::Iii::ScrewJoint::computeConstraints(), and computeConstraints().

float OMK::Iii::HingeSlideJoint::_maxSlide [protected]

Definition at line 333 of file OMKJoint.h.

Referenced by OMK::Iii::ScrewJoint::computeConstraints(), and computeConstraints().

bool OMK::Iii::HingeSlideJoint::_minSlideEnable [protected]

Definition at line 334 of file OMKJoint.h.

Referenced by OMK::Iii::ScrewJoint::computeConstraints(), and computeConstraints().

bool OMK::Iii::HingeSlideJoint::_maxSlideEnable [protected]

Definition at line 335 of file OMKJoint.h.

Referenced by OMK::Iii::ScrewJoint::computeConstraints(), and computeConstraints().

float OMK::Iii::HingeSlideJoint::_minAngle [protected]

Definition at line 336 of file OMKJoint.h.

Referenced by computeConstraints().

float OMK::Iii::HingeSlideJoint::_maxAngle [protected]

Definition at line 337 of file OMKJoint.h.

Referenced by computeConstraints().

bool OMK::Iii::HingeSlideJoint::_angleEnable [protected]

Definition at line 338 of file OMKJoint.h.

Referenced by computeConstraints().

bool OMK::Iii::HingeSlideJoint::_rotateOnly [protected]

Definition at line 339 of file OMKJoint.h.

Referenced by establishLink().

bool OMK::Iii::HingeSlideJoint::_ignoreTranslate [protected]

Definition at line 340 of file OMKJoint.h.

Referenced by establishLink(), and retroPropagation().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:04 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007