Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/interaction/include/Inventor/draggers/SoTrackballDragger.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.1.1.1 $
00045  |
00046  |   Description:
00047  |      This file defines the trackball dragger class.
00048  |
00049  | NOTE TO DEVELOPERS:
00050  |     For info about the structure of SoTrackballDragger:
00051  |     [1] compile: /usr/share/src/Inventor/samples/ivNodeKitStructure
00052  |     [2] type:    ivNodeKitStructure SoTrackballDragger.
00053  |     [3] The program prints a diagram of the scene graph and a table with 
00054  |         information about each part.
00055  |
00056  |  The following parts in this dragger are created at construction time.
00057  |  'ResourceName' corresponds to the name of the default geometry for the
00058  |  part. The dragger's constructor gets the scene graph for 'ResourceName'
00059  |  by querying the global dictionary ( SoDB::getByName("ResourceName"); ).  
00060  |
00061  |  Resource Name:                           Part Name:
00062  |
00063  |  trackballRotator                       - rotator     
00064  |  trackballRotatorActive                 - rotatorActive     
00065  |  trackballXRotator                      - XRotator    
00066  |  trackballXRotatorActive                - XRotatorActive    
00067  |  trackballYRotator,                     - YRotator   
00068  |  trackballYRotatorActive,               - YRotatorActive   
00069  |  trackballZRotator                      - ZRotator  
00070  |  trackballZRotatorActive                - ZRotatorActive  
00071  |  trackballUserAxis                      - userAxis    
00072  |  trackballUserAxisActive                - userAxisActive    
00073  |  trackballUserRotator                   - userRotator 
00074  |  trackballUserRotatorActive             - userRotatorActive 
00075  |
00076  |   Author(s): Paul Isaacs, David Mott
00077  |
00078  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00079  _______________________________________________________________________
00080  */
00081 
00082 #ifndef  _SO_TRACKBALL_DRAGGER_
00083 #define  _SO_TRACKBALL_DRAGGER_
00084 
00085 #include <Inventor/SbLinear.h>
00086 #include <Inventor/SbTime.h>
00087 #include <Inventor/sensors/SoSensor.h>
00088 #include <Inventor/draggers/SoDragger.h>
00089 #include <Inventor/fields/SoSFVec3f.h>
00090 #include <Inventor/fields/SoSFRotation.h>
00091 
00092 class SbDict;
00093 class SoGroup;
00094 class SoRotation;
00095 class SbSphereProjector;
00096 class SbCylinderProjector;
00097 class SoFieldSensor;
00098 class SoTimerSensor;
00099 
00100 
00103 
00190 
00191 
00192 class INVENTOR_API SoTrackballDragger : public SoDragger {
00193 
00194     SO_KIT_HEADER(SoTrackballDragger);
00195 
00197     SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
00199     SO_KIT_CATALOG_ENTRY_HEADER(antiSquish);
00200 
00201     SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch);
00202     SO_KIT_CATALOG_ENTRY_HEADER(rotator);
00203     SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive);
00204     SO_KIT_CATALOG_ENTRY_HEADER(XRotatorSwitch);
00205     SO_KIT_CATALOG_ENTRY_HEADER(XRotator);
00206     SO_KIT_CATALOG_ENTRY_HEADER(XRotatorActive);
00207     SO_KIT_CATALOG_ENTRY_HEADER(YRotatorSwitch);
00208     SO_KIT_CATALOG_ENTRY_HEADER(YRotator);
00209     SO_KIT_CATALOG_ENTRY_HEADER(YRotatorActive);
00210     SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorSwitch);
00211     SO_KIT_CATALOG_ENTRY_HEADER(ZRotator);
00212     SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorActive);
00213 
00215     SO_KIT_CATALOG_ENTRY_HEADER(userAxisRotation);
00216 
00217     SO_KIT_CATALOG_ENTRY_HEADER(userAxisSwitch);
00218     SO_KIT_CATALOG_ENTRY_HEADER(userAxis);
00219     SO_KIT_CATALOG_ENTRY_HEADER(userAxisActive);
00220     SO_KIT_CATALOG_ENTRY_HEADER(userRotatorSwitch);
00221     SO_KIT_CATALOG_ENTRY_HEADER(userRotator);
00222     SO_KIT_CATALOG_ENTRY_HEADER(userRotatorActive);
00223 
00224   public:
00225 
00227     SoTrackballDragger();
00228 
00229     SoSFRotation rotation;
00230     SoSFVec3f scaleFactor;
00231 
00233     SbBool isAnimationEnabled() { return animationEnabled; }
00238     void setAnimationEnabled( SbBool newVal );
00239 
00240   SoINTERNAL public:
00241     static void         initClass();    
00242 
00243   protected:
00244 
00246     static void startCB(void *, SoDragger *);
00247     static void motionCB(void *, SoDragger *);
00248     static void finishCB(void *, SoDragger *);
00249     
00250     SoFieldSensor *rotFieldSensor;
00251     SoFieldSensor *scaleFieldSensor;
00252     static void fieldSensorCB( void *, SoSensor * );
00253     static void valueChangedCB( void *, SoDragger * );
00254 
00256     static void metaKeyChangeCB(void *, SoDragger *);
00257 
00259     void        dragStart();
00260     void        drag();
00261     void        dragFinish();
00262 
00263     void setAllPartsActive( SbBool onOrOff );
00264 
00271     virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE );
00272 
00273     virtual void setDefaultOnNonWritingFields();
00274 
00275     virtual ~SoTrackballDragger();
00276 
00277   private:
00278 
00279     enum State
00280         { INACTIVE, FREE_ROTATE, X_ROTATE, Y_ROTATE, Z_ROTATE,
00281           SCALE, USER_AXIS_ADJUST, USER_AXIS_ROTATE, SPINNING };
00282     State               currentState;     
00283 
00284     SbVec3f             constrainedAxis;
00285     SbVec3f             userAxisVec;       
00286 
00287 
00288     SbSphereProjector   *sphereProj;
00289     SbCylinderProjector *stripeProj;
00290 
00291     SbVec3f             startWorldHitPt; 
00292     SbBool              ctlDown, shftDown; 
00293     SbVec3f             prevWorldHitPt; 
00294 
00295     SbMatrix            prevMotionMatrix; 
00296 
00297 
00299     void        setHighlights();
00300 
00301     SbBool              rotateDrag();
00302     SbBool              scaleDrag();
00303     SbBool              userStripeDrag();
00304     
00306     static const char geomBuffer[];             
00307 
00309     SbBool animationEnabled;
00310     SbTime          prevTime;
00311     SbTime          spinTime;
00312     SbTime          scheduleRate;
00313     SoTimerSensor   *spinSensor;
00314     SbRotation      *rotBuffer;
00315     SbTime          *timeBuffer;
00316     int             firstIndex, lastIndex;
00317     SbVec3f         averageAxis;
00318     float           angleVelocity;
00319     SbBool          computeAverage;
00320 
00322     static  void spinSensorCB(void *, SoSensor *);
00323     void    spinAnimate();
00324     void    resetSpinStuff();
00325 
00330     SbBool  wasSpinningAtDragStart;
00331 };
00332 
00333 #endif /* _SO_TRACKBALL_DRAGGER_ */