#include <OMKTrajectory.h>
Inheritance diagram for OMK::Trajectory:
Protected Member Functions | |
virtual void | computeParameters () |
This part of the compute methods computes the associated data. | |
virtual bool | loadParameters (const ConfigurationParameterDescriptor *node) |
Configuration parameters loader of Trajectory. | |
Protected Attributes | |
std::vector< OMK::Type::Transform > | _targets |
The targets to follow. | |
Wm4::BSplineCurve3f * | _bSpline |
The B-spline. | |
float | _positionBetweenTargets |
Position between two points. | |
int | _currentTarget |
Current target. | |
Wm4::Vector3f | _refOrientation |
Reference orientation. | |
Type::Transform | _refPosition |
Reference position. | |
bool | _followOrientation |
Flag for orientation. | |
OMK::AttributeT< float > | _step |
The step to increase the position between two targets. | |
Private Member Functions | |
DECLARE_OBJECT_FACTORY (Trajectory) |
Configuration parameters are :
Example:
object1 { Class Trajectory Scheduling { ... } Extensions { ... } UserParams { Targets [ [[160 0 -400]] [[80 0 -540]] [[-80 0 -540]] [[-160 0 -400]] [[-80 0 -260]] [[80 0 -260]] ] // A hexagon Step 0.001 BSpline on // At least 2 points to define a B-spline Degree 2 // Ignored if BSpline is disable, the greatest it is the smoothest it is Position [[0 0 0 ][1.57 1.57 0]] } }
Extensions { offset { Class PostOffset Attribute Position Offset [[0 0 -100]] } }
Extensions { plus { Class PlusMinusFloatExtension Increment 0.001 Key ADD Attribute Step VisuName visuOgre } minus { Class PlusMinusFloatExtension Increment -0.001 Key SUBTRACT Attribute Step VisuName visuOgre } }
Definition at line 97 of file OMKTrajectory.h.
OMK::Trajectory::DECLARE_OBJECT_FACTORY | ( | Trajectory | ) | [private] |
void Trajectory::computeParameters | ( | ) | [protected, virtual] |
This part of the compute methods computes the associated data.
The inputs and outputs should work with associated data, you should use these associated data.
Reimplemented from OMK::ExtensibleSimulatedObject.
Definition at line 76 of file OMKTrajectory.cpp.
References _bSpline, _currentTarget, _followOrientation, OMK::SimplePoint::_position, _positionBetweenTargets, _refOrientation, _refPosition, _step, _targets, OMK::IAttributeT< PrmType, ModelType, AccessorType >::get(), OMK::Type::Transform::getRotate(), OMK::IAttributeT< PrmType, ModelType, AccessorType >::set(), OMK::Type::Transform::setRotate(), and OMK::Type::Transform::setTranslate().
00077 { 00078 float step = _step.get() * ( _bSpline ? 1.0f : _targets.size() ) ; 00079 // Get the increment 00080 if ( 1.0f <= _positionBetweenTargets ) 00081 { // step > 0 00082 _currentTarget = ( _currentTarget + 1 ) % _targets.size() ; 00083 _positionBetweenTargets = step ; 00084 } 00085 else if ( _positionBetweenTargets <= 0.0f ) 00086 { // step < 0 00087 _currentTarget = ( _currentTarget + _targets.size() - 1 ) % _targets.size() ; 00088 _positionBetweenTargets = 1.0f + step ; 00089 } 00090 else 00091 { 00092 _positionBetweenTargets += step ; 00093 } 00094 00095 // Get the translate and the rotate 00096 OMK::Type::Transform position( _refPosition ) ; 00097 Wm4::Vector3f orientation ; 00098 if( _bSpline ) 00099 { // For B-spline 00100 if( _followOrientation ) 00101 { 00102 Wm4::Vector3f translate ; 00103 _bSpline->Get( _positionBetweenTargets, &translate, &orientation, 0, 0 ) ; 00104 position.setTranslate( translate ) ; 00105 } 00106 else 00107 { 00108 position.setTranslate( _bSpline->GetPosition( _positionBetweenTargets ) ) ; 00109 } 00110 } 00111 else 00112 { // For segments 00113 int previousTarget( ( _currentTarget + _targets.size() - 1 ) % _targets.size() ) ; 00114 orientation = _targets[ _currentTarget ].getTranslate() - _targets[ previousTarget ].getTranslate() ; 00115 position.setTranslate( _targets[previousTarget].getTranslate() + orientation * _positionBetweenTargets ) ; 00116 } 00117 00118 if( _followOrientation ) 00119 { // Calculate the orientation 00120 orientation.Normalize() ; 00121 Wm4::Vector3f axis( orientation.Cross( _refOrientation ) ) ; 00122 axis.Normalize() ; 00123 float angle = -Wm4::Math<float>::ACos( orientation.Dot( _refOrientation ) ) ; 00124 Wm4::Matrix3f rotationMatrix( axis, angle ) ; 00125 position.setRotate( position.getRotate() * rotationMatrix ) ; 00126 } 00127 // Set the new position 00128 _position.set( position ) ; 00129 }
bool Trajectory::loadParameters | ( | const ConfigurationParameterDescriptor * | node | ) | [protected, virtual] |
Configuration parameters loader of Trajectory.
[in] | node | the root node of the configuration parameter. |
Reimplemented from OMK::ExtensibleSimulatedObject.
Definition at line 33 of file OMKTrajectory.cpp.
References _bSpline, _followOrientation, OMK::SimplePoint::_position, _refOrientation, _refPosition, _targets, OMK::IAttributeT< PrmType, ModelType, AccessorType >::get(), OMK::ParametersAccessor::get(), OMK::ExtensibleSimulatedObject::loadParameters(), OMK::IAttributeT< PrmType, ModelType, AccessorType >::set(), OMK::Type::Transform::setTranslate(), and OMK::IAttributeT< PrmType, ModelType, AccessorType >::setValueToOutput().
00034 { 00035 SimplePoint::loadParameters( node ) ; 00036 if( !ParametersAccessor::get( node, "Targets", _targets ) ) 00037 { 00038 _targets.push_back( Transform( Wm4::Vector3f( 10, 0, 10 ) ) ) ; 00039 _targets.push_back( Transform( Wm4::Vector3f( 10, 0, -10 ) ) ) ; 00040 _targets.push_back( Transform( Wm4::Vector3f( -10, 0, -10 ) ) ) ; 00041 _targets.push_back( Transform( Wm4::Vector3f( -10, 0, 10 ) ) ) ; 00042 } 00043 ParametersAccessor::get( node, "Orientation", _followOrientation ) ; 00044 bool bspline = false ; 00045 ParametersAccessor::get( node, "BSpline", bspline ) ; 00046 if( bspline && 2 <= _targets.size() ) 00047 { // At least 2 points to define a B-spline 00048 int degree = 2 ; // Default value 00049 ParametersAccessor::get( node, "Degree", degree ) ; 00050 degree = degree < (int)_targets.size() ? degree : _targets.size() - 1 ; 00051 Wm4::Vector3f* targets = new Wm4::Vector3f[ _targets.size() ] ; 00052 for( unsigned int i = 0 ; i < _targets.size() ; i++ ) 00053 { 00054 targets[ i ] = _targets[ i ].getTranslate() ; 00055 } 00056 _bSpline = new Wm4::BSplineCurve3f( _targets.size(), targets, degree, true, false ) ; 00057 delete[] targets ; 00058 _refOrientation = _bSpline->GetFirstDerivative( 0.0f ) ; 00059 _refOrientation.Normalize() ; 00060 } 00061 else 00062 { 00063 _refOrientation = _targets[ 1 ].getTranslate() - _targets[ 0 ].getTranslate() ; 00064 _refOrientation.Normalize() ; 00065 } 00066 00067 _refPosition = _position.get() ; 00068 OMK::Type::Transform position( _refPosition ) ; 00069 position.setTranslate( _targets[ 0 ].getTranslate() ) ; 00070 _position.set( position ) ; 00071 _position.setValueToOutput() ; 00072 return true ; 00073 }
std::vector< OMK::Type::Transform > OMK::Trajectory::_targets [protected] |
The targets to follow.
Definition at line 111 of file OMKTrajectory.h.
Referenced by computeParameters(), and loadParameters().
Wm4::BSplineCurve3f* OMK::Trajectory::_bSpline [protected] |
The B-spline.
This one is defined only if there is a B-spline.
Definition at line 114 of file OMKTrajectory.h.
Referenced by computeParameters(), and loadParameters().
float OMK::Trajectory::_positionBetweenTargets [protected] |
Position between two points.
Its value is in the set [0, 1[
Definition at line 117 of file OMKTrajectory.h.
Referenced by computeParameters().
int OMK::Trajectory::_currentTarget [protected] |
Wm4::Vector3f OMK::Trajectory::_refOrientation [protected] |
Reference orientation.
Definition at line 121 of file OMKTrajectory.h.
Referenced by computeParameters(), and loadParameters().
Type::Transform OMK::Trajectory::_refPosition [protected] |
Reference position.
Definition at line 123 of file OMKTrajectory.h.
Referenced by computeParameters(), and loadParameters().
bool OMK::Trajectory::_followOrientation [protected] |
Flag for orientation.
Definition at line 125 of file OMKTrajectory.h.
Referenced by computeParameters(), and loadParameters().
OMK::AttributeT< float > OMK::Trajectory::_step [protected] |
The step to increase the position between two targets.
Definition at line 128 of file OMKTrajectory.h.
Referenced by computeParameters().
Documentation generated on Mon Jun 9 11:46:04 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |