DynamicTransform.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __DYNAMICTRANSFORM_H__
00030 #define __DYNAMICTRANSFORM_H__
00031 
00032 #include "MatrixTransform.h"
00033 #include "PeriodicUpdate.h"
00034 #include "RK4.h"
00035 #include "SFMatrix3f.h"
00036 #include "SFQuaternion.h"
00037 
00038 namespace H3D {
00039 
00046   class H3DAPI_API DynamicTransform : public MatrixTransform {
00047   public:
00048 
00053     class H3DAPI_API SFMotion: 
00054       public  TypedField< H3D::SFVec3f, Types< SFTime > >  {
00055     public:
00056       
00057       SFMotion(): last_t( 0 ) {
00058       }
00059       
00060       H3DTime last_t;
00061     protected:
00063       virtual void update();
00064 
00065       virtual void updateState( LMState &state, H3DTime dt );
00066     };
00067 
00073     class H3DAPI_API SFMatrix4f: 
00074       public TypedField< H3D::SFMatrix4f,
00075                          Types< SFRotation, SFVec3f > >{
00076     protected:
00077  
00079       virtual void update();
00080     };
00081 
00087     class H3DAPI_API SFVelocity: public TypedField< SFVec3f, 
00088                                                     Types< SFFloat, 
00089                                                            SFVec3f > > {
00090       virtual void update() {
00091         H3DFloat mass = 
00092           static_cast< SFFloat * >( routes_in[0] )->getValue();
00093         const Vec3f &momentum = 
00094           static_cast< SFVec3f * >( routes_in[1] )->getValue();
00095         value = momentum / mass;
00096       }
00097     };
00098 
00103     class H3DAPI_API SFSpin: public TypedField< SFQuaternion, 
00104                                                 Types< SFVec3f, 
00105                                                        SFRotation > > {
00106       virtual void update() {
00107         const Vec3f & ang_vel = 
00108           static_cast< SFVec3f * >( routes_in[0] )->getValue();
00109         const Rotation &orn = 
00110           static_cast< SFRotation * >( routes_in[1] )->getValue();
00111         value = 0.5 * Quaternion(ang_vel.x, ang_vel.y, ang_vel.z, 0) * (Quaternion)orn;
00112       }
00113     };
00114 
00120     class H3DAPI_API SFAngularVelocity: public TypedField< SFVec3f, 
00121                                                            Types< SFMatrix3f,
00122                                                                   SFVec3f > > {
00123       virtual void update() {
00124         const Matrix3f &inertia_tensor = 
00125           static_cast< SFMatrix3f * >( routes_in[0] )->getValue();
00126         const Vec3f &ang_momentum = 
00127           static_cast< SFVec3f * >( routes_in[1] )->getValue();
00128         value = inertia_tensor.inverse() * ang_momentum;
00129       }
00130     };
00131 
00133     DynamicTransform( Inst< MFChild    > _addChildren              = 0,
00134                   Inst< MFChild    > _removeChildren           = 0,
00135                   Inst< MFChild    > _children                 = 0,
00136                   Inst< SFNode     > _metadata                 = 0,
00137                   Inst< SFBound    > _bound                    = 0,
00138                   Inst< SFVec3f    > _bboxCenter               = 0,
00139                   Inst< SFVec3f    > _bboxSize                 = 0,
00140                   Inst< SFTransformedBound > _transformedBound = 0,    
00141                   Inst< SFMatrix4f > _matrix                   = 0,
00142                   Inst< SFMatrix4f > _accumulatedForward       = 0,
00143                   Inst< SFMatrix4f > _accumulatedInverse       = 0,
00144                   Inst< SFVec3f          > _position         = 0,
00145                   Inst< SFRotation       > _orientation      = 0,
00146                   Inst< SFVelocity       > _velocity         = 0,
00147                   Inst< SFVec3f          > _momentum         = 0,
00148                   Inst< SFVec3f          > _force            = 0,
00149                   Inst< SFAngularVelocity > _angularVelocity  = 0,
00150                   Inst< SFVec3f          > _angularMomentum  = 0, 
00151                   Inst< SFSpin           > _spin             = 0,
00152                   Inst< SFVec3f          > _torque           = 0,
00153                   Inst< SFFloat          > _mass             = 0,
00154                   Inst< SFMatrix3f       > _inertiaTensor    = 0,
00155                   Inst< SFMotion         > _motion           = 0 );
00156 
00161     auto_ptr<    SFVec3f    >  position;
00162 
00167     auto_ptr<    SFRotation >  orientation;
00168 
00172     auto_ptr<    SFVec3f    >  velocity;
00173     
00178     auto_ptr<    SFVec3f    >  momentum;
00179     
00184     auto_ptr<    SFVec3f    >  force;
00185 
00189     auto_ptr<    SFVec3f    >  angularVelocity;
00190 
00195     auto_ptr<    SFVec3f    >  angularMomentum;
00196 
00200     auto_ptr<    SFSpin    >  spin;
00201 
00206     auto_ptr<    SFVec3f    >  torque;
00207 
00212     auto_ptr<    SFFloat    >  mass;
00213 
00218     auto_ptr<    SFMatrix3f  >  inertiaTensor;
00219 
00221     auto_ptr<    SFMotion    >  motion;
00222     
00224     static H3DNodeDatabase database;
00225   };
00226 }
00227 
00228 #endif

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5