OMK::Iii::BallJoint Class Reference
[Joints]

Ball joint. More...

#include <OMKJoint.h>

Inheritance diagram for OMK::Iii::BallJoint:

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

Collaboration graph
[legend]
List of all members.

Protected Member Functions

Interface
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.

Protected Attributes

Internal parameters.
OMK::Type::Transform _newObjectPosition
 The object position computed in retroPropagation.
OMK::Type::Transform _refObjectOffset
 The reference.
bool _alreadyKnow
 Flag to avoid the calculate twice the position.
float _radius
 the radius of the ball.
Wm4::Vector3f _previousPosition
 Previous object position translate to compute the translation.
bool _reset
 Flag to reset the _previousPosition.

Private Member Functions

 DECLARE_JOINT_FACTORY (BallJoint)

Detailed Description

Ball joint.

Date:
2007-06-20
Author:
Beno� Chanclou
An object linked with this extension rotate to a constant distant form the joint position.

Parameters are the same as the lock joint.

The following configuration can be used to lock an object on an other one.

object
{
  ...
    joint
    {
      class Joint
      ...
      Joint Ball // The ball joint
      Attribute Position // The name of the attribute (by default "Position")
      ...
    }
  ...
}
If the object is translated, it try to move the reference position. If the object is rotated, it turns around the joint position.

Definition at line 278 of file OMKJoint.h.


Member Function Documentation

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

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

Initialises the link reference positions.

Reimplemented from OMK::Iii::Joint.

Definition at line 120 of file OMKJoint.cpp.

References _newObjectPosition, OMK::Iii::Joint::_objectOffset, OMK::Iii::Joint::_objectPosition, _radius, _refObjectOffset, _reset, OMK::Iii::Joint::establishLink(), OMK::IAccessorT< T >::get(), and OMK::Type::Transform::getTranslate().

00121 {
00122   Joint::establishLink() ;
00123   _radius = _objectOffset.getTranslate().Length() ;
00124   
00125     // stores the reference offset
00126   _refObjectOffset = _objectOffset ;
00127   _newObjectPosition = _objectPosition->get() ;
00128   _reset = true ;
00129 }

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

Calculates the ideal position of the reference point.

Reimplemented from OMK::Iii::Joint.

Definition at line 131 of file OMKJoint.cpp.

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

00132 {
00133   if( _reset )
00134   {
00135     _previousPosition = _objectPosition->get().getTranslate() ;
00136     _reset = false ;
00137   }
00138   // Get the joint axis and perpendicular plane
00139   Wm4::Vector3f axis( _refObjectOffset.getTranslate() ) ;
00140   axis.Normalize() ;
00141   
00142   // the reference position according to the position of the joint and the reference offset
00143   OMK::Type::Transform refObjectPosition( product( _jointPosition->get(), _refObjectOffset ) ) ;
00144   
00145   // The reference orientation
00146   Wm4::Matrix3f refOrientation = _jointPosition->get().getRotate() ;
00147   // get the new orientation
00148   Wm4::Matrix3f newOrientation = _objectPosition->get().getRotate() * ( refObjectPosition.getRotate().Transpose() * refOrientation ) ;
00149   
00150   // Only the translation
00151   bool isConstraint = _objectPosition->get().getTranslate() != refObjectPosition.getTranslate() ;
00152   
00153   // The new object position
00154   // = the position of the joint
00155   // + the position along the axis
00156   _newObjectPosition.setTranslate( _jointPosition->get().getTranslate() + ( newOrientation * axis ) * _radius ) ;
00157   _newObjectPosition.setRotate( newOrientation ) ;
00158   _alreadyKnow = true ;
00159   // update the current object offset
00160   _objectOffset = product( _jointPosition->get().inverse(), _newObjectPosition ) ;
00161   _objectOffset.updateFlags() ;
00162   _objectOffsetInverse = _objectOffset.inverse() ;
00163   _objectOffsetInverse.updateFlags() ;
00164 
00165   if( isConstraint )
00166   {
00167     // Calculates the optimal position of the reference position to retro-propagates
00168     OMK::Type::Transform newJointPosition( _jointPosition->get().getTranslate() 
00169                                         + _objectPosition->get().getTranslate() 
00170                                         - _previousPosition,
00171                                           _jointPosition->get().getRotate() ) ;
00172     _referencePosition->set( product( newJointPosition, _jointOffsetInverse ) ) ;
00173     _reset = true ;
00174   }
00175 
00176   return isConstraint ;
00177 }

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

Calculates the current position of the object.

Reimplemented from OMK::Iii::Joint.

Definition at line 179 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().

00180 {
00181   if( _alreadyKnow )
00182   {
00183     _alreadyKnow = false ;
00184     _objectPosition->set( _newObjectPosition ) ;
00185   }
00186   else
00187   {
00188     // calculates the new object position
00189     _objectPosition->set( product( _jointPosition->get(), _objectOffset ) ) ;
00190   }
00191 }


Member Data Documentation

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

The object position computed in retroPropagation.

This value is stored to optimise the compute.

Definition at line 295 of file OMKJoint.h.

Referenced by currentObjectPosition(), establishLink(), and retroPropagation().

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

The reference.

Definition at line 297 of file OMKJoint.h.

Referenced by establishLink(), and retroPropagation().

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

Flag to avoid the calculate twice the position.

Definition at line 299 of file OMKJoint.h.

Referenced by currentObjectPosition(), and retroPropagation().

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

the radius of the ball.

Its value is set during the establishLink call.

Definition at line 302 of file OMKJoint.h.

Referenced by establishLink(), and retroPropagation().

Wm4::Vector3f OMK::Iii::BallJoint::_previousPosition [protected]

Previous object position translate to compute the translation.

Definition at line 304 of file OMKJoint.h.

Referenced by retroPropagation().

bool OMK::Iii::BallJoint::_reset [protected]

Flag to reset the _previousPosition.

Definition at line 306 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