00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef _SO_TRACKBALL_DRAGGER_
00052 #define _SO_TRACKBALL_DRAGGER_
00053
00054 #include <Inventor/SbLinear.h>
00055 #include <Inventor/SbTime.h>
00056 #include <Inventor/sensors/SoSensor.h>
00057 #include <Inventor/draggers/SoDragger.h>
00058 #include <Inventor/fields/SoSFVec3f.h>
00059 #include <Inventor/fields/SoSFRotation.h>
00060
00061 class SbDict;
00062 class SoGroup;
00063 class SoRotation;
00064 class SbSphereProjector;
00065 class SbCylinderProjector;
00066 class SbLineProjector;
00067 class SoFieldSensor;
00068 class SoTimerSensor;
00069
00071
00072
00073
00074
00075
00077
00294 class SoTrackballDragger : public SoDragger {
00295
00296 SO_KIT_HEADER(SoTrackballDragger);
00297
00298
00299 SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
00300
00301 SO_KIT_CATALOG_ENTRY_HEADER(antiSquish);
00302
00303 SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch);
00304 SO_KIT_CATALOG_ENTRY_HEADER(rotator);
00305 SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive);
00306 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorSwitch);
00307 SO_KIT_CATALOG_ENTRY_HEADER(XRotator);
00308 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorActive);
00309 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorSwitch);
00310 SO_KIT_CATALOG_ENTRY_HEADER(YRotator);
00311 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorActive);
00312 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorSwitch);
00313 SO_KIT_CATALOG_ENTRY_HEADER(ZRotator);
00314 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorActive);
00315
00316
00317 SO_KIT_CATALOG_ENTRY_HEADER(userAxisRotation);
00318
00319 SO_KIT_CATALOG_ENTRY_HEADER(userAxisSwitch);
00320 SO_KIT_CATALOG_ENTRY_HEADER(userAxis);
00321 SO_KIT_CATALOG_ENTRY_HEADER(userAxisActive);
00322 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorSwitch);
00323 SO_KIT_CATALOG_ENTRY_HEADER(userRotator);
00324 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorActive);
00325
00326 public:
00330 SoTrackballDragger();
00331
00336 SoSFRotation rotation;
00345 SoSFVec3f scaleFactor;
00346
00350 SbBool isAnimationEnabled() { return animationEnabled; }
00356 void setAnimationEnabled( SbBool newVal );
00357
00358 private:
00359 static void initClass();
00360 static void exitClass();
00361
00362 private:
00363
00364
00365 static void startCB(void *, SoDragger *);
00366 static void motionCB(void *, SoDragger *);
00367 static void finishCB(void *, SoDragger *);
00368
00369 SoFieldSensor *rotFieldSensor;
00370 SoFieldSensor *scaleFieldSensor;
00371 static void fieldSensorCB( void *, SoSensor * );
00372 static void valueChangedCB( void *, SoDragger * );
00373
00374
00375 static void metaKeyChangeCB(void *, SoDragger *);
00376
00377
00378 void dragStart();
00379 void drag();
00380 void dragFinish();
00381
00382 void setAllPartsActive( SbBool onOrOff );
00383
00384
00385
00386
00387
00388
00389
00390 virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE );
00391
00392 virtual void setDefaultOnNonWritingFields();
00393
00394 virtual ~SoTrackballDragger();
00395
00396 private:
00397
00398 enum State
00399 { INACTIVE, FREE_ROTATE, X_ROTATE, Y_ROTATE, Z_ROTATE,
00400 SCALE, USER_AXIS_ADJUST, USER_AXIS_ROTATE, SPINNING };
00401 State currentState;
00402
00403 SbVec3f constrainedAxis;
00404 SbVec3f userAxisVec;
00405
00406
00407 SbSphereProjector *sphereProj;
00408 SbCylinderProjector *stripeProj;
00409 SbLineProjector *lineProj;
00410
00411 SbVec3f startWorldHitPt;
00412 SbBool ctlDown, shftDown;
00413 SbVec3f prevWorldHitPt;
00414
00415 SbMatrix prevMotionMatrix;
00416
00417
00418
00419 void setHighlights();
00420
00421 SbBool rotateDrag();
00422 SbBool scaleDrag();
00423 SbBool userStripeDrag();
00424
00425
00426 static const char geomBuffer[];
00427
00428
00429 SbBool animationEnabled;
00430 SbTime prevTime;
00431 SbTime spinTime;
00432 SbTime scheduleRate;
00433 SoTimerSensor *spinSensor;
00434 SbRotation *rotBuffer;
00435 SbTime *timeBuffer;
00436 int firstIndex, lastIndex;
00437 SbVec3f averageAxis;
00438 float angleVelocity;
00439 SbBool computeAverage;
00440
00441
00442 static void spinSensorCB(void *, SoSensor *);
00443 void spinAnimate();
00444 void resetSpinStuff();
00445
00446
00447
00448
00449
00450 SbBool wasSpinningAtDragStart;
00451
00452 };
00453
00454 #endif
00455
00456