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
00292 class SoTrackballDragger : public SoDragger {
00293
00294 SO_KIT_HEADER(SoTrackballDragger);
00295
00296
00297 SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
00298
00299 SO_KIT_CATALOG_ENTRY_HEADER(antiSquish);
00300
00301 SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch);
00302 SO_KIT_CATALOG_ENTRY_HEADER(rotator);
00303 SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive);
00304 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorSwitch);
00305 SO_KIT_CATALOG_ENTRY_HEADER(XRotator);
00306 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorActive);
00307 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorSwitch);
00308 SO_KIT_CATALOG_ENTRY_HEADER(YRotator);
00309 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorActive);
00310 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorSwitch);
00311 SO_KIT_CATALOG_ENTRY_HEADER(ZRotator);
00312 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorActive);
00313
00314
00315 SO_KIT_CATALOG_ENTRY_HEADER(userAxisRotation);
00316
00317 SO_KIT_CATALOG_ENTRY_HEADER(userAxisSwitch);
00318 SO_KIT_CATALOG_ENTRY_HEADER(userAxis);
00319 SO_KIT_CATALOG_ENTRY_HEADER(userAxisActive);
00320 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorSwitch);
00321 SO_KIT_CATALOG_ENTRY_HEADER(userRotator);
00322 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorActive);
00323
00324 public:
00328 SoTrackballDragger();
00329
00334 SoSFRotation rotation;
00343 SoSFVec3f scaleFactor;
00344
00348 SbBool isAnimationEnabled() { return animationEnabled; }
00354 void setAnimationEnabled( SbBool newVal );
00355
00356 private:
00357 static void initClass();
00358 static void exitClass();
00359
00360 private:
00361
00362
00363 static void startCB(void *, SoDragger *);
00364 static void motionCB(void *, SoDragger *);
00365 static void finishCB(void *, SoDragger *);
00366
00367 SoFieldSensor *rotFieldSensor;
00368 SoFieldSensor *scaleFieldSensor;
00369 static void fieldSensorCB( void *, SoSensor * );
00370 static void valueChangedCB( void *, SoDragger * );
00371
00372
00373 static void metaKeyChangeCB(void *, SoDragger *);
00374
00375
00376 void dragStart();
00377 void drag();
00378 void dragFinish();
00379
00380 void setAllPartsActive( SbBool onOrOff );
00381
00382
00383
00384
00385
00386
00387
00388 virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE );
00389
00390 virtual void setDefaultOnNonWritingFields();
00391
00392 virtual ~SoTrackballDragger();
00393
00394 private:
00395
00396 enum State
00397 { INACTIVE, FREE_ROTATE, X_ROTATE, Y_ROTATE, Z_ROTATE,
00398 SCALE, USER_AXIS_ADJUST, USER_AXIS_ROTATE, SPINNING };
00399 State currentState;
00400
00401 SbVec3f constrainedAxis;
00402 SbVec3f userAxisVec;
00403
00404
00405 SbSphereProjector *sphereProj;
00406 SbCylinderProjector *stripeProj;
00407 SbLineProjector *lineProj;
00408
00409 SbVec3f startWorldHitPt;
00410 SbBool ctlDown, shftDown;
00411 SbVec3f prevWorldHitPt;
00412
00413 SbMatrix prevMotionMatrix;
00414
00415
00416
00417 void setHighlights();
00418
00419 SbBool rotateDrag();
00420 SbBool scaleDrag();
00421 SbBool userStripeDrag();
00422
00423
00424 static const char geomBuffer[];
00425
00426
00427 SbBool animationEnabled;
00428 SbTime prevTime;
00429 SbTime spinTime;
00430 SbTime scheduleRate;
00431 SoTimerSensor *spinSensor;
00432 SbRotation *rotBuffer;
00433 SbTime *timeBuffer;
00434 int firstIndex, lastIndex;
00435 SbVec3f averageAxis;
00436 float angleVelocity;
00437 SbBool computeAverage;
00438
00439
00440 static void spinSensorCB(void *, SoSensor *);
00441 void spinAnimate();
00442 void resetSpinStuff();
00443
00444
00445
00446
00447
00448 SbBool wasSpinningAtDragStart;
00449
00450 };
00451
00452 #endif
00453
00454