Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoTrackballDragger.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul Isaacs (MMM yyyy)
25** Modified by : David Mott (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2019 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifndef _SO_TRACKBALL_DRAGGER_
52#define _SO_TRACKBALL_DRAGGER_
53
54#include <Inventor/SbLinear.h>
55#include <Inventor/SbTime.h>
56#include <Inventor/sensors/SoSensor.h>
57#include <Inventor/draggers/SoDragger.h>
58#include <Inventor/fields/SoSFVec3f.h>
59#include <Inventor/fields/SoSFRotation.h>
60
61class SbDict;
62class SoGroup;
63class SoRotation;
66class SbLineProjector;
67class SoFieldSensor;
68class SoTimerSensor;
69
71//
72// Class: SoTrackballDragger
73//
74// Trackball dragger - allows user to rotate objects.
75//
77
293
294 SO_KIT_HEADER(SoTrackballDragger);
295
296 // For making the dragger surround what lies above it.
297 SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
298 // For keeping the dragger even size in all 3 dimensions
299 SO_KIT_CATALOG_ENTRY_HEADER(antiSquish);
300
301 SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch);
302 SO_KIT_CATALOG_ENTRY_HEADER(rotator);
303 SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive);
304 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorSwitch);
305 SO_KIT_CATALOG_ENTRY_HEADER(XRotator);
306 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorActive);
307 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorSwitch);
308 SO_KIT_CATALOG_ENTRY_HEADER(YRotator);
309 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorActive);
310 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorSwitch);
311 SO_KIT_CATALOG_ENTRY_HEADER(ZRotator);
312 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorActive);
313
314 // The userAxisRotation is not a public part.
315 SO_KIT_CATALOG_ENTRY_HEADER(userAxisRotation);
316
317 SO_KIT_CATALOG_ENTRY_HEADER(userAxisSwitch);
318 SO_KIT_CATALOG_ENTRY_HEADER(userAxis);
319 SO_KIT_CATALOG_ENTRY_HEADER(userAxisActive);
320 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorSwitch);
321 SO_KIT_CATALOG_ENTRY_HEADER(userRotator);
322 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorActive);
323
324 public:
329
344
348 SbBool isAnimationEnabled() { return animationEnabled; }
355
356 private:
357 static void initClass(); // initialize the class
358 static void exitClass();
359
360 private:
361
362 // Callbacks for drag start, motion, and finish
363 static void startCB(void *, SoDragger *);
364 static void motionCB(void *, SoDragger *);
365 static void finishCB(void *, SoDragger *);
366
367 SoFieldSensor *rotFieldSensor;
368 SoFieldSensor *scaleFieldSensor;
369 static void fieldSensorCB( void *, SoSensor * );
370 static void valueChangedCB( void *, SoDragger * );
371
372 // Callback for pressing and releasing the meta keys
373 static void metaKeyChangeCB(void *, SoDragger *);
374
375 // These really do the work during startCB, motionCB, and finishCB
376 void dragStart();
377 void drag();
378 void dragFinish();
379
380 void setAllPartsActive( SbBool onOrOff );
381
382 // detach/attach any sensors, callbacks, and/or field connections.
383 // Called by: start/end of SoBaseKit::readInstance
384 // and on new copy by: start/end of SoBaseKit::copy.
385 // Classes that redefine must call setUpConnections(TRUE,TRUE)
386 // at end of constructor.
387 // Returns the state of the node when this was called.
388 virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE );
389
390 virtual void setDefaultOnNonWritingFields();
391
392 virtual ~SoTrackballDragger();
393
394 private:
395
396 enum State
397 { INACTIVE, FREE_ROTATE, X_ROTATE, Y_ROTATE, Z_ROTATE,
398 SCALE, USER_AXIS_ADJUST, USER_AXIS_ROTATE, SPINNING };
399 State currentState;
400
401 SbVec3f constrainedAxis;// if so, about what axis?
402 SbVec3f userAxisVec; // For storing the user definable
403 // 'special' rotation axis.
404
405 SbSphereProjector *sphereProj;
406 SbCylinderProjector *stripeProj;
407 SbLineProjector *lineProj;
408
409 SbVec3f startWorldHitPt; // used during interaction
410 SbBool ctlDown, shftDown; // keep track of meta keys
411 SbVec3f prevWorldHitPt; // used during interaction by
412 // spherical projector.
413 SbMatrix prevMotionMatrix; // used during interaction by
414 // spherical projector.
415
416 // functions which do all the work
417 void setHighlights();
418
419 SbBool rotateDrag();
420 SbBool scaleDrag();
421 SbBool userStripeDrag();
422
423 // character strings from which the shared geometry is read
424 static const char geomBuffer[];
425
426 // variables used for doing spinning animation
427 SbBool animationEnabled;
428 SbTime prevTime;
429 SbTime spinTime;
430 SbTime scheduleRate;
431 SoTimerSensor *spinSensor;
432 SbRotation *rotBuffer;
433 SbTime *timeBuffer;
434 int firstIndex, lastIndex;
435 SbVec3f averageAxis;
436 float angleVelocity;
437 SbBool computeAverage;
438
439 // routines used for doing spinning animation
440 static void spinSensorCB(void *, SoSensor *);
441 void spinAnimate();
442 void resetSpinStuff();
443
444 // We record whether ball was spinning at drag start. If so, it will
445 // call ha->setHandled() in dragFinish(). This way, it won't be
446 // considered an item selection, which is usually the case when you click
447 // on an object without moving the mouse.
448 SbBool wasSpinningAtDragStart;
449
450};
451
452#endif /* _SO_TRACKBALL_DRAGGER_ */
453
Cylinder projector.
Line projector.
4x4 matrix class.
Definition SbMatrix.h:309
Class for representing a rotation.
Definition SbRotation.h:126
Sphere projector.
Class for representation of a time.
Definition SbTime.h:91
3D vector class.
Definition SbVec.h:932
Base class for nodekits that move in response to click-drag-release mouse events.
Definition SoDragger.h:537
Sensor class that can be attached to Open Inventor fields.
Base class for all group nodes.
Definition SoGroup.h:122
Node representing a 3D rotation about an arbitrary axis.
Definition SoRotation.h:98
Field containing a rotation.
Field containing a three-dimensional vector.
Definition SoSFVec3f.h:80
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:100
Sensor that triggers repeatedly at regular intervals.
Striped ball you can rotate or scale uniformly by dragging with the mouse.
SoSFRotation rotation
Orientation of the dragger.
SoTrackballDragger()
Constructor.
void setAnimationEnabled(SbBool newVal)
Enables/disables spin animation.
SoSFVec3f scaleFactor
Scale of the dragger.
SbBool isAnimationEnabled()
Returns whether spin animation is enabled.
int SbBool
Boolean type.
Definition SbBase.h:87