SpaceWareSensor.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 __SPACEWARESENSOR_H__
00030 #define __SPACEWARESENSOR_H__
00031 
00032 
00033 #include "X3DSensorNode.h"
00034 #include <list>
00035 #include "SFVec3f.h"
00036 #include "SFFloat.h"
00037 #include "SFInt32.h"
00038 #include "SFRotation.h"
00039 #include "Threads.h"
00040 
00041 namespace H3D {
00042 
00050   class H3DAPI_API SpaceWareSensor : public X3DSensorNode {
00051   public:
00052 
00059     struct H3DAPI_API ScaleRotation: 
00060       public TypedField< SFRotation,
00061                          Types< SFRotation, SFFloat > > {
00062       virtual void update() {
00063         Rotation r = 
00064           static_cast< SFRotation * >( routes_in[0] )->getValue();
00065         H3DFloat s = 
00066           static_cast< SFFloat * >( routes_in[1] )->getValue();
00067   
00068         //TODO: fix so that operator can be used
00069         r.angle = r.angle * s;
00070         value = r;
00071       }
00072     };
00073 
00079     struct H3DAPI_API ScaleTranslation: 
00080       public TypedField< SFVec3f,
00081                          Types< SFVec3f, SFFloat > > {
00082       virtual void update() {
00083         const Vec3f &r = static_cast< SFVec3f * >( routes_in[0] )->getValue();
00084         H3DFloat s = static_cast< SFFloat * >( routes_in[1] )->getValue();
00085         value = r * s;
00086       }
00087     };
00088 
00089 
00094     struct H3DAPI_API AccumulateRotation: 
00095       public AutoUpdate< SFRotation > {
00096       virtual void update() {
00097         Rotation r = static_cast< SFRotation * >( event.ptr )->getValue();
00098         value = r * value;
00099       }
00100     };
00101 
00106     struct H3DAPI_API AccumulateTranslation: 
00107       public AutoUpdate< SFVec3f > {
00108       virtual void update() {
00109         const Vec3f &v = static_cast< SFVec3f * >( event.ptr )->getValue();
00110         value = value + v;
00111       }
00112     };
00113   
00115     SpaceWareSensor( 
00116                     Inst< SFBool                > _enabled  = 0,
00117                     Inst< SFNode                > _metadata = 0,
00118                     Inst< SFBool                > _isActive = 0,
00119                     Inst< SFVec3f               > _rawTranslation = 0,
00120                     Inst< SFRotation            > _rawYaw = 0,
00121                     Inst< SFRotation            > _rawPitch = 0,
00122                     Inst< SFRotation            > _rawRoll = 0,
00123                     Inst< SFRotation            > _rawRotation = 0,
00124                     Inst< ScaleTranslation      > _instantTranslation = 0,
00125                     Inst< ScaleRotation         > _instantYaw = 0,
00126                     Inst< ScaleRotation         > _instantPitch = 0,
00127                     Inst< ScaleRotation         > _instantRoll = 0,
00128                     Inst< ScaleRotation         > _instantRotation = 0,
00129                     Inst< AccumulateTranslation > _accumulatedTranslation = 0,
00130                     Inst< AccumulateRotation    > _accumulatedYaw = 0,
00131                     Inst< AccumulateRotation    > _accumulatedPitch = 0,
00132                     Inst< AccumulateRotation    > _accumulatedRoll = 0,
00133                     Inst< AccumulateRotation    > _accumulatedRotation = 0,
00134                     Inst< SFFloat               > _translationScale = 0,
00135                     Inst< SFFloat               > _rotationScale = 0,
00136                     Inst< SFInt32               > _buttons = 0,
00137                     Inst< SFInt32               > _latestButtonPress = 0,
00138                     Inst< SFInt32               > _latestButtonRelease = 0
00139                     );
00140 
00146     auto_ptr< SFVec3f>             rawTranslation;
00147 
00154     auto_ptr< SFRotation>          rawYaw;
00155 
00162     auto_ptr< SFRotation>          rawPitch;
00163 
00170     auto_ptr< SFRotation>          rawRoll;
00171 
00178     auto_ptr< SFRotation>        rawRotation;
00179 
00185     auto_ptr< ScaleTranslation>  instantTranslation;
00186 
00192     auto_ptr< ScaleRotation>     instantYaw;
00193 
00199     auto_ptr< ScaleRotation>     instantPitch;
00200 
00206     auto_ptr< ScaleRotation>     instantRoll;
00207 
00213     auto_ptr< ScaleRotation>      instantRotation;
00214 
00220     auto_ptr< AccumulateTranslation>  accumulatedTranslation;
00221 
00227     auto_ptr< AccumulateRotation>     accumulatedYaw;
00228 
00234     auto_ptr< AccumulateRotation>     accumulatedPitch;
00235 
00241     auto_ptr< AccumulateRotation>     accumulatedRoll; 
00242 
00248     auto_ptr< AccumulateRotation>     accumulatedRotation;
00249 
00256     auto_ptr< SFFloat>          translationScale; 
00257 
00265     auto_ptr< SFFloat>          rotationScale;
00266 
00277     auto_ptr< SFInt32 > buttons;
00278 
00284     auto_ptr< SFInt32 > latestButtonPress;
00285 
00291     auto_ptr< SFInt32 > latestButtonRelease;
00292 
00293 #ifdef USE_HAPTICS
00296     virtual void traverseSG( TraverseInfo &ti );
00297 #endif
00298 
00299     // This data structure is used to transfer button data from the 
00300     // device communication thread to the scene graph thread.
00301     struct ButtonData {
00302       ButtonData( int _pressed, 
00303                   int _released,
00304                   int _current_state ) :
00305         pressed( _pressed ),
00306         released( _released ),
00307         current_state( _current_state ) {}
00308       unsigned int pressed, released, current_state;
00309     };
00310   public:
00311     // has a motion event occured since last scenegraph loop.
00312     bool thread_motion_event;
00313     // button data since last scenegraph loop.
00314     vector< ButtonData > thread_buttons; 
00315     // rotation values from the last motion event.
00316     Vec3f thread_rotation;
00317     // translation values from the last motion event.
00318     Vec3f thread_translation;
00320     static H3DNodeDatabase database;
00321 
00322   private:
00323 #ifdef HAVE_3DXWARE
00324     // the handle of the communication thread.
00325     auto_ptr< SimpleThread > thread_handle;
00326 #endif
00327   };
00328 }
00329 
00330 #endif

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