//////////////////////////////////////////////////////////////////////// // // Description: // Rotate the rotateDiscDragger based on mouse motion. // // Use: private // void SoRotateDiscDragger::drag() // //////////////////////////////////////////////////////////////////////// { // Set up the projector space and view. // Working space is space at end of motion matrix. planeProj->setViewVolume( getViewVolume() ); planeProj->setWorkingSpace( getLocalToWorldMatrix() ); // Get newHitPt and startHitPt in workspace. SbVec3f newHitPt = planeProj->project( getNormalizedLocaterPosition()); SbVec3f startHitPt = getLocalStartingPoint(); // Find the amount of rotation SbVec3f oldVec = startHitPt; SbVec3f newVec = newHitPt; // Remove the part of these vectors that is parallel to the normal oldVec -= SbVec3f( 0, 0, oldVec[2] ); newVec -= SbVec3f( 0, 0, newVec[2] ); // deltaRot is how much we rotated since the mouse button went down. SbRotation deltaRot = SbRotation( oldVec, newVec ); // Append this to the startMotionMatrix, which we saved at the beginning // of the drag, to find the current motion matrix. setMotionMatrix( appendRotation( getStartMotionMatrix(), deltaRot, SbVec3f(0,0,0))); }
//////////////////////////////////////////////////////////////////////// // // Description: // Stretch the dragger according to the motion along the plane // projector // // Use: private // void SoTranslate2Dragger::drag() // //////////////////////////////////////////////////////////////////////// { // Set up the projector space and view. // Working space is space at end of motion matrix. planeProj->setViewVolume( getViewVolume() ); planeProj->setWorkingSpace( getLocalToWorldMatrix() ); // Get newHitPt and startHitPt in workspace. SbVec3f newHitPt = planeProj->project( getNormalizedLocaterPosition()); SbVec3f startHitPt = getLocalStartingPoint(); // Convert newHitPt to world space and save this as our new worldRestartPt getLocalToWorldMatrix().multVecMatrix( newHitPt, worldRestartPt ); // Figure out the translation relative to start position. SbVec3f motion = newHitPt - startHitPt; // Maybe we need to constrain the motion... if ( !shftDown ) translateDir = -1; else { // The shift key is pressed. This means 1-D translation. if ( translateDir == -1 ) { // The 1-D direction is not defined. Calculate it based on which // direction got the maximum locater motion. if ( isAdequateConstraintMotion() ) { if ( fabs( motion[0]) > fabs( motion[1])) translateDir = 0; else translateDir = 1; // Set the axis feedback switch to the given direction. setSwitchValue( axisFeedbackSwitch.getValue(), translateDir ); } else { // Not ready to pick a direction yet. Don't move. return; } } // get the projection of 'motion' onto the preferred axis. SbVec3f constrainedMotion(0,0,0); constrainedMotion[translateDir] = motion[translateDir]; motion = constrainedMotion; } // Append this to the startMotionMatrix, which we saved at the beginning // of the drag, to find the current motion matrix. setMotionMatrix( appendTranslation( getStartMotionMatrix(), motion ) ); }
void TranslateRadialDragger:: drag() { // Things can change between renderings. To be safe, update // the projector with the current values. lineProj->setViewVolume(getViewVolume()); lineProj->setWorkingSpace(getLocalToWorldMatrix()); // Find the new intersection on the projector. SbVec3f newHitPt = lineProj->project(getNormalizedLocaterPosition()); // Get initial point expressed in our current local space. SbVec3f startHitPt = getLocalStartingPoint(); // Motion in local space is difference between old and // new positions. SbVec3f motion = newHitPt - startHitPt; // Append this to the startMotionMatrix, which was saved // automatically at the beginning of the drag, to find // the current motion matrix. setMotionMatrix( appendTranslation(getStartMotionMatrix(), motion)); }
//////////////////////////////////////////////////////////////////////// // // Description: // Sets the feedback geometry depending on which dragger is active. // A 1-D translator results in that line's feedback turning on. // A 2-D translator results in that plane's feedback turning on. // // Use: private // void SoDragPointDragger::setFeedbackGeometry() // //////////////////////////////////////////////////////////////////////// { // First, figure out if we need to know a constrained translation // direction. This happens if a plane dragger is in use, but is // being constrained. int translateDir = -1; #define TINY .0001 if ( shftDown ) { SbVec3f current = getMotionMatrix()[3]; SbVec3f start = getStartMotionMatrix()[3]; SbVec3f motion = current - start; if ( fabs( motion[0]) > fabs( motion[1]) && fabs( motion[0]) > fabs( motion[2])) translateDir = 0; else if ( fabs( motion[1]) > fabs( motion[2])) translateDir = 1; else if ( fabs( motion[2] ) > TINY ) translateDir = 2; } #undef TINY // Turn on appropriate parts, based on state. if (currentDragger == NULL) { setSwitchValue(xFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(yFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(zFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(planeFeedbackSwitch.getValue(), SO_SWITCH_NONE ); } else if (currentDragger == xTranslator.getValue() ) { setSwitchValue(xFeedbackSwitch.getValue(), 0 ); setSwitchValue(yFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(zFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(planeFeedbackSwitch.getValue(), SO_SWITCH_NONE ); } else if (currentDragger == yTranslator.getValue() ) { setSwitchValue(xFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(yFeedbackSwitch.getValue(), 0 ); setSwitchValue(zFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(planeFeedbackSwitch.getValue(), SO_SWITCH_NONE ); } else if (currentDragger == zTranslator.getValue() ) { setSwitchValue(xFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(yFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(zFeedbackSwitch.getValue(), 0 ); setSwitchValue(planeFeedbackSwitch.getValue(), SO_SWITCH_NONE ); } else if (currentDragger == yzTranslator.getValue() ) { setSwitchValue(xFeedbackSwitch.getValue(), SO_SWITCH_NONE ); if ( translateDir == -1 || translateDir == 1 ) setSwitchValue(yFeedbackSwitch.getValue(), 0 ); else setSwitchValue(yFeedbackSwitch.getValue(), SO_SWITCH_NONE ); if ( translateDir == -1 || translateDir == 2 ) setSwitchValue(zFeedbackSwitch.getValue(), 0 ); else setSwitchValue(zFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(planeFeedbackSwitch.getValue(), 0 ); } else if (currentDragger == xzTranslator.getValue() ) { if ( translateDir == -1 || translateDir == 0 ) setSwitchValue(xFeedbackSwitch.getValue(), 0 ); else setSwitchValue(xFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(yFeedbackSwitch.getValue(), SO_SWITCH_NONE ); if ( translateDir == -1 || translateDir == 2 ) setSwitchValue(zFeedbackSwitch.getValue(), 0 ); else setSwitchValue(zFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(planeFeedbackSwitch.getValue(), 1 ); } else if (currentDragger == xyTranslator.getValue() ) { if ( translateDir == -1 || translateDir == 0 ) setSwitchValue(xFeedbackSwitch.getValue(), 0 ); else setSwitchValue(xFeedbackSwitch.getValue(), SO_SWITCH_NONE ); if ( translateDir == -1 || translateDir == 1 ) setSwitchValue(yFeedbackSwitch.getValue(), 0 ); else setSwitchValue(yFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(zFeedbackSwitch.getValue(), SO_SWITCH_NONE ); setSwitchValue(planeFeedbackSwitch.getValue(), 2 ); } checkBoxLimits(); //************************************** // Set the transforms for the feedback axes and/or planes. //************************************** // First, find the center and scale for each part, in LOCAL space. // The limit box is defined in a space aligned and scaled as // LOCAL space, but with it's center remaining fixed in WORLD // space. // We need to transform the center of the limitBox // from WORLD space to LOCAL space to // find the location of the center of the limit box feedback. SbMatrix worldToLocal = getWorldToLocalMatrix(); SbVec3f limitBoxCenterInLocal = limitBox.getCenter(); worldToLocal.multVecMatrix( limitBoxCenterInLocal, limitBoxCenterInLocal ); SbVec3f xAxisSpot = limitBoxCenterInLocal; SbVec3f yAxisSpot = limitBoxCenterInLocal; SbVec3f zAxisSpot = limitBoxCenterInLocal; SbVec3f planeSpot = limitBoxCenterInLocal; //With center matching mouse location... // The point under the mouse is stored as 'startLocalHitPt', which is // expressed in LOCAL space. xAxisSpot[1] = startLocalHitPt[1]; xAxisSpot[2] = startLocalHitPt[2]; yAxisSpot[0] = startLocalHitPt[0]; yAxisSpot[2] = startLocalHitPt[2]; zAxisSpot[0] = startLocalHitPt[0]; zAxisSpot[1] = startLocalHitPt[1]; if ( currentDragger == yzTranslator.getValue()) { planeSpot[0] = startLocalHitPt[0]; } else if ( currentDragger == xzTranslator.getValue()) { planeSpot[1] = startLocalHitPt[1]; } else if ( currentDragger == xyTranslator.getValue()) { planeSpot[2] = startLocalHitPt[2]; } SoTranslation *transNode; // Set position of each axis feedback if ( xFeedbackTranslation.getValue() == NULL ) setAnyPart( "xFeedbackTranslation", new SoTranslation ); transNode = (SoTranslation *) xFeedbackTranslation.getValue(); transNode->translation = xAxisSpot; if ( yFeedbackTranslation.getValue() == NULL ) setAnyPart( "yFeedbackTranslation", new SoTranslation ); transNode = (SoTranslation *) yFeedbackTranslation.getValue(); transNode->translation = yAxisSpot; if ( zFeedbackTranslation.getValue() == NULL ) setAnyPart( "zFeedbackTranslation", new SoTranslation ); transNode = (SoTranslation *) zFeedbackTranslation.getValue(); transNode->translation = zAxisSpot; // Set position of plane feedback if ( planeFeedbackTranslation.getValue() == NULL ) setAnyPart( "planeFeedbackTranslation", new SoTranslation ); transNode = (SoTranslation *) planeFeedbackTranslation.getValue(); transNode->translation = planeSpot; }