| 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 |
* Copyright (C) 1992 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| $Revision: 1.1.1.1 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoCenterballDragger |
| 47 |
| |
| 48 |
| Author(s): Paul Isaacs, Howard Look |
| 49 |
| |
| 50 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 |
_______________________________________________________________________ |
| 52 |
*/ |
| 53 |
|
| 54 |
|
| 55 |
#include <cstdio> |
| 56 |
|
| 57 |
#include <Inventor/SoDB.h> |
| 58 |
#include <Inventor/sensors/SoFieldSensor.h> |
| 59 |
|
| 60 |
#include <Inventor/events/SoEvent.h> |
| 61 |
#include <Inventor/actions/SoGetBoundingBoxAction.h> |
| 62 |
#include <Inventor/actions/SoGetMatrixAction.h> |
| 63 |
#include <Inventor/draggers/SoCenterballDragger.h> |
| 64 |
|
| 65 |
#include <Inventor/elements/SoModelMatrixElement.h> |
| 66 |
|
| 67 |
#include <Inventor/nodes/SoSeparator.h> |
| 68 |
#include <Inventor/nodes/SoRotation.h> |
| 69 |
#include <Inventor/nodes/SoLightModel.h> |
| 70 |
#include <Inventor/nodes/SoSwitch.h> |
| 71 |
#include <Inventor/nodes/SoSurroundScale.h> |
| 72 |
#include <Inventor/nodes/SoAntiSquish.h> |
| 73 |
|
| 74 |
#include <Inventor/draggers/SoTranslate2Dragger.h> |
| 75 |
#include <Inventor/draggers/SoRotateCylindricalDragger.h> |
| 76 |
#include <Inventor/draggers/SoRotateSphericalDragger.h> |
| 77 |
|
| 78 |
#include "geom/SoCenterballDraggerGeom.h" |
| 79 |
|
| 80 |
SO_KIT_SOURCE(SoCenterballDragger); |
| 81 |
|
| 82 |
|
| 83 |
//////////////////////////////////////////////////////////////////////// |
| 84 |
// |
| 85 |
// Description: |
| 86 |
// Constructor |
| 87 |
// |
| 88 |
SoCenterballDragger::SoCenterballDragger() |
| 89 |
// |
| 90 |
//////////////////////////////////////////////////////////////////////// |
| 91 |
{ |
| 92 |
SO_KIT_CONSTRUCTOR(SoDragger); |
| 93 |
|
| 94 |
isBuiltIn = TRUE; |
| 95 |
|
| 96 |
// Create the center translator, a matrix that will move |
| 97 |
// the dragger over the center. It's separate from the motion matrix |
| 98 |
// because 'center' does not affect an aggregate tranform matrix. |
| 99 |
SO_KIT_ADD_CATALOG_ENTRY(translateToCenter, SoMatrixTransform, TRUE, |
| 100 |
topSeparator, geomSeparator, TRUE); |
| 101 |
|
| 102 |
// Don't create this by default. It's only really put into use |
| 103 |
// if this dragger is put inside a manipulator. |
| 104 |
SO_KIT_ADD_CATALOG_ENTRY(surroundScale, SoSurroundScale, |
| 105 |
TRUE, topSeparator, geomSeparator, TRUE); |
| 106 |
// Create an anti-squish node by default. |
| 107 |
SO_KIT_ADD_CATALOG_ENTRY(antiSquish, SoAntiSquish, |
| 108 |
FALSE, topSeparator, geomSeparator, TRUE); |
| 109 |
|
| 110 |
// This whole manip gets modelled in BASE_COLOR |
| 111 |
SO_KIT_ADD_CATALOG_ENTRY(lightModel, SoLightModel, |
| 112 |
TRUE, topSeparator, geomSeparator,TRUE); |
| 113 |
|
| 114 |
// This little grouping goes under the geomSeparator, since it's |
| 115 |
// geometry only, not draggers. |
| 116 |
SO_KIT_ADD_CATALOG_ENTRY(XAxisSwitch, SoSwitch, TRUE, |
| 117 |
geomSeparator, ,FALSE); |
| 118 |
SO_KIT_ADD_CATALOG_ENTRY(XAxis, SoSeparator, TRUE, |
| 119 |
XAxisSwitch, ,TRUE); |
| 120 |
SO_KIT_ADD_CATALOG_ENTRY(YAxisSwitch, SoSwitch, TRUE, |
| 121 |
geomSeparator, ,FALSE); |
| 122 |
SO_KIT_ADD_CATALOG_ENTRY(YAxis, SoSeparator, TRUE, |
| 123 |
YAxisSwitch, ,TRUE); |
| 124 |
SO_KIT_ADD_CATALOG_ENTRY(ZAxisSwitch, SoSwitch, TRUE, |
| 125 |
geomSeparator, ,FALSE); |
| 126 |
SO_KIT_ADD_CATALOG_ENTRY(ZAxis, SoSeparator, TRUE, |
| 127 |
ZAxisSwitch, ,TRUE); |
| 128 |
|
| 129 |
// The rest of the stuff will go after the geomSeparator |
| 130 |
SO_KIT_ADD_CATALOG_ENTRY(rotator, SoRotateSphericalDragger, TRUE, |
| 131 |
topSeparator, ,TRUE); |
| 132 |
|
| 133 |
SO_KIT_ADD_CATALOG_ENTRY(YRotator, SoRotateCylindricalDragger, TRUE, |
| 134 |
topSeparator, ,TRUE); |
| 135 |
SO_KIT_ADD_CATALOG_ENTRY(ZCenterChanger, SoTranslate2Dragger, TRUE, |
| 136 |
topSeparator, ,TRUE); |
| 137 |
|
| 138 |
SO_KIT_ADD_CATALOG_ENTRY(rotX90, SoRotation, TRUE, |
| 139 |
topSeparator, ,FALSE); |
| 140 |
SO_KIT_ADD_CATALOG_ENTRY(ZRotator, SoRotateCylindricalDragger, TRUE, |
| 141 |
topSeparator, ,TRUE); |
| 142 |
SO_KIT_ADD_CATALOG_ENTRY(YCenterChanger, SoTranslate2Dragger, TRUE, |
| 143 |
topSeparator, ,TRUE); |
| 144 |
|
| 145 |
SO_KIT_ADD_CATALOG_ENTRY(rotY90, SoRotation, TRUE, |
| 146 |
topSeparator, ,FALSE); |
| 147 |
SO_KIT_ADD_CATALOG_ENTRY(XCenterChanger, SoTranslate2Dragger, TRUE, |
| 148 |
topSeparator, ,TRUE); |
| 149 |
|
| 150 |
SO_KIT_ADD_CATALOG_ENTRY(rot2X90, SoRotation, TRUE, |
| 151 |
topSeparator, ,FALSE); |
| 152 |
SO_KIT_ADD_CATALOG_ENTRY(XRotator, SoRotateCylindricalDragger, TRUE, |
| 153 |
topSeparator, ,TRUE); |
| 154 |
|
| 155 |
|
| 156 |
if ( SO_KIT_IS_FIRST_INSTANCE()) |
| 157 |
readDefaultParts("centerballDragger.iv",geomBuffer, sizeof(geomBuffer)); |
| 158 |
|
| 159 |
SO_KIT_ADD_FIELD(rotation, (0.0, 0.0, 0.0, 1.0)); |
| 160 |
SO_KIT_ADD_FIELD(center, (0.0, 0.0, 0.0)); |
| 161 |
|
| 162 |
SO_KIT_INIT_INSTANCE(); |
| 163 |
|
| 164 |
// Make the anti-squish node surround the biggest dimension |
| 165 |
SoAntiSquish *as = SO_GET_ANY_PART( this, "antiSquish", SoAntiSquish); |
| 166 |
as->sizing = SoAntiSquish::LONGEST_DIAGONAL; |
| 167 |
|
| 168 |
// Make the dragger phong shaded by default. |
| 169 |
SoLightModel *lm = new SoLightModel; |
| 170 |
lm->model = SoLightModel::PHONG; |
| 171 |
setAnyPartAsDefault( "lightModel", lm ); |
| 172 |
|
| 173 |
// Create the child draggers that live under this dragger. |
| 174 |
|
| 175 |
// ROTATOR BALL |
| 176 |
SoDragger *ball = (SoDragger *) getAnyPart("rotator", TRUE ); |
| 177 |
|
| 178 |
// STRIPES |
| 179 |
SoDragger *stps[3]; |
| 180 |
stps[0] = SO_GET_ANY_PART(this,"XRotator", SoDragger); |
| 181 |
stps[1] = SO_GET_ANY_PART(this,"YRotator", SoDragger); |
| 182 |
stps[2] = SO_GET_ANY_PART(this,"ZRotator", SoDragger); |
| 183 |
|
| 184 |
// CENTER CHANGERS |
| 185 |
SoDragger *ccs[3]; |
| 186 |
ccs[0] = SO_GET_ANY_PART(this,"XCenterChanger", SoDragger); |
| 187 |
ccs[1] = SO_GET_ANY_PART(this,"YCenterChanger", SoDragger); |
| 188 |
ccs[2] = SO_GET_ANY_PART(this,"ZCenterChanger", SoDragger); |
| 189 |
|
| 190 |
// AXES |
| 191 |
setPartAsDefault("XAxis", "centerballXAxis"); |
| 192 |
setPartAsDefault("YAxis", "centerballYAxis"); |
| 193 |
setPartAsDefault("ZAxis", "centerballZAxis"); |
| 194 |
|
| 195 |
// Turn off the axes completely. They're just used as feedback |
| 196 |
setSwitchValue( XAxisSwitch.getValue(), SO_SWITCH_NONE ); |
| 197 |
setSwitchValue( YAxisSwitch.getValue(), SO_SWITCH_NONE ); |
| 198 |
setSwitchValue( ZAxisSwitch.getValue(), SO_SWITCH_NONE ); |
| 199 |
|
| 200 |
// Rotation nodes that orient the parts... |
| 201 |
SoRotation *rNodeX90 = new SoRotation; |
| 202 |
SoRotation *rNodeY90 = new SoRotation; |
| 203 |
rNodeX90->rotation.setValue( SbVec3f(1,0,0), 1.57079 ); |
| 204 |
rNodeY90->rotation.setValue( SbVec3f(0,1,0), 1.57079 ); |
| 205 |
|
| 206 |
setAnyPartAsDefault( "rotX90", rNodeX90 ); |
| 207 |
setAnyPartAsDefault( "rotY90", rNodeY90 ); |
| 208 |
setAnyPartAsDefault( "rot2X90", rNodeX90 ); |
| 209 |
|
| 210 |
// Update the rotation field when the motionMatrix is set. |
| 211 |
addValueChangedCallback( &SoCenterballDragger::valueChangedCB ); |
| 212 |
|
| 213 |
// Updates the motionMatrix when the rotation field is set. |
| 214 |
rotFieldSensor= new SoFieldSensor(&SoCenterballDragger::fieldSensorCB,this); |
| 215 |
rotFieldSensor->setPriority(0); |
| 216 |
|
| 217 |
// Updates the motionMatrix when the center field is set. |
| 218 |
centerFieldSensor= new SoFieldSensor( |
| 219 |
&SoCenterballDragger::fieldSensorCB, this); |
| 220 |
centerFieldSensor->setPriority(0); |
| 221 |
|
| 222 |
setUpConnections( TRUE, TRUE ); |
| 223 |
} |
| 224 |
|
| 225 |
//////////////////////////////////////////////////////////////////////// |
| 226 |
// |
| 227 |
// Description: |
| 228 |
// Destructor. |
| 229 |
// |
| 230 |
// Use: public |
| 231 |
|
| 232 |
SoCenterballDragger::~SoCenterballDragger() |
| 233 |
// |
| 234 |
//////////////////////////////////////////////////////////////////////// |
| 235 |
{ |
| 236 |
if (rotFieldSensor) |
| 237 |
delete rotFieldSensor; |
| 238 |
if (centerFieldSensor) |
| 239 |
delete centerFieldSensor; |
| 240 |
} |
| 241 |
|
| 242 |
// detach/attach any sensors, callbacks, and/or field connections. |
| 243 |
// Called by: start/end of SoBaseKit::readInstance |
| 244 |
// and on new copy by: start/end of SoBaseKit::copy. |
| 245 |
// Classes that redefine must call setUpConnections(TRUE,TRUE) |
| 246 |
// at end of constructor. |
| 247 |
// Returns the state of the node when this was called. |
| 248 |
SbBool |
| 249 |
SoCenterballDragger::setUpConnections( SbBool onOff, SbBool doItAlways ) |
| 250 |
{ |
| 251 |
if ( !doItAlways && connectionsSetUp == onOff) |
| 252 |
return onOff; |
| 253 |
|
| 254 |
if ( onOff ) { |
| 255 |
|
| 256 |
// We connect AFTER base class. |
| 257 |
SoDragger::setUpConnections( onOff, FALSE ); |
| 258 |
|
| 259 |
// FIRST, DEAL WITH CHILD DRAGGERS: |
| 260 |
// Set the default parts and add callback to our child draggers. |
| 261 |
// The parts will only be changed if they are still set as default. |
| 262 |
// So we won't stomp over a non-default, intentionally set part. |
| 263 |
SoSeparator *dummySep = new SoSeparator; |
| 264 |
dummySep->ref(); |
| 265 |
|
| 266 |
// BALL |
| 267 |
SoDragger *ball; |
| 268 |
ball = (SoDragger *) getAnyPart( "rotator", FALSE ); |
| 269 |
if (ball != NULL) { |
| 270 |
ball->setPartAsDefault("rotator", "centerballRotator"); |
| 271 |
ball->setPartAsDefault("rotatorActive","centerballRotatorActive"); |
| 272 |
ball->setPartAsDefault("feedback", dummySep); |
| 273 |
ball->setPartAsDefault("feedbackActive",dummySep); |
| 274 |
registerChildDragger( ball ); |
| 275 |
ball->addStartCallback(&SoCenterballDragger::kidStartCB, this ); |
| 276 |
ball->addFinishCallback(&SoCenterballDragger::kidFinishCB, this ); |
| 277 |
} |
| 278 |
|
| 279 |
// STRIPES |
| 280 |
SoDragger *stps[3]; |
| 281 |
stps[0] = (SoDragger *) getAnyPart("XRotator", FALSE); |
| 282 |
stps[1] = (SoDragger *) getAnyPart("YRotator", FALSE); |
| 283 |
stps[2] = (SoDragger *) getAnyPart("ZRotator", FALSE); |
| 284 |
int i; |
| 285 |
for (i = 0; i < 3; i++) { |
| 286 |
if ( stps[i] == NULL ) continue; |
| 287 |
stps[i]->setPartAsDefault("rotator", "centerballStripe" ); |
| 288 |
stps[i]->setPartAsDefault("rotatorActive","centerballStripeActive"); |
| 289 |
stps[i]->setPartAsDefault("feedback", dummySep ); |
| 290 |
stps[i]->setPartAsDefault("feedbackActive",dummySep ); |
| 291 |
registerChildDragger( stps[i] ); |
| 292 |
stps[i]->addStartCallback(&SoCenterballDragger::kidStartCB,this); |
| 293 |
stps[i]->addFinishCallback(&SoCenterballDragger::kidFinishCB,this); |
| 294 |
} |
| 295 |
// CENTER CHANGERS |
| 296 |
SoDragger *ccs[3]; |
| 297 |
ccs[0] = (SoDragger *) getAnyPart("XCenterChanger", FALSE ); |
| 298 |
ccs[1] = (SoDragger *) getAnyPart("YCenterChanger", FALSE ); |
| 299 |
ccs[2] = (SoDragger *) getAnyPart("ZCenterChanger", FALSE ); |
| 300 |
for (i = 0; i < 3; i++) { |
| 301 |
if ( ccs[i] == NULL ) continue; |
| 302 |
ccs[i]->setPartAsDefault("translator", |
| 303 |
"centerballCenterChanger"); |
| 304 |
ccs[i]->setPartAsDefault("translatorActive", |
| 305 |
"centerballCenterChangerActive"); |
| 306 |
ccs[i]->setPartAsDefault("feedback", dummySep ); |
| 307 |
ccs[i]->setPartAsDefault("feedbackActive", dummySep ); |
| 308 |
ccs[i]->setPartAsDefault("xAxisFeedback", |
| 309 |
"centerballCenterXAxisFeedback"); |
| 310 |
ccs[i]->setPartAsDefault("yAxisFeedback", |
| 311 |
"centerballCenterYAxisFeedback"); |
| 312 |
|
| 313 |
// When the centers translate, they should not affect our |
| 314 |
// motion matrix. Instead, they affect our translateToCenter |
| 315 |
// node. |
| 316 |
registerChildDraggerMovingIndependently( ccs[i] ); |
| 317 |
ccs[i]->addStartCallback(&SoCenterballDragger::kidStartCB,this); |
| 318 |
ccs[i]->addFinishCallback(&SoCenterballDragger::kidFinishCB,this); |
| 319 |
} |
| 320 |
dummySep->unref(); |
| 321 |
|
| 322 |
// Call the sensor CBs to make things are up-to-date. |
| 323 |
fieldSensorCB( this, NULL ); |
| 324 |
|
| 325 |
// Connect the field sensors |
| 326 |
if (rotFieldSensor->getAttachedField() != &rotation) |
| 327 |
rotFieldSensor->attach( &rotation ); |
| 328 |
if (centerFieldSensor->getAttachedField() != ¢er) |
| 329 |
centerFieldSensor->attach( ¢er ); |
| 330 |
} |
| 331 |
else { |
| 332 |
|
| 333 |
// We disconnect BEFORE base class. |
| 334 |
|
| 335 |
// Disconnect the field sensors. |
| 336 |
if (rotFieldSensor->getAttachedField()) |
| 337 |
rotFieldSensor->detach(); |
| 338 |
if (centerFieldSensor->getAttachedField()) |
| 339 |
centerFieldSensor->detach(); |
| 340 |
|
| 341 |
// REMOVE callbacks from our child draggers: |
| 342 |
// BALL |
| 343 |
SoDragger *ball; |
| 344 |
ball = (SoDragger *) getAnyPart( "rotator", FALSE ); |
| 345 |
if (ball != NULL) { |
| 346 |
unregisterChildDragger( ball ); |
| 347 |
ball->removeStartCallback(&SoCenterballDragger::kidStartCB, this ); |
| 348 |
ball->removeFinishCallback(&SoCenterballDragger::kidFinishCB, this ); |
| 349 |
} |
| 350 |
|
| 351 |
// STRIPES |
| 352 |
SoDragger *stps[3]; |
| 353 |
stps[0] = (SoDragger *) getAnyPart("XRotator", FALSE); |
| 354 |
stps[1] = (SoDragger *) getAnyPart("YRotator", FALSE); |
| 355 |
stps[2] = (SoDragger *) getAnyPart("ZRotator", FALSE); |
| 356 |
int i; |
| 357 |
for (i = 0; i < 3; i++) { |
| 358 |
if ( stps[i] == NULL ) continue; |
| 359 |
unregisterChildDragger( stps[i] ); |
| 360 |
stps[i]->removeStartCallback(&SoCenterballDragger::kidStartCB,this); |
| 361 |
stps[i]->removeFinishCallback(&SoCenterballDragger::kidFinishCB,this); |
| 362 |
} |
| 363 |
// CENTER CHANGERS |
| 364 |
SoDragger *ccs[3]; |
| 365 |
ccs[0] = (SoDragger *) getAnyPart("XCenterChanger", FALSE ); |
| 366 |
ccs[1] = (SoDragger *) getAnyPart("YCenterChanger", FALSE ); |
| 367 |
ccs[2] = (SoDragger *) getAnyPart("ZCenterChanger", FALSE ); |
| 368 |
for (i = 0; i < 3; i++) { |
| 369 |
if ( ccs[i] == NULL ) continue; |
| 370 |
unregisterChildDraggerMovingIndependently( ccs[i] ); |
| 371 |
ccs[i]->removeStartCallback(&SoCenterballDragger::kidStartCB,this); |
| 372 |
ccs[i]->removeFinishCallback(&SoCenterballDragger::kidFinishCB,this); |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
SoDragger::setUpConnections( onOff, FALSE ); |
| 377 |
} |
| 378 |
|
| 379 |
return !(connectionsSetUp = onOff); |
| 380 |
} |
| 381 |
|
| 382 |
void |
| 383 |
SoCenterballDragger::valueChangedCB(void *, SoDragger *inDragger ) |
| 384 |
{ |
| 385 |
SoCenterballDragger *dBall = (SoCenterballDragger *) inDragger; |
| 386 |
|
| 387 |
// If the value was changed due to a centerDragger, transfer the |
| 388 |
// centerDragger motion into our 'translateToCenter' matrix. |
| 389 |
SoDragger *cd = dBall->getActiveChildDragger(); |
| 390 |
if ( cd != NULL && |
| 391 |
( cd == dBall->XCenterChanger.getValue() || |
| 392 |
cd == dBall->YCenterChanger.getValue() || |
| 393 |
cd == dBall->ZCenterChanger.getValue() ) ) { |
| 394 |
|
| 395 |
// Temporarily disable callbacks, since within this method |
| 396 |
// we'll be resetting the centerDragger's motion matrix |
| 397 |
// to identity, which would re-trigger this callback. |
| 398 |
SbBool saveEnabled = dBall->enableValueChangedCallbacks( FALSE ); |
| 399 |
dBall->transferCenterDraggerMotion( cd ); |
| 400 |
dBall->enableValueChangedCallbacks( saveEnabled ); |
| 401 |
|
| 402 |
// No reason to call valueChanged() here. This should always |
| 403 |
// be the first callback in our valueChangedCallback list. |
| 404 |
return; |
| 405 |
} |
| 406 |
|
| 407 |
// Otherwise, the value was changed by something other than a |
| 408 |
// centerDragger. We treat it as an oridinary change affecting the |
| 409 |
// motionMatrix. |
| 410 |
SbMatrix motMat = dBall->getMotionMatrix(); |
| 411 |
|
| 412 |
SbVec3f trans, scale; |
| 413 |
SbRotation rot, scaleOrient; |
| 414 |
const SbVec3f ¢er = dBall->center.getValue(); |
| 415 |
motMat.getTransform(trans,rot,scale,scaleOrient,center); |
| 416 |
|
| 417 |
// Disconnect the field sensor |
| 418 |
dBall->rotFieldSensor->detach(); |
| 419 |
|
| 420 |
if ( dBall->rotation.getValue() != rot ) |
| 421 |
dBall->rotation = rot; |
| 422 |
|
| 423 |
// Reconnect the field sensor |
| 424 |
dBall->rotFieldSensor->attach( &(dBall->rotation) ); |
| 425 |
} |
| 426 |
|
| 427 |
void |
| 428 |
SoCenterballDragger::fieldSensorCB(void *inDragger, SoSensor *inSensor ) |
| 429 |
{ |
| 430 |
SoCenterballDragger *dragger = (SoCenterballDragger *) inDragger; |
| 431 |
|
| 432 |
SoField *trigF = NULL; |
| 433 |
if ( inSensor ) |
| 434 |
trigF = ((SoDataSensor *)inSensor)->getTriggerField(); |
| 435 |
|
| 436 |
// If inSensor is NULL or the trigger field is NULL, we will |
| 437 |
// do both the matrix and center stuff, since we don't know what changed. |
| 438 |
SbBool doMatrix = TRUE; |
| 439 |
SbBool doCenter = TRUE; |
| 440 |
|
| 441 |
// But if this is invoked by a sensor with a trigger field, |
| 442 |
// we can do different things if it was the center |
| 443 |
// or the rotation fields that triggered. |
| 444 |
if ( trigF ) { |
| 445 |
|
| 446 |
if ( trigF == &dragger->rotation ) |
| 447 |
doCenter = FALSE; |
| 448 |
|
| 449 |
if ( trigF == &dragger->center ) |
| 450 |
doMatrix = FALSE; |
| 451 |
} |
| 452 |
|
| 453 |
if ( doCenter ) { |
| 454 |
|
| 455 |
// Center field is given in local space of the motionmatrix. |
| 456 |
// Copy this value as a translation into the translateToCenter matrix |
| 457 |
SbVec3f center = dragger->center.getValue(); |
| 458 |
|
| 459 |
// Build a matrix to translate the origin of the ball |
| 460 |
// to the transformed center... |
| 461 |
SbMatrix newMat; |
| 462 |
newMat.setTranslate( center ); |
| 463 |
|
| 464 |
// Set the translate to center matrix... |
| 465 |
SoMatrixTransform *mx = SO_GET_ANY_PART(dragger,"translateToCenter", |
| 466 |
SoMatrixTransform ); |
| 467 |
mx->matrix = newMat; |
| 468 |
|
| 469 |
// We need to specifically tell the dragger to invoke the |
| 470 |
// value changed callbacks, since only calling setMotionMatrix |
| 471 |
// automatically does this. |
| 472 |
if ( doMatrix == FALSE ) |
| 473 |
dragger->valueChanged(); |
| 474 |
} |
| 475 |
|
| 476 |
if ( doMatrix ) { |
| 477 |
|
| 478 |
SbMatrix motMat = dragger->getMotionMatrix(); |
| 479 |
dragger->workFieldsIntoTransform(motMat); |
| 480 |
|
| 481 |
dragger->setMotionMatrix(motMat); |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
void |
| 486 |
SoCenterballDragger::kidStartCB( void *parentAsVoid, SoDragger *childM ) |
| 487 |
{ |
| 488 |
// ESTABLISHES HIGHLIGHTS and TELLS THE SURROUNDSCALE PART TO UPDATE |
| 489 |
|
| 490 |
SoCenterballDragger *cbD = (SoCenterballDragger *) parentAsVoid; |
| 491 |
|
| 492 |
// DEAL WITH SURROUNDSCALE |
| 493 |
SoSurroundScale *ss = SO_CHECK_PART(cbD, "surroundScale", SoSurroundScale ); |
| 494 |
if (ss != NULL) |
| 495 |
ss->invalidate(); |
| 496 |
|
| 497 |
cbD->setSwitches( childM ); |
| 498 |
|
| 499 |
} |
| 500 |
|
| 501 |
void |
| 502 |
SoCenterballDragger::kidFinishCB( void *parentAsVoid, SoDragger * ) |
| 503 |
{ |
| 504 |
SoCenterballDragger *cbD = (SoCenterballDragger *) parentAsVoid; |
| 505 |
|
| 506 |
// ESTABLISHES HIGHLIGHTS and TELLS THE SURROUNDSCALE PART TO UPDATE |
| 507 |
|
| 508 |
// DEAL WITH SURROUNDSCALE |
| 509 |
SoSurroundScale *ss = SO_CHECK_PART(cbD, "surroundScale", SoSurroundScale ); |
| 510 |
if (ss != NULL) |
| 511 |
ss->invalidate(); |
| 512 |
|
| 513 |
cbD->setSwitches( NULL ); |
| 514 |
} |
| 515 |
|
| 516 |
void |
| 517 |
SoCenterballDragger::setSwitches( SoDragger *activeChild ) |
| 518 |
{ |
| 519 |
// Figure out what we are doing... |
| 520 |
SbBool freeRotate = ( activeChild && activeChild == rotator.getValue()); |
| 521 |
SbBool changeCenter = ( activeChild && |
| 522 |
( activeChild == XCenterChanger.getValue() |
| 523 |
|| activeChild == YCenterChanger.getValue() |
| 524 |
|| activeChild == ZCenterChanger.getValue())); |
| 525 |
SbBool xRotate = (activeChild && activeChild == XRotator.getValue()); |
| 526 |
SbBool yRotate = (activeChild && activeChild == YRotator.getValue()); |
| 527 |
SbBool zRotate = (activeChild && activeChild == ZRotator.getValue()); |
| 528 |
|
| 529 |
// ROTATOR - only highlight during free rotation |
| 530 |
if ( freeRotate ) |
| 531 |
setSwitchValue( getAnyPart("rotator.rotatorSwitch",FALSE ), 1); |
| 532 |
else |
| 533 |
setSwitchValue( getAnyPart("rotator.rotatorSwitch",FALSE ), 0); |
| 534 |
|
| 535 |
// TRANSLATORS - ALL hilight during free rotation or centerChanging |
| 536 |
if ( freeRotate || changeCenter ) { |
| 537 |
setSwitchValue(getAnyPart("XCenterChanger.translatorSwitch",FALSE),1); |
| 538 |
setSwitchValue(getAnyPart("YCenterChanger.translatorSwitch",FALSE),1); |
| 539 |
setSwitchValue(getAnyPart("ZCenterChanger.translatorSwitch",FALSE),1); |
| 540 |
} |
| 541 |
else { |
| 542 |
setSwitchValue(getAnyPart("XCenterChanger.translatorSwitch",FALSE),0); |
| 543 |
setSwitchValue(getAnyPart("YCenterChanger.translatorSwitch",FALSE),0); |
| 544 |
setSwitchValue(getAnyPart("ZCenterChanger.translatorSwitch",FALSE),0); |
| 545 |
} |
| 546 |
|
| 547 |
// STRIPES - ALL hilight during free rotation |
| 548 |
// Each hilights during its own rotation |
| 549 |
if ( freeRotate || xRotate ) |
| 550 |
setSwitchValue( getAnyPart("XRotator.rotatorSwitch",FALSE), 1); |
| 551 |
else |
| 552 |
setSwitchValue( getAnyPart("XRotator.rotatorSwitch",FALSE), 0); |
| 553 |
|
| 554 |
if ( freeRotate || yRotate ) |
| 555 |
setSwitchValue( getAnyPart("YRotator.rotatorSwitch",FALSE), 1); |
| 556 |
else |
| 557 |
setSwitchValue( getAnyPart("YRotator.rotatorSwitch",FALSE), 0); |
| 558 |
|
| 559 |
if ( freeRotate || zRotate ) |
| 560 |
setSwitchValue( getAnyPart("ZRotator.rotatorSwitch",FALSE), 1); |
| 561 |
else |
| 562 |
setSwitchValue( getAnyPart("ZRotator.rotatorSwitch",FALSE), 0); |
| 563 |
|
| 564 |
// AXES - ALL displayed during rotation or center changing. |
| 565 |
// Each displayed during its rotation. |
| 566 |
if ( freeRotate || changeCenter || xRotate ) |
| 567 |
setSwitchValue( XAxisSwitch.getValue(), 0 ); |
| 568 |
else |
| 569 |
setSwitchValue( XAxisSwitch.getValue(), SO_SWITCH_NONE ); |
| 570 |
|
| 571 |
if ( freeRotate || changeCenter || yRotate ) |
| 572 |
setSwitchValue( YAxisSwitch.getValue(), 0 ); |
| 573 |
else |
| 574 |
setSwitchValue( YAxisSwitch.getValue(), SO_SWITCH_NONE ); |
| 575 |
|
| 576 |
if ( freeRotate || changeCenter || zRotate ) |
| 577 |
setSwitchValue( ZAxisSwitch.getValue(), 0 ); |
| 578 |
else |
| 579 |
setSwitchValue( ZAxisSwitch.getValue(), SO_SWITCH_NONE ); |
| 580 |
} |
| 581 |
|
| 582 |
//////////////////////////////////////////////////////////////////////// |
| 583 |
// |
| 584 |
// Description: |
| 585 |
// Saves the matrix that moves the center relative to the rest of the |
| 586 |
// parts after it calls the regular SoDragger method. |
| 587 |
// |
| 588 |
void |
| 589 |
SoCenterballDragger::saveStartParameters() |
| 590 |
// |
| 591 |
//////////////////////////////////////////////////////////////////////// |
| 592 |
{ |
| 593 |
SoDragger::saveStartParameters(); |
| 594 |
|
| 595 |
SoMatrixTransform *thePart |
| 596 |
= SO_GET_ANY_PART(this,"translateToCenter",SoMatrixTransform); |
| 597 |
|
| 598 |
this->startCenterMatrix = thePart->matrix.getValue(); |
| 599 |
} |
| 600 |
|
| 601 |
//////////////////////////////////////////////////////////////////////// |
| 602 |
// |
| 603 |
// Description: |
| 604 |
// This function is invoked by the valueChangedCB if the |
| 605 |
// reason was because a centerDragger was moved. |
| 606 |
// |
| 607 |
void |
| 608 |
SoCenterballDragger::transferCenterDraggerMotion( SoDragger *childDragger ) |
| 609 |
// |
| 610 |
//////////////////////////////////////////////////////////////////////// |
| 611 |
{ |
| 612 |
// Get the motion matrix from the child |
| 613 |
SbMatrix childMotion = childDragger->getMotionMatrix(); |
| 614 |
|
| 615 |
// There's a lot we don't need to bother with if the childMotion is |
| 616 |
// identity... |
| 617 |
SbBool childIdent = ( childMotion == SbMatrix::identity() ); |
| 618 |
|
| 619 |
// Return if childMotion is identity and our center matrix has not changed. |
| 620 |
SoMatrixTransform *centerTranslatePart |
| 621 |
= SO_GET_ANY_PART(this,"translateToCenter",SoMatrixTransform); |
| 622 |
SbMatrix curCenterMatrix = centerTranslatePart->matrix.getValue(); |
| 623 |
if ( childIdent && (curCenterMatrix == startCenterMatrix) ) |
| 624 |
return; |
| 625 |
|
| 626 |
if (!childIdent) { |
| 627 |
// First, set the childDragger matrix to identity. |
| 628 |
childDragger->setMotionMatrix( SbMatrix::identity() ); |
| 629 |
|
| 630 |
// Convert the childMotion from child LOCAL space to world space |
| 631 |
childDragger->transformMatrixLocalToWorld(childMotion, childMotion); |
| 632 |
|
| 633 |
// Convert the childMotion from world space to our LOCAL space. |
| 634 |
transformMatrixWorldToLocal(childMotion,childMotion); |
| 635 |
} |
| 636 |
|
| 637 |
// Multiply the local space motion by the parent's |
| 638 |
// 'startCenterMatrix'. We start with childMotion in space before parent, |
| 639 |
// so we use a multRight, not multLeft. |
| 640 |
SbMatrix newCenterMatrix = startCenterMatrix; |
| 641 |
if ( !childIdent ) |
| 642 |
newCenterMatrix.multRight( childMotion ); |
| 643 |
centerTranslatePart->matrix = newCenterMatrix; |
| 644 |
|
| 645 |
// Now determine and set the field value... |
| 646 |
// Disconnect the field sensors |
| 647 |
centerFieldSensor->detach(); |
| 648 |
|
| 649 |
// Figure out the center |
| 650 |
SbVec3f newCenter(curCenterMatrix[3][0], |
| 651 |
curCenterMatrix[3][1], |
| 652 |
curCenterMatrix[3][2]); |
| 653 |
|
| 654 |
// Set the field if we need to... |
| 655 |
if ( center.getValue() != newCenter ) |
| 656 |
center = newCenter; |
| 657 |
|
| 658 |
// Reconnect the field sensors |
| 659 |
centerFieldSensor->attach( &(center) ); |
| 660 |
|
| 661 |
// Force child to update its local matrix. (it changes when parent moves.) |
| 662 |
SoPath *myPath = childDragger->createPathToThis(); |
| 663 |
// Important to ref and unref, or the path will not get deleted. |
| 664 |
if (myPath) myPath->ref(); |
| 665 |
childDragger->setTempPathToThis(myPath); |
| 666 |
if (myPath) myPath->unref(); |
| 667 |
} |
| 668 |
|
| 669 |
void |
| 670 |
SoCenterballDragger::setDefaultOnNonWritingFields() |
| 671 |
{ |
| 672 |
// These nodes may change after construction, but we still |
| 673 |
// don't want to write them out. |
| 674 |
surroundScale.setDefault(TRUE); |
| 675 |
antiSquish.setDefault(TRUE); |
| 676 |
translateToCenter.setDefault(TRUE); |
| 677 |
|
| 678 |
// Try not to write out the sub-draggers. |
| 679 |
rotator.setDefault(TRUE); |
| 680 |
|
| 681 |
XRotator.setDefault(TRUE); |
| 682 |
YRotator.setDefault(TRUE); |
| 683 |
ZRotator.setDefault(TRUE); |
| 684 |
|
| 685 |
XCenterChanger.setDefault(TRUE); |
| 686 |
YCenterChanger.setDefault(TRUE); |
| 687 |
ZCenterChanger.setDefault(TRUE); |
| 688 |
|
| 689 |
// Call the base class... |
| 690 |
SoDragger::setDefaultOnNonWritingFields(); |
| 691 |
} |
| 692 |
|
| 693 |
//////////////////////////////////////////////////////////////////////// |
| 694 |
// |
| 695 |
// Description: |
| 696 |
// Differs from SoDragger as follows: If it has a surroundScale node with |
| 697 |
// 'ignoreInBbox' set to TRUE, this means surroundScale is calculating its |
| 698 |
// bbox for sizing. We need to tell the surroundScale not to |
| 699 |
// do translations. |
| 700 |
// |
| 701 |
// Use: protected |
| 702 |
// |
| 703 |
void |
| 704 |
SoCenterballDragger::getBoundingBox(SoGetBoundingBoxAction *action) |
| 705 |
// |
| 706 |
//////////////////////////////////////////////////////////////////////// |
| 707 |
{ |
| 708 |
SbBool oldFlag = TRUE; |
| 709 |
SoSurroundScale *ss = SO_CHECK_PART(this, "surroundScale", SoSurroundScale); |
| 710 |
if (ss) { |
| 711 |
oldFlag = ss->isDoingTranslations(); |
| 712 |
ss->setDoingTranslations(FALSE); |
| 713 |
} |
| 714 |
|
| 715 |
// Call base class method |
| 716 |
SoDragger::getBoundingBox( action ); |
| 717 |
|
| 718 |
if (ss) |
| 719 |
ss->setDoingTranslations(oldFlag); |
| 720 |
} |
| 721 |
//////////////////////////////////////////////////////////////////////// |
| 722 |
// |
| 723 |
// Description: |
| 724 |
// Differs from SoDragger as follows: If it has a surroundScale node with |
| 725 |
// 'ignoreInBbox' set to TRUE, this means surroundScale is calculating its |
| 726 |
// bbox for sizing. We need to tell the surroundScale not to |
| 727 |
// do translations. |
| 728 |
// |
| 729 |
// Use: protected |
| 730 |
// |
| 731 |
void |
| 732 |
SoCenterballDragger::getMatrix(SoGetMatrixAction *action) |
| 733 |
// |
| 734 |
//////////////////////////////////////////////////////////////////////// |
| 735 |
{ |
| 736 |
SbBool oldFlag = TRUE; |
| 737 |
SoSurroundScale *ss = SO_CHECK_PART(this, "surroundScale", SoSurroundScale); |
| 738 |
if (ss) { |
| 739 |
oldFlag = ss->isDoingTranslations(); |
| 740 |
ss->setDoingTranslations(FALSE); |
| 741 |
} |
| 742 |
|
| 743 |
// Call base class method |
| 744 |
SoDragger::getMatrix( action ); |
| 745 |
|
| 746 |
if (ss) |
| 747 |
ss->setDoingTranslations(oldFlag); |
| 748 |
} |