Ejemplo n.º 1
0
void keyboardCB(void*, SoEventCallback*cb)
{
  //printf("Keyboard\n");
  if(SO_KEY_PRESS_EVENT(cb->getEvent(), Q))
    exit(0);
  if(SO_KEY_PRESS_EVENT(cb->getEvent(), LEFT_ARROW))
    player.left=1;
  if(SO_KEY_PRESS_EVENT(cb->getEvent(), RIGHT_ARROW))
    player.right=1;
  if(SO_KEY_PRESS_EVENT(cb->getEvent(), UP_ARROW))
    player.up=1;
  if(SO_KEY_PRESS_EVENT(cb->getEvent(), DOWN_ARROW))
    player.down=1;
  if(SO_KEY_RELEASE_EVENT(cb->getEvent(), LEFT_ARROW))
    player.left=0;
  if(SO_KEY_RELEASE_EVENT(cb->getEvent(), RIGHT_ARROW))
    player.right=0;
  if(SO_KEY_RELEASE_EVENT(cb->getEvent(), UP_ARROW))
    player.up=0;
  if(SO_KEY_RELEASE_EVENT(cb->getEvent(), DOWN_ARROW))
    player.down=0;

  if(SO_KEY_PRESS_EVENT(cb->getEvent(), SPACE))
    if((player.z==0)&&(player.dz<.5))
      player.dz+=0.8;

  cb->setHandled();
}
void UMDSoMeasureTool::cursorPressCB(void* /*userData*/, SoEventCallback* eventCB) {
  // check for the arrow keys being pressed
  const SoEvent* event = eventCB->getEvent();
  Taste zusatzTaste = none; //{shift, control, alt};
  if (_currentTool != NULL){
    if (!eventCB->isHandled()){
      if (event->wasShiftDown())
        zusatzTaste = shift;

      if (event->wasCtrlDown())
        zusatzTaste = control;

      /*
      if (SO_KEY_PRESS_EVENT(event, SPACE)) {
        if (_currentTool != NULL) {
          if (_currentTool->interactionMode.getValue() == directSelect)
            _currentTool->interactionMode.setValue(dragMode);
          else
            _currentTool->interactionMode.setValue(directSelect);
          eventCB->setHandled();
        }
      }
      else
      */
        if (SO_KEY_PRESS_EVENT(event, UP_ARROW)) {
          if (_currentTool->cursorUpPressed(zusatzTaste))
            eventCB->setHandled();
        }
        else
          if (SO_KEY_PRESS_EVENT(event, DOWN_ARROW)) {
            if (_currentTool->cursorDownPressed(zusatzTaste))
              eventCB->setHandled();
          }
          else
            if (SO_KEY_PRESS_EVENT(event, LEFT_ARROW)) {
              if (_currentTool->cursorLeftPressed(zusatzTaste))
                eventCB->setHandled();
            }
            else
              if (SO_KEY_PRESS_EVENT(event, RIGHT_ARROW)) {
                if (_currentTool->cursorRightPressed(zusatzTaste))
                  eventCB->setHandled();
              }
              else
                if (SO_KEY_PRESS_EVENT(event, PAGE_UP)) {
                  if (_currentTool->pageUpPressed(zusatzTaste))
                    eventCB->setHandled();
                }
                else
                  if (SO_KEY_PRESS_EVENT(event, PAGE_DOWN)) {
                    if (_currentTool->pageDownPressed(zusatzTaste))
                      eventCB->setHandled();
                  }
    }
  }
}
Ejemplo n.º 3
0
void
SoTranslate2Dragger::metaKeyChangeCB( void *, SoDragger *inDragger)
{
    SoTranslate2Dragger *d = (SoTranslate2Dragger *) inDragger;
    SoHandleEventAction *ha = d->getHandleEventAction();

    // [1] Only do this if we are grabbing
    if (ha->getGrabber() != d )
	return;

    // [2] We only want key press or release events.
    const SoEvent *event = d->getEvent();
    if ( !SO_KEY_PRESS_EVENT(event, ANY) && !SO_KEY_RELEASE_EVENT(event, ANY))
	return;

    // [3] Is the key the shift key?
    const SoKeyboardEvent *ke = (const SoKeyboardEvent *) event;
    SoKeyboardEvent::Key key = ke->getKey();

    if ( key == SoKeyboardEvent::LEFT_SHIFT ||
	 key == SoKeyboardEvent::RIGHT_SHIFT ) {

	// We want to end the old gesture and start a new one.

	// [A] Release the grabber. This ends the gesture and calls all 
	//     finishCallbacks (on parent dragger, too, if we're registered)
	    ha->releaseGrabber();

	// [B] Set the starting point to be our saved worldRestartPoint
	    d->setStartingPoint( d->worldRestartPt );

	// [C] Become the grabber again. This begins a new gesture and calls all
	//     startCallbacks (parent dragger, too).  Info like viewVolume, 
	//     viewportRegion, handleEventAction, and 
	//     tempPathToThis is still valid.
	    ha->setGrabber(d);

	// [D] set handled
	    ha->setHandled();
    }
}
void
myKeyPressCB(void *myUserData, SoEventCallback *eventCB)
{
   const SoEvent *event = eventCB->getEvent();
   PoseEstimationQuarterWidget::Angles * angles = 
      (PoseEstimationQuarterWidget::Angles *) myUserData;

   const float angleIncrementRad = 1. * M_PI / 180.;

   //SbVec3f axis;
   //float angle;

   // Check for the Up and Down arrow keys being pressed.
   if (SO_KEY_PRESS_EVENT(event, LEFT_ARROW)) 
   {
      angles->m_currentYawAngle += angleIncrementRad;

      // implement a rotation around the y axis with 1 degree to the left
      SoRotation * transformNode = (SoRotation*) SoNode::getByName("MyFineAdjustmentRotationAzimuth");
      if (transformNode)
      {
         //transformNode->rotation.getValue(axis,angle);
         //std::cout << "current azimuth angle: " << angle << std::endl;
         //std::cout << "current azimuth axis: " << std::endl;
         //axis.print(stdout);
         //std::cout << std::endl;
         //transformNode->rotation.setValue(axis,angle + angleIncrementRad);

         /*angle += angleIncrement
         SoSFRotation oldSFRotation = transformNode->rotation;
         SbRotation oldRotation = oldSFRotation.getValue();

         SbRotation incrementalRotation(SbVec3f(0.0f,1.0f,0.0f),-angleIncrementRad);

         SbMatrix test;
         (oldRotation * incrementalRotation).getValue(test);

         std::cout << "current matrix: " << std::endl;
         test.print(stdout);

         SoSFRotation rot;
         rot.setValue(incrementalRotation * oldRotation);
         transformNode->rotation = rot;*/
      }
   } 
   else if (SO_KEY_PRESS_EVENT(event, RIGHT_ARROW)) 
   {
      angles->m_currentYawAngle -= angleIncrementRad;
      //std::cout << "current roll angle: " << angles->m_currentRollAngle << std::endl;

      // implement a rotation around the y axis with 1 degree to the right
      SoRotation * transformNode = (SoRotation*) SoNode::getByName("MyFineAdjustmentRotationAzimuth");
      if (transformNode)
      {
         //transformNode->rotation.getValue(axis,angle);
         //std::cout << "current azimuth angle: " << angle << std::endl;
         //std::cout << "current azimuth axis: " << std::endl;
         //axis.print(stdout);
         //std::cout << std::endl;
         //transformNode->rotation.setValue(axis,angle - angleIncrementRad);

         /*SoSFRotation oldSFRotation = transformNode->rotation;
         SbRotation oldRotation = oldSFRotation.getValue();

         SbRotation incrementalRotation(SbVec3f(0.0f,1.0f,0.0f),angleIncrementRad);

         SbMatrix test;
         (oldRotation * incrementalRotation).getValue(test);

         std::cout << "current matrix: " << std::endl;
         test.print(stdout);

         SoSFRotation rot;
         rot.setValue(incrementalRotation * oldRotation);
         transformNode->rotation = rot;*/
      }
   } 
   else if (SO_KEY_PRESS_EVENT(event, UP_ARROW)) 
   {
      angles->m_currentPitchAngle += angleIncrementRad;
      //std::cout << "current pitch angle: " << angles->m_currentPitchAngle << std::endl;

      // implement a rotation around the y axis with 1 degree to the left
      SoRotation * transformNode = (SoRotation*) SoNode::getByName("MyFineAdjustmentRotationElevation");
      if (transformNode)
      {
         /*transformNode->rotation.getValue(axis,angle);
         std::cout << "current elevation angle: " << angle << std::endl;
         std::cout << "current elevation axis: " << std::endl;
         axis.print(stdout);
         std::cout << std::endl;
         transformNode->rotation.setValue(axis,angle + angleIncrementRad);*/

         /*SoSFRotation oldSFRotation = transformNode->rotation;
         SbRotation oldRotation = oldSFRotation.getValue();

         SbRotation incrementalRotation(SbVec3f(1.0f,0.0f,0.0f),-angleIncrementRad);

         SbMatrix test;
         (oldRotation * incrementalRotation).getValue(test);

         std::cout << "current matrix: " << std::endl;
         test.print(stdout);

         SoSFRotation rot;
         rot.setValue(incrementalRotation * oldRotation);
         transformNode->rotation = rot;*/
      }
   } 
   else if (SO_KEY_PRESS_EVENT(event, DOWN_ARROW)) 
   {
      angles->m_currentPitchAngle -= angleIncrementRad;
      //std::cout << "current pitch angle: " << angles->m_currentPitchAngle << std::endl;

      // implement a rotation around the y axis with 1 degree to the right
      SoRotation * transformNode = (SoRotation*) SoNode::getByName("MyFineAdjustmentRotationElevation");
      if (transformNode)
      {
         /*transformNode->rotation.getValue(axis,angle);
         std::cout << "current elevation angle: " << angle << std::endl;
         std::cout << "current elevation axis: " << std::endl;
         axis.print(stdout);
         std::cout << std::endl;
         transformNode->rotation.setValue(axis,angle - angleIncrementRad);*/

         /*SoSFRotation oldSFRotation = transformNode->rotation;
         SbRotation oldRotation = oldSFRotation.getValue();

         SbRotation incrementalRotation(SbVec3f(1.0f,0.0f,0.0f),angleIncrementRad);

         SbMatrix test;
         (oldRotation * incrementalRotation).getValue(test);

         std::cout << "current matrix: " << std::endl;
         test.print(stdout);

         SoSFRotation rot;
         rot.setValue(incrementalRotation * oldRotation);
         transformNode->rotation = rot;*/
      }
   }
   else if (SO_KEY_PRESS_EVENT(event, PAGE_UP)) 
   {
      angles->m_currentRollAngle += angleIncrementRad;
      //std::cout << "current yaw angle: " << angles->m_currentYawAngle << std::endl;

      // implement a rotation around the y axis with 1 degree to the right
      SoRotation * transformNode = (SoRotation*) SoNode::getByName("MyFineAdjustmentRotationTwist");
      if (transformNode)
      {
         /*transformNode->rotation.getValue(axis,angle);
         std::cout << "current twist angle: " << angle << std::endl;
         std::cout << "current twist axis: " << std::endl;
         axis.print(stdout);
         std::cout << std::endl;
         transformNode->rotation.setValue(axis,angle + angleIncrementRad);*/
      }
   }
   else if (SO_KEY_PRESS_EVENT(event, PAGE_DOWN)) 
   {
      angles->m_currentRollAngle -= angleIncrementRad;
      //std::cout << "current yaw angle: " << angles->m_currentYawAngle << std::endl;

      // implement a rotation around the y axis with 1 degree to the right
      SoRotation * transformNode = (SoRotation*) SoNode::getByName("MyFineAdjustmentRotationTwist");
      if (transformNode)
      {
         /*transformNode->rotation.getValue(axis,angle);
         std::cout << "current twist angle: " << angle << std::endl;
         std::cout << "current twist axis: " << std::endl;
         axis.print(stdout);
         std::cout << std::endl;
         transformNode->rotation.setValue(axis,angle - angleIncrementRad);*/
      }
   }
   else if (SO_KEY_PRESS_EVENT(event, H)) 
   {
      angles->m_currentYawAngle = 0.0;
      angles->m_currentPitchAngle = 0.0;
      angles->m_currentRollAngle = 0.0;
   }

   eventCB->setHandled();

   //if (global_render_manager)
   //   global_render_manager->render();
   if (global_quarter_widget)
      global_quarter_widget->updateGL();
}
Ejemplo n.º 5
0
void
SoDragPointDragger::metaKeyChangeCB( void *, SoDragger *inDragger )
//
////////////////////////////////////////////////////////////////////////
{
    SoDragPointDragger *dp = (SoDragPointDragger *) inDragger;

    SoHandleEventAction *ha = dp->getHandleEventAction();

    // We care if the shift key is down for drawing feedback.
	const SoEvent *event = dp->getEvent();
        dp->shftDown = event->wasShiftDown();

    // Don't check for grabber yet.
    // CONTROL key press overrides if the grabber is a childDragger.

    // [1] We only respond to CONTROL key press events.
	if ( !SO_KEY_PRESS_EVENT(event,  LEFT_CONTROL) &&
	     !SO_KEY_PRESS_EVENT(event, RIGHT_CONTROL))
	     return;

    //[2] Should we return?
    //    Stay here if there's no grabber and the mouse is over us,
    //         or over a surrogate part.
    //    Stay here if we are the grabber.
    //    Stay here if our currentDragger is grabbing events.
    //    Return if anyone else is grabbing.
	SbBool takeIt = FALSE;
	if ( ha->getGrabber() == NULL  ) {

	    // grabber is NULL...
	    const SoPickedPoint *p = ha->getPickedPoint();

	    if ( p && p->getPath()) {

		// Are we on the pickPath?
		// Or is the path a surrogate path for us or any draggers 
		// contained within us?
	        if (  p->getPath()->containsNode(dp) ||
		     dp->isPathSurrogateInMySubgraph(p->getPath()) )
		        takeIt = TRUE;
	    }
	}
	else if ( ha->getGrabber() == dp )
	    takeIt = TRUE;
	else if ( ha->getGrabber() == dp->currentDragger )
	    takeIt = TRUE;
	else 
	    takeIt = FALSE;

	if ( !takeIt )
	    return;

    //[3] Now, switch the set of visible draggers...
	dp->showNextDraggerSet();

    //[4] If a child is grabbing, release events and hand it all over to 
    //    the next one...
	SoDragger *oldDragger = dp->currentDragger;
	if (oldDragger) {

	    // Ref the oldDragger.
		oldDragger->ref();

	    // Release the grabber. This will call grabEventsCleanUp() if 
	    // the grabber is a dragger.
		ha->releaseGrabber();

	    // If there was an oldDragger, 
	    // [a] select a new dragger to grab events.
	    // [b] Set up a plane or line projector oriented like newDragger.
	    // [c] Find out where current mouse position intersects that new 
	    //     plane or line. The new gesture will continue from there.
		SoDragger *newDragger;
		SbVec3f    projPt;
		SbLineProjector  lp;
		SbPlaneProjector pp;
		lp.setViewVolume( dp->getViewVolume() );
		pp.setViewVolume( dp->getViewVolume() );
		lp.setWorkingSpace( dp->getLocalToWorldMatrix() );
		pp.setWorkingSpace( dp->getLocalToWorldMatrix() );

		if (      oldDragger == dp->xTranslator.getValue() ) {
		    newDragger = (SoDragger *) dp->yTranslator.getValue();
		    lp.setLine( SbLine( SbVec3f(0,0,0), SbVec3f(0,1,0)));
		    projPt = lp.project(dp->getNormalizedLocaterPosition());
		}
		else if ( oldDragger == dp->yTranslator.getValue() ) {
		    newDragger = (SoDragger *) dp->zTranslator.getValue();
		    lp.setLine( SbLine( SbVec3f(0,0,0), SbVec3f(0,0,1)));
		    projPt = lp.project(dp->getNormalizedLocaterPosition());
		}
		else if ( oldDragger == dp->zTranslator.getValue() ) {
		    newDragger = (SoDragger *) dp->xTranslator.getValue();
		    lp.setLine( SbLine( SbVec3f(0,0,0), SbVec3f(1,0,0)));
		    projPt = lp.project(dp->getNormalizedLocaterPosition());
		}
		else if ( oldDragger == dp->yzTranslator.getValue() ) {
		    newDragger = (SoDragger *) dp->xzTranslator.getValue();
		    pp.setPlane( SbPlane( SbVec3f(0,1,0), SbVec3f(0,0,0)));
		    projPt = pp.project(dp->getNormalizedLocaterPosition());
		}
		else if ( oldDragger == dp->xzTranslator.getValue() ) {
		    newDragger = (SoDragger *) dp->xyTranslator.getValue();
		    pp.setPlane( SbPlane( SbVec3f(0,0,1), SbVec3f(0,0,0)));
		    projPt = pp.project(dp->getNormalizedLocaterPosition());
		}
		else if ( oldDragger == dp->xyTranslator.getValue() ) {
		    newDragger = (SoDragger *) dp->yzTranslator.getValue();
		    pp.setPlane( SbPlane( SbVec3f(1,0,0), SbVec3f(0,0,0)));
		    projPt = pp.project(dp->getNormalizedLocaterPosition());
		}

	    // unref oldDragger. We don't need it any more.
		oldDragger->unref();

	    // Give newDragger our handleEvent action. 
		newDragger->setHandleEventAction(ha);

	    // Cast the projPt into world space for the new starting point.
		dp->getLocalToWorldMatrix().multVecMatrix(projPt,projPt);
		newDragger->setStartingPoint( projPt );

	    // Give the newDragger a path to itself
		SoPath *pathToDragger;

		    // We must ref() & unref() dpThisPath to dispose of it.
		    SoPath *dpThisPath = dp->createPathToThis();
		    if (dpThisPath) dpThisPath->ref();
		    pathToDragger = dp->createPathToPart(
			dp->getPartString(newDragger), TRUE, dpThisPath );
		    if (dpThisPath) dpThisPath->unref();

		if (pathToDragger)
		    pathToDragger->ref();
		newDragger->setTempPathToThis( pathToDragger );
		if (pathToDragger)
		    pathToDragger->unref();

	    // Give the newDragger our viewing information.
		newDragger->setViewVolume(dp->getViewVolume());
		newDragger->setViewportRegion(dp->getViewportRegion());

	    // Set the grabber. This will call starting callbacks on the new
	    // grabber, as well as it's registered parent, moi!
		ha->setGrabber( newDragger );
	}

    //[5] set handled
	ha->setHandled();
}