예제 #1
0
파일: main.cpp 프로젝트: pmitros/ball
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();
}
예제 #2
0
/*! \COININTERNAL */
void
SoHandleBoxDragger::metaKeyChangeCB(void *, SoDragger * d)
{
  SoHandleBoxDragger * thisp = static_cast<SoHandleBoxDragger *>(d);
  if (!thisp->isActive.getValue()) return;

  const SoEvent *event = thisp->getEvent();
  if (SO_KEY_RELEASE_EVENT(event, LEFT_SHIFT) ||
      SO_KEY_RELEASE_EVENT(event, RIGHT_SHIFT)) {
    if (thisp->constraintState != CONSTRAINT_OFF) thisp->drag();
  }
  else if (thisp->ctrlDown != event->wasCtrlDown()) {
    thisp->ctrlDown = !thisp->ctrlDown;
    thisp->updateSwitches();
  }
}
예제 #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();
    }
}