Open Inventor Reference
SoTrackballDragger.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | This file defines the trackball dragger class.
48 |
49 | NOTE TO DEVELOPERS:
50 | For info about the structure of SoTrackballDragger:
51 | [1] compile: /usr/share/src/Inventor/samples/ivNodeKitStructure
52 | [2] type: ivNodeKitStructure SoTrackballDragger.
53 | [3] The program prints a diagram of the scene graph and a table with
54 | information about each part.
55 |
56 | The following parts in this dragger are created at construction time.
57 | 'ResourceName' corresponds to the name of the default geometry for the
58 | part. The dragger's constructor gets the scene graph for 'ResourceName'
59 | by querying the global dictionary ( SoDB::getByName("ResourceName"); ).
60 |
61 | Resource Name: Part Name:
62 |
63 | trackballRotator - rotator
64 | trackballRotatorActive - rotatorActive
65 | trackballXRotator - XRotator
66 | trackballXRotatorActive - XRotatorActive
67 | trackballYRotator, - YRotator
68 | trackballYRotatorActive, - YRotatorActive
69 | trackballZRotator - ZRotator
70 | trackballZRotatorActive - ZRotatorActive
71 | trackballUserAxis - userAxis
72 | trackballUserAxisActive - userAxisActive
73 | trackballUserRotator - userRotator
74 | trackballUserRotatorActive - userRotatorActive
75 |
76 | Author(s): Paul Isaacs, David Mott
77 |
78 ______________ S I L I C O N G R A P H I C S I N C . ____________
79 _______________________________________________________________________
80 */
81
82#ifndef _SO_TRACKBALL_DRAGGER_
83#define _SO_TRACKBALL_DRAGGER_
84
85#include <Inventor/SbLinear.h>
86#include <Inventor/SbTime.h>
91
92class SbDict;
93class SoGroup;
94class SoRotation;
95class SbProjector;
98class SoFieldSensor;
99class SoTimerSensor;
100
101
104
192
194
196
198 SO_KIT_CATALOG_ENTRY_HEADER(surroundScale);
200 SO_KIT_CATALOG_ENTRY_HEADER(antiSquish);
201
202 SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch);
204 SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive);
205 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorSwitch);
207 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorActive);
208 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorSwitch);
210 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorActive);
211 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorSwitch);
213 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorActive);
214
216 SO_KIT_CATALOG_ENTRY_HEADER(userAxisRotation);
217
218 SO_KIT_CATALOG_ENTRY_HEADER(userAxisSwitch);
220 SO_KIT_CATALOG_ENTRY_HEADER(userAxisActive);
221 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorSwitch);
222 SO_KIT_CATALOG_ENTRY_HEADER(userRotator);
223 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorActive);
224
225 public:
226
229
232
234 bool isAnimationEnabled() { return animationEnabled; }
239 void setAnimationEnabled( bool newVal );
240
241 SoINTERNAL public:
242 static void initClass();
243
244 protected:
245
247 static void startCB(void *, SoDragger *);
248 static void motionCB(void *, SoDragger *);
249 static void finishCB(void *, SoDragger *);
250
253 static void fieldSensorCB( void *, SoSensor * );
254 static void valueChangedCB( void *, SoDragger * );
255
257 static void metaKeyChangeCB(void *, SoDragger *);
258
260 void dragStart();
261 void drag();
263
264 virtual void setAllPartsActive( bool onOrOff );
265
272 virtual bool setUpConnections( bool onOff, bool doItAlways = FALSE );
273
275
277
278 // Results of refactoring (MMS Bug: 57374):
279
283
284 bool ctlDown, shftDown;
285
286 enum State
287 { INACTIVE, FREE_ROTATE, X_ROTATE, Y_ROTATE, Z_ROTATE,
288 SCALE, USER_AXIS_ADJUST, USER_AXIS_ROTATE, SPINNING };
290
291
295 virtual void initDragState();
296
299 virtual SbProjector* initSphereProjector(SbVec3f center, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace);
300
303 virtual SbProjector* initStripeProjector(SbLine axis, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace);
304
306 virtual void getSphereDeltaRotation(SbRotation &deltaRot, SbVec3f &newHitPt, SbVec3f prevHitPt, SbMatrix workingSpace);
307
309 virtual void getStripeDeltaRotation(SbRotation &deltaRot, SbVec3f &newHitPt, SbVec3f prevHitPt, SbMatrix workingSpace);
310
311 private:
312
313 SbVec3f constrainedAxis;
314 SbVec3f userAxisVec;
316
317 SbVec3f startWorldHitPt;
318 SbVec3f prevWorldHitPt;
320 SbMatrix prevMotionMatrix;
322
324 void initSphereProjectorInternal(SbVec3f center, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace);
325
327 void initStripeProjectorInternal(SbLine axis, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace);
328
329 void setHighlights();
330
331 bool rotateDrag();
332 bool scaleDrag();
333 bool userStripeDrag();
334
336 static const unsigned char geomBuffer[];
337
339 bool animationEnabled;
340 SbTime prevTime;
341 SbTime spinTime;
342 SbTime scheduleRate;
343 SoTimerSensor *spinSensor;
344 SbRotation *rotBuffer;
345 SbTime *timeBuffer;
346 int firstIndex, lastIndex;
347 SbVec3f averageAxis;
348 float angleVelocity;
349 bool computeAverage;
350
352 static void spinSensorCB(void *, SoSensor *);
353 void spinAnimate();
354 void resetSpinStuff();
355
360 bool wasSpinningAtDragStart;
361};
362
363#endif /* _SO_TRACKBALL_DRAGGER_ */
#define FALSE
Definition SbBasic.h:79
#define SoINTERNAL
Definition SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
#define SO_KIT_CATALOG_ENTRY_HEADER(partName)
This defines an SoSFNode field for the catalog part given.
Definition SoSubKit.h:155
#define SO_KIT_HEADER(className)
Definition SoSubKit.h:143
Cylinder projector.
This is a dictionary mapping (size_t) integer keys to (void *) data pointers.
Definition SbDict.h:101
Directed line in 3D.
Definition SbLinear.h:1292
4x4 matrix class.
Definition SbLinear.h:823
Base class for representing projectors.
Definition SbProjector.h:87
Class for representing a rotation.
Definition SbLinear.h:678
Sphere projector.
Class for representation of a time.
Definition SbTime.h:89
3D vector class.
Definition SbLinear.h:120
Base class for nodekits that move in response to click-drag-release mouse events.
Definition SoDragger.h:225
Sensor class that can be attached to Inventor fields.
Base class for all group nodes.
Definition SoGroup.h:104
Node representing a 3D rotation about an arbitrary axis.
Definition SoRotation.h:94
Field containing a rotation.
Field containing a three-dimensional vector.
Definition SoSFVec3f.h:79
Abstract base class for Inventor sensors.
Definition SoSensor.h:108
Sensor that triggers callback repeatedly at regular intervals.
Striped ball you can rotate or scale uniformly by dragging with the mouse.
virtual SbProjector * initStripeProjector(SbLine axis, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace)
Setup the projector at start of constrained rotation.
static void valueChangedCB(void *, SoDragger *)
SoFieldSensor * scaleFieldSensor
virtual void setAllPartsActive(bool onOrOff)
void dragStart()
These really do the work during startCB, motionCB, and finishCB.
SoFieldSensor * rotFieldSensor
virtual ~SoTrackballDragger()
SoTrackballDragger()
Constructor.
void setAnimationEnabled(bool newVal)
If the mouse is moving while you release it, the trackball will continue to spin afterwards.
static void startCB(void *, SoDragger *)
Callbacks for drag start, motion, and finish.
SbCylinderProjector * stripeProj
static void fieldSensorCB(void *, SoSensor *)
SbSphereProjector * sphereProj
Moved variables from private to protected.
static void finishCB(void *, SoDragger *)
virtual bool setUpConnections(bool onOff, bool doItAlways=FALSE)
detach/attach any sensors, callbacks, and/or field connections.
static void metaKeyChangeCB(void *, SoDragger *)
Callback for pressing and releasing the meta keys.
static void initClass()
initialize the class
virtual void initDragState()
Determines the State based on the current pick path.
virtual SbProjector * initSphereProjector(SbVec3f center, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace)
Setup the projector at start of free rotation.
static void motionCB(void *, SoDragger *)
virtual void setDefaultOnNonWritingFields()
Called by the SoBaseKit::write() method.
virtual void getSphereDeltaRotation(SbRotation &deltaRot, SbVec3f &newHitPt, SbVec3f prevHitPt, SbMatrix workingSpace)
Compute newHitPt and derive the delta rotation based on prevHitPt and newHitPt.
virtual void getStripeDeltaRotation(SbRotation &deltaRot, SbVec3f &newHitPt, SbVec3f prevHitPt, SbMatrix workingSpace)
Compute newHitPt and derive the delta rotation based on prevHitPt and newHitPt.