00001 #include "OMKOrbit.h" 00002 #include "OMKParametersAccessor.inl" 00003 #include "OMKAttribute.inl" 00004 #include "OMKTracer.h" 00005 #include "Wm4BSplineCurve3.h" 00006 #include "OMKTransformType.h" 00007 00008 using namespace OMK ; 00009 using namespace OMK::Type ; 00010 00011 //------------------------------------------------------------------------- 00012 REGISTER_OBJECT_FACTORY( Orbit, "Orbit" ) ; 00013 //----------------------------------------------------------------------------- 00014 00015 Orbit::Orbit( Controller& ctrl, const ObjectDescriptor& objectDescriptor ) 00016 : OMK::SimplePoint( ctrl, objectDescriptor ), 00017 _angle( 0.0f ), 00018 _planetAngle( 0.0f ), 00019 _speed( "TimeScale", 0.0f ), 00020 _radius( "Radius", 1.0f ), 00021 _period( "Period", 1.0f ), 00022 _planetPeriod( "PlanetPeriod", 1.0f ) 00023 { 00024 addAttribute( _speed ) ; 00025 addAttribute( _radius ) ; 00026 addAttribute( _period ) ; 00027 addAttribute( _planetPeriod ) ; 00028 } 00029 00030 //----------------------------------------------------------------------------- 00031 00032 Orbit::~Orbit() 00033 { 00034 } 00035 //----------------------------------------------------------------------------- 00036 00037 bool Orbit::loadParameters( const ConfigurationParameterDescriptor * node ) 00038 { 00039 SimplePoint::loadParameters( node ) ; 00040 _planetAxis = _position.get().getDirection() ; 00041 _position.setValueToOutput() ; 00042 00043 return true ; 00044 } 00045 //----------------------------------------------------------------------------- 00046 00047 void Orbit::computeParameters() 00048 { 00049 // Get the increment 00050 if ( 1.0f <= _angle ) 00051 { // step > 0 00052 _angle = 0.0 ; 00053 } 00054 else if( _period.get() != 0.0f ) 00055 { 00056 _angle += 1.0f / _period.get() * _speed.get() ; 00057 } 00058 if ( 1.0f <= _planetAngle ) 00059 { // step > 0 00060 _planetAngle = 0.0 ; 00061 } 00062 else if( _planetPeriod.get() != 0.0f ) 00063 { 00064 _planetAngle += 1.0f / _planetPeriod.get() * _speed.get() ; 00065 } 00066 00067 // Get the translate and the rotate 00068 OMK::Type::Transform position ; 00069 Wm4::Vector3f orientation ; 00070 position.setTranslate( Wm4::Vector3f( _radius.get() * Wm4::Math<float>::Cos( Wm4::Math<float>::TWO_PI * _angle ), 00071 _radius.get() * Wm4::Math<float>::Sin( Wm4::Math<float>::TWO_PI * _angle ), 00072 0.0f ) ) ; 00073 00074 // Calculate the orientation 00075 Wm4::Matrix3f rotationMatrix( _planetAxis, Wm4::Math<float>::TWO_PI * _planetAngle ) ; 00076 position.setRotate( position.getRotate() * rotationMatrix ) ; 00077 00078 // Set the new position 00079 _position.set( position ) ; 00080 } 00081 00082 00083
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |