OMK::DistanceToExtension Class Reference
[Extensions]

Calculates a distance to a target. More...

#include <OMKTriggerExtension.h>

Inheritance diagram for OMK::DistanceToExtension:

Inheritance graph
[legend]
Collaboration diagram for OMK::DistanceToExtension:

Collaboration graph
[legend]
List of all members.

Protected Member Functions

virtual bool loadExtensionParameters (const ConfigurationParameterDescriptor *node)
 Configuration parameters loader of Extension.
virtual void preComputeParameters ()
 method.

Protected Attributes

IAttributeBaseT< Type::Transform > * _target
AttributeT< float > _distance
IAccessorT< OMK::Type::Transform > * _positionAccessor
 The associated attribute.
bool _deleteTarget

Private Member Functions

 DECLARE_EXTENSION_FACTORY (DistanceToExtension)

Detailed Description

Calculates a distance to a target.

Module description :
Creates a float attribute named ExtensionIdDistance which gives the distance to a target (where ExtensionId is replaced by the id of the extension).

To find the attribute which gives the position of the target, this extension follows these steps:

The user have to connect this attribute to the position of the target. To change the target during the simulation, you can send a event to reconnect the target attribute. To do this define the parameter AttributeNameConnectByEvent or call activateConnectByEvent for the attribute, then send the connection event with the new target.

To find the attribute which gives the position of the object, this extension find the attribute id in the field PositionId the extension configuration node. By default the looked for attribute is the one named Position.

See also TriggerAttributeExtension and TriggerExtension which use this extension as their ancestor.

Configuration parameters :
Example with a tracker :
    object
    {
      Class Tracker
      Scheduling
      {
        Frequency 60
      }
      UserParams
      {
        TargetConnect [trajectory Position]
        Position [[0 0 200]]
        Speed 0.01
      }
      Extensions
      {
        reach
        {
          Class DistanceTo 
          // By default uses "Target" as target attribute and "Position" as position attribute
        }
      }
    }
Example with a simple point :
    object
    {
      Class SimplePoint
      Scheduling
      {
        Frequency 60
      }
      UserParams
      {
        Position [[0 0 200]]
      }
      Extensions
      {
        reach
        {
          Class DistanceTo 
          TargetConnect [trajectory Position]
          // By default adds a "reachTarget" attribute and uses "Position" as position attribute
        }
      }
    }

Definition at line 130 of file OMKTriggerExtension.h.


Member Function Documentation

OMK::DistanceToExtension::DECLARE_EXTENSION_FACTORY ( DistanceToExtension   )  [private]

bool DistanceToExtension::loadExtensionParameters ( const ConfigurationParameterDescriptor node  )  [protected, virtual]

Configuration parameters loader of Extension.

Parameters:
[in] node the root node of the configuration parameter, null if no node defined for the extension.
Returns:
should return true if all the parameters are well retrieved.
Overwrite this method to initialise the extension. This method allows the extension to get parameters of its own field.
Be careful, loadObjectParameters method is called before this method.
See How to configure an extension ? for details.

Reimplemented from OMK::Extension.

Reimplemented in OMK::TriggerBaseExtension, OMK::TriggerAttributeExtension, and OMK::TriggerExtension.

Definition at line 67 of file OMKTriggerExtension.cpp.

References _deleteTarget, _distance, OMK::ExtensionT< OMK::ExtensibleSimulatedObject >::_owner, _positionAccessor, _target, OMK::ParametersAccessor::get(), OMK::ExtensibleSimulatedObject::getBaseAttribute(), and OMK::IAttributeBaseT< PrmType >::loadParameters().

Referenced by OMK::TriggerBaseExtension::loadExtensionParameters().

00068 {
00069   // Retrieve all the parameters
00070   Name attributeName( "Position" ) ;
00071   ParametersAccessor::get( node, "PositionId", attributeName ) ;
00072   _positionAccessor = _owner->getBaseAttribute< OMK::Type::Transform >( attributeName ) ;
00073   if( _deleteTarget )
00074   {
00075     _target->loadParameters( node, "Target" ) ;
00076   }
00077   _distance.loadParameters( node, "Distance" ) ;
00078 
00079   return _positionAccessor != 0 ;
00080 }

void DistanceToExtension::preComputeParameters (  )  [protected, virtual]

method.

This method is called by the extensible simulated object at each compute step. Its call takes place in the compute method just after the inputs were retrieved by the computeInputs method and before the output parameters will be computed by the computeParameters

Reimplemented from OMK::Extension.

Reimplemented in OMK::TriggerBaseExtension.

Definition at line 82 of file OMKTriggerExtension.cpp.

References _distance, _positionAccessor, _target, OMK::IAccessorT< T >::get(), OMK::Type::Transform::getTranslate(), and OMK::IAttributeT< PrmType, ModelType, AccessorType >::set().

Referenced by OMK::TriggerBaseExtension::preComputeParameters().

00083 {
00084   Wm4::Vector3f target( _target->get().getTranslate() ) ;  
00085   Wm4::Vector3f pos( _positionAccessor->get().getTranslate() ) ;  
00086   float deltaX = target.X() - pos.X() ;
00087   float deltaY = target.Y() - pos.Y() ;
00088   float deltaZ = target.Z() - pos.Z() ;
00089   _distance.set( sqrt( deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ ) ) ;
00090 }


Member Data Documentation

IAttributeBaseT< Type::Transform >* OMK::DistanceToExtension::_target [protected]

Definition at line 136 of file OMKTriggerExtension.h.

Referenced by loadExtensionParameters(), and preComputeParameters().

AttributeT< float > OMK::DistanceToExtension::_distance [protected]

Definition at line 137 of file OMKTriggerExtension.h.

Referenced by loadExtensionParameters(), OMK::TriggerBaseExtension::preComputeParameters(), and preComputeParameters().

IAccessorT< OMK::Type::Transform >* OMK::DistanceToExtension::_positionAccessor [protected]

The associated attribute.

It must be defined by the configuration parameter named AttributeId.

Definition at line 140 of file OMKTriggerExtension.h.

Referenced by loadExtensionParameters(), and preComputeParameters().

bool OMK::DistanceToExtension::_deleteTarget [protected]

Definition at line 141 of file OMKTriggerExtension.h.

Referenced by loadExtensionParameters().


logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007