OMK::PreOffsetExtension Class Reference
[Extensions]

Extension to add an offset to a Transform attribute of the object. More...

#include <OMKOffsetExtension.h>

Inheritance diagram for OMK::PreOffsetExtension:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DECLARE_EXTENSION_FACTORY (PreOffsetExtension)
 Factory and constructor/destructor.

Protected Member Functions

Configuration loaders
virtual bool loadExtensionParameters (const ConfigurationParameterDescriptor *node)
 Configuration parameters loader of Extension.
Computation
virtual void preComputeParameters ()
 Offsets the associated attribute.

Protected Attributes

IAccessorT< OMK::Type::Transform > * _attributeAccessor
 The associated attribute.
AttributeT< OMK::Type::Transform_offset
 The offset attribute.
bool _post
 Flag to define pre or post-computing.
bool _ignoreRotate
 Flag to define if the rotate is disable, false by default.
bool _ignoreScale
 Flag to define if the scale is disable, false by default.

Detailed Description

Extension to add an offset to a Transform attribute of the object.

Date:
2007-03-15
Author:
Benoît Chanclou
Module description :
Defines an offset attribute for the object. The name of the attribute will be the same as the one of the extension. This attribute can be connected to the output of an another object. For this use OffsetConnect.

The offset can be done in the pre-compute or the post-compute step according to creation id. To choose one or the other use PreOffset (uses to offset an input) or PostOffest (uses to offset an output), as class's name in the configuration.

Example:
myObject
{ 
  Class MyObject // with a "Position" attribute
  Extensions
  {     
    offset
    {
      Class PostOffset // or PreOffset
      Attribute Position // the name of the attribute to offset
      Offset [[0 0 -100]] // the offset value (it is optional, the default is identity)
      OffsetConnect [anotherObject aTransformOutput]
    }
  }
}
 *

Definition at line 49 of file OMKOffsetExtension.h.


Member Function Documentation

OMK::PreOffsetExtension::DECLARE_EXTENSION_FACTORY ( PreOffsetExtension   ) 

Factory and constructor/destructor.

See Extension feature

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

Configuration parameters loader of Extension.

It retrieves, in the extension configuration, the offset and the name of the attribute to ofset.

Reimplemented from OMK::Extension.

Definition at line 30 of file OMKOffsetExtension.cpp.

References _attributeAccessor, _ignoreRotate, _ignoreScale, _offset, OMK::ExtensionT< SimulatedObjectType >::_owner, OMK::ParametersAccessor::get(), and OMK::IAttributeBaseT< PrmType >::loadParameters().

00032 {
00033   // Retrieve the visual objects
00034   bool ok = true ;
00035   // Offset value
00036   _offset.loadParameters( node, "Offset" ) ;
00037   // Attribute to offset
00038   Name attributeName ;
00039   ok = ok && ParametersAccessor::get( node, "Attribute", attributeName, _owner ) ;
00040   _attributeAccessor =
00041     ok ? _owner->getBaseAttribute< OMK::Type::Transform >( attributeName ) : 0 ;
00042   ok = ok && _attributeAccessor != 0 ;
00043   ParametersAccessor::get( node, "IgnoreRotate", _ignoreRotate ) ;
00044   ParametersAccessor::get( node, "IgnoreScale", _ignoreScale ) ;
00045 
00046   return ok ;
00047 }

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

Offsets the associated attribute.

Only in for the pre compute version.

Reimplemented from OMK::Extension.

Reimplemented in OMK::PostOffsetExtension.

Definition at line 49 of file OMKOffsetExtension.cpp.

References _attributeAccessor, _ignoreRotate, _ignoreScale, _offset, OMK::ExtensionT< SimulatedObjectType >::_owner, OMK::debugMsg(), OMK::IAttributeT< PrmType, ModelType, AccessorType >::get(), OMK::IAccessorT< T >::get(), OMASSERTM, and OMK::IAccessorT< T >::set().

Referenced by OMK::PostOffsetExtension::postComputeParameters().

