#include <OMKJoint.h>
Inheritance diagram for OMK::Iii::ScrewJoint:
Protected Types | |
enum | States { NOSCREW, SCREW, UNSCREW, IS_MIN, IS_MAX } |
Protected Member Functions | |
virtual void | establishLink () |
Initialises the link reference positions. | |
virtual bool | computeConstraints (float &angle, float ¤tSlide, Wm4::Matrix3f &overRotationMatrix, float &overSlide, Wm4::Vector3f &newOrientation, const Wm4::Vector3f &refOrientation, const Wm4::Vector3f &axis) |
float | computeConstraintAngle (float &angle, const float ¤tSlide, Wm4::Vector3f &newOrientation, const Wm4::Vector3f &refOrientation, const Wm4::Vector3f &axis) |
Protected Attributes | |
States | _state |
States | _stateMin |
States | _stateMax |
float | _previousAngle |
float | _turns |
Wm4::Vector3f | _previousOrientation |
Parameters. | |
float | _pitch |
bool | _reverse |
Private Member Functions | |
DECLARE_JOINT_FACTORY (ScrewJoint) |
Definition at line 349 of file OMKJoint.h.
enum OMK::Iii::ScrewJoint::States [protected] |
OMK::Iii::ScrewJoint::DECLARE_JOINT_FACTORY | ( | ScrewJoint | ) | [private] |
void OMK::Iii::ScrewJoint::establishLink | ( | ) | [protected, virtual] |
Initialises the link reference positions.
Reimplemented from OMK::Iii::HingeSlideJoint.
Definition at line 423 of file OMKJoint.cpp.
References OMK::Iii::Joint::_jointPosition, _previousAngle, _previousOrientation, _state, _turns, OMK::Iii::HingeSlideJoint::establishLink(), OMK::IAccessorT< T >::get(), OMK::Type::Transform::getRight(), and NOSCREW.
00424 { 00425 _turns = 0.0f ; 00426 _previousAngle = 0.0f ; 00427 _state = NOSCREW ; 00428 HingeSlideJoint::establishLink() ; 00429 _previousOrientation = _jointPosition->get().getRight() ; 00430 }
bool OMK::Iii::ScrewJoint::computeConstraints | ( | float & | angle, | |
float & | currentSlide, | |||
Wm4::Matrix3f & | overRotationMatrix, | |||
float & | overSlide, | |||
Wm4::Vector3f & | newOrientation, | |||
const Wm4::Vector3f & | refOrientation, | |||
const Wm4::Vector3f & | axis | |||
) | [protected, virtual] |
Reimplemented from OMK::Iii::HingeSlideJoint.
Definition at line 432 of file OMKJoint.cpp.
References OMK::Iii::HingeSlideJoint::_maxSlide, OMK::Iii::HingeSlideJoint::_maxSlideEnable, OMK::Iii::HingeSlideJoint::_minSlide, OMK::Iii::HingeSlideJoint::_minSlideEnable, _pitch, _previousAngle, _previousOrientation, _reverse, _state, _stateMax, _stateMin, _turns, computeConstraintAngle(), IS_MAX, IS_MIN, NOSCREW, SCREW, and UNSCREW.
00436 { 00437 overRotationMatrix.MakeIdentity() ; 00438 overSlide = 0.0f ; 00439 bool isConstraint = false ; 00440 if( _reverse ) 00441 { // angle is a function of the slide 00442 // Compute the constraint 00443 if( _minSlideEnable && ( currentSlide < _minSlide ) ) 00444 { 00445 overSlide = currentSlide - _minSlide ; 00446 currentSlide = _minSlide ; 00447 isConstraint = true ; 00448 } 00449 else if( _maxSlideEnable && ( _maxSlide < currentSlide ) ) 00450 { 00451 overSlide = currentSlide - _maxSlide ; 00452 currentSlide = _maxSlide ; 00453 isConstraint = true ; 00454 } 00455 // The angle is only a function of the slide offset 00456 angle = currentSlide / _pitch * -Wm4::Math<float>::TWO_PI ; 00457 newOrientation = Wm4::Matrix3f( axis, angle ) * refOrientation ; 00458 } 00459 else 00460 { // slide is a function of the angle 00461 // Computes the angle between the previous and the new orientation to determine if it screws or unscrews 00462 float screw = axis.Dot( newOrientation.Cross( _previousOrientation ) ) ; 00463 switch( _state ) 00464 { 00465 case NOSCREW : 00466 if( Wm4::Math<float>::ZERO_TOLERANCE < screw ) _state = SCREW ; 00467 else if( screw < -Wm4::Math<float>::ZERO_TOLERANCE ) _state = UNSCREW ; 00468 // Calculates the slide 00469 currentSlide = ( _turns + angle * -Wm4::Math<float>::INV_TWO_PI ) * _pitch ; 00470 break ; 00471 case SCREW : 00472 case UNSCREW : 00473 if( Wm4::Math<float>::ZERO_TOLERANCE < screw ) 00474 { 00475 _state = SCREW ; 00476 if( _previousAngle < angle ) _turns += 1.0f ; 00477 } 00478 else if( screw < -Wm4::Math<float>::ZERO_TOLERANCE ) 00479 { 00480 _state = UNSCREW ; 00481 if( angle < _previousAngle ) _turns -= 1.0f ; 00482 } 00483 else _state = NOSCREW ; 00484 // Calculates the slide 00485 currentSlide = ( _turns + angle * -Wm4::Math<float>::INV_TWO_PI ) * _pitch ; 00486 // Applies the constraintes 00487 if( _state == _stateMin && _minSlideEnable && ( currentSlide < _minSlide ) ) 00488 { 00489 _state = IS_MIN ; 00490 computeConstraintAngle( angle, _minSlide, newOrientation, refOrientation, axis ) ; 00491 } 00492 else if( _state == _stateMax && _maxSlideEnable && ( _maxSlide < currentSlide ) ) 00493 { 00494 _state = IS_MAX ; 00495 computeConstraintAngle( angle, _maxSlide, newOrientation, refOrientation, axis ) ; 00496 } 00497 break ; 00498 case IS_MIN : 00499 { 00500 if( -Wm4::Math<float>::ZERO_TOLERANCE < screw ) _state = NOSCREW ; 00501 // The angle is only a function of the slide offset 00502 currentSlide = _minSlide ; 00503 overRotationMatrix.FromAxisAngle( axis, angle - computeConstraintAngle( angle, currentSlide, newOrientation, refOrientation, axis ) ) ; 00504 isConstraint = true ; 00505 } 00506 break ; 00507 case IS_MAX : 00508 { 00509 if( screw < Wm4::Math<float>::ZERO_TOLERANCE) _state = NOSCREW ; 00510 // The angle is only a function of the slide offset 00511 currentSlide = _maxSlide ; 00512 overRotationMatrix.FromAxisAngle( axis, angle - computeConstraintAngle( angle, currentSlide, newOrientation, refOrientation, axis ) ) ; 00513 isConstraint = true ; 00514 } 00515 break ; 00516 } 00517 // min and max slide saturation 00518 if( _minSlideEnable && ( currentSlide < _minSlide ) ) 00519 { 00520 currentSlide = _minSlide ; 00521 } 00522 else if( _maxSlideEnable && ( _maxSlide < currentSlide ) ) 00523 { 00524 currentSlide = _maxSlide ; 00525 } 00526 _turns = currentSlide / _pitch + angle * Wm4::Math<float>::INV_TWO_PI ; 00527 // Stores current values which will be the previous ones of the next step 00528 _previousAngle = angle ; 00529 _previousOrientation = newOrientation ; 00530 } 00531 00532 return isConstraint ; 00533 }
float OMK::Iii::ScrewJoint::computeConstraintAngle | ( | float & | angle, | |
const float & | currentSlide, | |||
Wm4::Vector3f & | newOrientation, | |||
const Wm4::Vector3f & | refOrientation, | |||
const Wm4::Vector3f & | axis | |||
) | [protected] |
Definition at line 534 of file OMKJoint.cpp.
References _pitch.
Referenced by computeConstraints().
00537 { 00538 float constraintAngle = currentSlide / _pitch * -Wm4::Math<float>::TWO_PI ; 00539 if( constraintAngle < 0.0f ) 00540 { 00541 constraintAngle = Wm4::Math<float>::FMod( -constraintAngle + Wm4::Math<float>::TWO_PI + Wm4::Math<float>::PI, Wm4::Math<float>::TWO_PI ) - Wm4::Math<float>::PI ; 00542 } 00543 else 00544 { 00545 constraintAngle = Wm4::Math<float>::FMod( constraintAngle + Wm4::Math<float>::PI, Wm4::Math<float>::TWO_PI ) - Wm4::Math<float>::PI ; 00546 } 00547 newOrientation = Wm4::Matrix3f( axis, constraintAngle ) * refOrientation ; 00548 angle = constraintAngle ; 00549 return constraintAngle ; 00550 }
float OMK::Iii::ScrewJoint::_pitch [protected] |
Definition at line 357 of file OMKJoint.h.
Referenced by computeConstraintAngle(), and computeConstraints().
bool OMK::Iii::ScrewJoint::_reverse [protected] |
States OMK::Iii::ScrewJoint::_state [protected] |
States OMK::Iii::ScrewJoint::_stateMin [protected] |
States OMK::Iii::ScrewJoint::_stateMax [protected] |
float OMK::Iii::ScrewJoint::_previousAngle [protected] |
float OMK::Iii::ScrewJoint::_turns [protected] |
Wm4::Vector3f OMK::Iii::ScrewJoint::_previousOrientation [protected] |
Documentation generated on Mon Jun 9 11:46:04 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |