Open Inventor Reference
|
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 SbProjector; 00096 class SbSphereProjector; 00097 class SbCylinderProjector; 00098 class SoFieldSensor; 00099 class SoTimerSensor; 00100 00101 00104 00191 00192 00193 class INVENTOR_API SoTrackballDragger : public SoDragger { 00194 00195 SO_KIT_HEADER(SoTrackballDragger); 00196 00198 SO_KIT_CATALOG_ENTRY_HEADER(surroundScale); 00200 SO_KIT_CATALOG_ENTRY_HEADER(antiSquish); 00201 00202 SO_KIT_CATALOG_ENTRY_HEADER(rotatorSwitch); 00203 SO_KIT_CATALOG_ENTRY_HEADER(rotator); 00204 SO_KIT_CATALOG_ENTRY_HEADER(rotatorActive); 00205 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorSwitch); 00206 SO_KIT_CATALOG_ENTRY_HEADER(XRotator); 00207 SO_KIT_CATALOG_ENTRY_HEADER(XRotatorActive); 00208 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorSwitch); 00209 SO_KIT_CATALOG_ENTRY_HEADER(YRotator); 00210 SO_KIT_CATALOG_ENTRY_HEADER(YRotatorActive); 00211 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorSwitch); 00212 SO_KIT_CATALOG_ENTRY_HEADER(ZRotator); 00213 SO_KIT_CATALOG_ENTRY_HEADER(ZRotatorActive); 00214 00216 SO_KIT_CATALOG_ENTRY_HEADER(userAxisRotation); 00217 00218 SO_KIT_CATALOG_ENTRY_HEADER(userAxisSwitch); 00219 SO_KIT_CATALOG_ENTRY_HEADER(userAxis); 00220 SO_KIT_CATALOG_ENTRY_HEADER(userAxisActive); 00221 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorSwitch); 00222 SO_KIT_CATALOG_ENTRY_HEADER(userRotator); 00223 SO_KIT_CATALOG_ENTRY_HEADER(userRotatorActive); 00224 00225 public: 00226 00228 SoTrackballDragger(); 00229 00230 SoSFRotation rotation; 00231 SoSFVec3f scaleFactor; 00232 00234 SbBool isAnimationEnabled() { return animationEnabled; } 00239 void setAnimationEnabled( SbBool newVal ); 00240 00241 SoINTERNAL public: 00242 static void initClass(); 00243 00244 protected: 00245 00247 static void startCB(void *, SoDragger *); 00248 static void motionCB(void *, SoDragger *); 00249 static void finishCB(void *, SoDragger *); 00250 00251 SoFieldSensor *rotFieldSensor; 00252 SoFieldSensor *scaleFieldSensor; 00253 static void fieldSensorCB( void *, SoSensor * ); 00254 static void valueChangedCB( void *, SoDragger * ); 00255 00257 static void metaKeyChangeCB(void *, SoDragger *); 00258 00260 void dragStart(); 00261 void drag(); 00262 void dragFinish(); 00263 00264 virtual void setAllPartsActive( SbBool onOrOff ); 00265 00272 virtual SbBool setUpConnections( SbBool onOff, SbBool doItAlways = FALSE ); 00273 00274 virtual void setDefaultOnNonWritingFields(); 00275 00276 virtual ~SoTrackballDragger(); 00277 00278 // Results of refactoring (MMS Bug: 57374): 00279 00281 SbSphereProjector *sphereProj; 00282 SbCylinderProjector *stripeProj; 00283 00284 SbBool ctlDown, shftDown; 00285 00286 enum State 00287 { INACTIVE, FREE_ROTATE, X_ROTATE, Y_ROTATE, Z_ROTATE, 00288 SCALE, USER_AXIS_ADJUST, USER_AXIS_ROTATE, SPINNING }; 00289 State currentState; 00290 00291 00295 virtual void initDragState(); 00296 00299 virtual SbProjector* initSphereProjector(SbVec3f center, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace); 00300 00303 virtual SbProjector* initStripeProjector(SbLine axis, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace); 00304 00306 virtual void getSphereDeltaRotation(SbRotation &deltaRot, SbVec3f &newHitPt, SbVec3f prevHitPt, SbMatrix workingSpace); 00307 00309 virtual void getStripeDeltaRotation(SbRotation &deltaRot, SbVec3f &newHitPt, SbVec3f prevHitPt, SbMatrix workingSpace); 00310 00311 private: 00312 00313 SbVec3f constrainedAxis; 00314 SbVec3f userAxisVec; 00315 00316 00317 SbVec3f startWorldHitPt; 00318 SbVec3f prevWorldHitPt; 00319 00320 SbMatrix prevMotionMatrix; 00321 00322 00324 void initSphereProjectorInternal(SbVec3f center, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace); 00325 00327 void initStripeProjectorInternal(SbLine axis, float radius, SbVec3f startWorkSpaceHitPt, SbMatrix workingSpace); 00328 00329 void setHighlights(); 00330 00331 SbBool rotateDrag(); 00332 SbBool scaleDrag(); 00333 SbBool userStripeDrag(); 00334 00336 static const char geomBuffer[]; 00337 00339 SbBool animationEnabled; 00340 SbTime prevTime; 00341 SbTime spinTime; 00342 SbTime scheduleRate; 00343 SoTimerSensor *spinSensor; 00344 SbRotation *rotBuffer; 00345 SbTime *timeBuffer; 00346 int firstIndex, lastIndex; 00347 SbVec3f averageAxis; 00348 float angleVelocity; 00349 SbBool computeAverage; 00350 00352 static void spinSensorCB(void *, SoSensor *); 00353 void spinAnimate(); 00354 void resetSpinStuff(); 00355 00360 SbBool wasSpinningAtDragStart; 00361 }; 00362 00363 #endif /* _SO_TRACKBALL_DRAGGER_ */