00050 {
00051   OMASSERTM( _attributeAccessor,
00052              debugMsg( this, _owner ) << "Must be initalised !" ) ;
00053 
00054   Transform result( _attributeAccessor->get() ) ;
00055   Transform offset( _offset.get() ) ;
00056   Transform value( _attributeAccessor->get() ) ;
00057   if( offset.isIdentity() )
00058   {
00059     result = value ;
00060   }
00061   else if( value.isIdentity() )
00062   {
00063     result = offset ;
00064   }
00065   else
00066   {
00067     Wm4::Matrix3f rotate( Wm4::Matrix3f::IDENTITY ) ;
00068     if( !_ignoreRotate ) 
00069     {
00070       result.setRotate( offset.getRotate() * value.getRotate() ) ;
00071       rotate = offset.getRotate() ;
00072     }
00073 
00074     if( _ignoreScale )
00075     {
00076       result.setTranslate( rotate * value.getTranslate() +
00077                            offset.getTranslate() ) ;
00078     }
00079     else
00080     {
00081       if( offset.isUniformScale() )
00082       {
00083         result.setTranslate( offset.getUniformScale() *
00084                              ( rotate * value.getTranslate() ) +
00085                              offset.getTranslate() ) ;
00086 
00087         if ( value.isUniformScale() )
00088         {
00089           result.setUniformScale( offset.getUniformScale() *
00090                                   value.getUniformScale() ) ;
00091         }
00092         else
00093         {
00094           result.setScale( offset.getUniformScale() * value.getScale() ) ;
00095         }
00096       }
00097       else
00098       {
00099         Wm4::Vector3f v0_translate( rotate * value.getTranslate() ) ;
00100         Wm4::Vector3f v1_translate( offset.getScale()[0] * v0_translate[0],
00101                                     offset.getScale()[1] * v0_translate[1],
00102                                     offset.getScale()[2] * v0_translate[2] ) ;
00103         result.setTranslate( v1_translate + offset.getTranslate() ) ;
00104 
00105         if ( value.isUniformScale() )
00106         {
00107           result.setScale( offset.getScale() * value.getUniformScale() ) ;
00108         }
00109         else
00110         {
00111           Wm4::Vector3f v0_scale( rotate * value.getScale() ) ;
00112           Wm4::Vector3f v1_scale( offset.getScale()[0] * v0_scale[0],
00113                                   offset.getScale()[1] * v0_scale[1],
00114                                   offset.getScale()[2] * v0_scale[2] ) ;
00115           result.setScale( v1_scale ) ;
00116         }
00117       }
00118     }
00119   }
00120 
00121   _attributeAccessor->set( result ) ;
00122 }


Member Data Documentation

IAccessorT< OMK::Type::Transform >* OMK::PreOffsetExtension::_attributeAccessor [protected]

The associated attribute.

It must be defined by the configuration parameter named Attribute.

Definition at line 74 of file OMKOffsetExtension.h.

Referenced by loadExtensionParameters(), and preComputeParameters().

AttributeT< OMK::Type::Transform > OMK::PreOffsetExtension::_offset [protected]

The offset attribute.

It can be defined by the configuration parameter named Offset.

Definition at line 77 of file OMKOffsetExtension.h.

Referenced by loadExtensionParameters(), and preComputeParameters().

bool OMK::PreOffsetExtension::_post [protected]

Flag to define pre or post-computing.

Definition at line 79 of file OMKOffsetExtension.h.

bool OMK::PreOffsetExtension::_ignoreRotate [protected]

Flag to define if the rotate is disable, false by default.

Definition at line 81 of file OMKOffsetExtension.h.

Referenced by loadExtensionParameters(), and preComputeParameters().

bool OMK::PreOffsetExtension::_ignoreScale [protected]

Flag to define if the scale is disable, false by default.

Definition at line 83 of file OMKOffsetExtension.h.

Referenced by loadExtensionParameters(), and preComputeParameters().


logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007