⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typeomatic.cpp.in

📁 学习 open inventor 的例子
💻 IN
📖 第 1 页 / 共 4 页
字号:
{  SO_NODE_INIT_CLASS(Switchboard, SoGroup, SoGroup);}SO_NODE_SOURCE(Switchboard);Switchboard::Switchboard(void){  SO_NODE_CONSTRUCTOR(Switchboard);  SO_NODE_ADD_FIELD(enable, (FALSE));}Switchboard::Switchboard(int numchildren)  : inherited(numchildren){  SO_NODE_CONSTRUCTOR(Switchboard);  SO_NODE_ADD_FIELD(enable, (FALSE));}Switchboard::~Switchboard(void) // virtual, protected{}voidSwitchboard::doAction(SoAction * action){  // FIXME: take PathCode and stuff into consideration...  if (action->isOfType(SoGetBoundingBoxAction::getClassTypeId())) {    // calculate center of bbox if bboxaction. This makes the    // switchboard node behave exactly like a group node    SoGetBoundingBoxAction * bbaction = (SoGetBoundingBoxAction*) action;    // Initialize accumulation variables.    SbVec3f acccenter(0.0f, 0.0f, 0.0f);    int numcenters = 0;    for (int idx = 0; idx < this->enable.getNum(); idx++) {      const int numchildren = this->children->getLength();      if ( numchildren > 0 )        action->traverse((*this->children)[idx % numchildren]);      // If center point is set, accumulate.      if (bbaction->isCenterSet()) {        acccenter += bbaction->getCenter();        numcenters++;        bbaction->resetCenter();      }    }    if (numcenters != 0) {      bbaction->setCenter(acccenter / float(numcenters), FALSE);    }  } else { // not a GetBoundingBoxAction    for ( int idx = 0; idx < this->enable.getNum(); idx++ ) {      if ( this->enable[idx] ) {        const int numchildren = this->children->getLength();        if ( numchildren > 0 )          action->traverse((*this->children)[idx % numchildren]);      }    }  }}voidSwitchboard::GLRender(SoGLRenderAction * action){  Switchboard::doAction((SoAction *) action);}voidSwitchboard::getBoundingBox(SoGetBoundingBoxAction * action){  Switchboard::doAction((SoAction *) action);}voidSwitchboard::getMatrix(SoGetMatrixAction * action){  switch (action->getCurPathCode()) {  case SoAction::OFF_PATH:  case SoAction::IN_PATH:    Switchboard::doAction((SoAction *) action);    break;  default:    break;  }}voidSwitchboard::callback(SoCallbackAction *action){  Switchboard::doAction(action);}// Documented in superclass.voidSwitchboard::pick(SoPickAction *action){  Switchboard::doAction((SoAction*)action);}// Documented in superclass.voidSwitchboard::handleEvent(SoHandleEventAction *action){  Switchboard::doAction(action);}voidSwitchboard::search(SoSearchAction * action){  SoNode::search(action);  if (action->isFound()) return;  Switchboard::doAction(action);}// *************************************************************************#include <Inventor/nodes/SoSubNode.h>#include <Inventor/actions/SoHandleEventAction.h>#include <Inventor/events/SoKeyboardEvent.h>#include <Inventor/errors/SoDebugError.h>SO_NODE_SOURCE(SwitchboardOperator);voidSwitchboardOperator::initClass(void){  SO_NODE_INIT_CLASS(SwitchboardOperator, Switchboard, Switchboard);}SwitchboardOperator::SwitchboardOperator(void){  this->constructor();}SwitchboardOperator::SwitchboardOperator(int numchildren): inherited(numchildren){  this->constructor();}voidSwitchboardOperator::constructor(void) // private{  SO_NODE_CONSTRUCTOR(SwitchboardOperator);  SO_NODE_ADD_FIELD(key, (UNDEFINED));  SO_NODE_ADD_FIELD(behavior, (TOGGLE));  SO_NODE_ADD_FIELD(msecs, (0));  // FIXME: complete this list  SO_NODE_DEFINE_ENUM_VALUE(Key, LEFT_SHIFT);  SO_NODE_DEFINE_ENUM_VALUE(Key, RIGHT_SHIFT);  SO_NODE_DEFINE_ENUM_VALUE(Key, LEFT_CONTROL);  SO_NODE_DEFINE_ENUM_VALUE(Key, RIGHT_CONTROL);  SO_NODE_DEFINE_ENUM_VALUE(Key, LEFT_ALT);  SO_NODE_DEFINE_ENUM_VALUE(Key, RIGHT_ALT);  SO_NODE_DEFINE_ENUM_VALUE(Key, CAPS_LOCK);  SO_NODE_DEFINE_ENUM_VALUE(Key, ANY);  SO_NODE_DEFINE_ENUM_VALUE(Key, UNDEFINED);  SO_NODE_DEFINE_ENUM_VALUE(Key, A);  SO_NODE_DEFINE_ENUM_VALUE(Key, B);  SO_NODE_DEFINE_ENUM_VALUE(Key, C);  SO_NODE_DEFINE_ENUM_VALUE(Key, D);  SO_NODE_DEFINE_ENUM_VALUE(Key, E);  SO_NODE_DEFINE_ENUM_VALUE(Key, F);  SO_NODE_DEFINE_ENUM_VALUE(Key, G);  SO_NODE_DEFINE_ENUM_VALUE(Key, H);  SO_NODE_DEFINE_ENUM_VALUE(Key, I);  SO_NODE_DEFINE_ENUM_VALUE(Key, J);  SO_NODE_DEFINE_ENUM_VALUE(Key, K);  SO_NODE_DEFINE_ENUM_VALUE(Key, L);  SO_NODE_DEFINE_ENUM_VALUE(Key, M);  SO_NODE_DEFINE_ENUM_VALUE(Key, N);  SO_NODE_DEFINE_ENUM_VALUE(Key, O);  SO_NODE_DEFINE_ENUM_VALUE(Key, P);  SO_NODE_DEFINE_ENUM_VALUE(Key, Q);  SO_NODE_DEFINE_ENUM_VALUE(Key, R);  SO_NODE_DEFINE_ENUM_VALUE(Key, S);  SO_NODE_DEFINE_ENUM_VALUE(Key, T);  SO_NODE_DEFINE_ENUM_VALUE(Key, U);  SO_NODE_DEFINE_ENUM_VALUE(Key, V);  SO_NODE_DEFINE_ENUM_VALUE(Key, W);  SO_NODE_DEFINE_ENUM_VALUE(Key, X);  SO_NODE_DEFINE_ENUM_VALUE(Key, Y);  SO_NODE_DEFINE_ENUM_VALUE(Key, Z);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_0);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_1);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_2);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_3);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_4);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_5);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_6);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_7);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_8);  SO_NODE_DEFINE_ENUM_VALUE(Key, NUMBER_9);  SO_NODE_DEFINE_ENUM_VALUE(Key, MINUS);  SO_NODE_DEFINE_ENUM_VALUE(Key, EQUAL);  SO_NODE_DEFINE_ENUM_VALUE(Key, SPACE);  SO_NODE_DEFINE_ENUM_VALUE(Key, BACKSPACE);  SO_NODE_DEFINE_ENUM_VALUE(Key, TAB);  SO_NODE_DEFINE_ENUM_VALUE(Key, RETURN);  SO_NODE_DEFINE_ENUM_VALUE(Key, BRACKETLEFT);  SO_NODE_DEFINE_ENUM_VALUE(Key, BRACKETRIGHT);  SO_NODE_DEFINE_ENUM_VALUE(Key, SEMICOLON);  SO_NODE_DEFINE_ENUM_VALUE(Key, APOSTROPHE);  SO_NODE_DEFINE_ENUM_VALUE(Key, COMMA);  SO_NODE_DEFINE_ENUM_VALUE(Key, PERIOD);  SO_NODE_DEFINE_ENUM_VALUE(Key, SLASH);  SO_NODE_DEFINE_ENUM_VALUE(Key, BACKSLASH);  SO_NODE_DEFINE_ENUM_VALUE(Key, GRAVE);  SO_NODE_DEFINE_ENUM_VALUE(Behavior, NONE);  SO_NODE_DEFINE_ENUM_VALUE(Behavior, TOGGLE);  SO_NODE_DEFINE_ENUM_VALUE(Behavior, HOLD);  SO_NODE_DEFINE_ENUM_VALUE(Behavior, INVERSE_HOLD);  SO_NODE_DEFINE_ENUM_VALUE(Behavior, TIME_HOLD);  SO_NODE_SET_SF_ENUM_TYPE(key, Key);  SO_NODE_SET_SF_ENUM_TYPE(behavior, Behavior);}SwitchboardOperator::~SwitchboardOperator(void) // virtual, protected{}voidSwitchboardOperator::handleEvent(SoHandleEventAction * action){  const SoEvent * ev = action->getEvent();  if ( ev->isOfType(SoKeyboardEvent::getClassTypeId()) ) {    const SoKeyboardEvent * event = (const SoKeyboardEvent *) ev;    SoKeyboardEvent::Key key = event->getKey();    for ( int idx = 0; idx < this->key.getNum(); idx++ ) {      if ( this->key[idx] == key ) {        switch ( idx < this->behavior.getNum() ? this->behavior[idx] : TOGGLE ) {        case TOGGLE:          if ( event->getState() == SoKeyboardEvent::DOWN ) {            if ( idx >= this->enable.getNum() ) this->enable.setNum(idx+1);            this->enable.set1Value(idx, this->enable[idx] ? FALSE : TRUE);          }          break;        case HOLD:          if ( idx >= this->enable.getNum() ) this->enable.setNum(idx+1);          this->enable.set1Value(idx, event->getState() == SoKeyboardEvent::DOWN ? TRUE : FALSE);          break;        case INVERSE_HOLD:          if ( idx >= this->enable.getNum() ) this->enable.setNum(idx+1);          this->enable.set1Value(idx, event->getState() == SoKeyboardEvent::DOWN ? FALSE : TRUE);          break;        case TIME_HOLD:          SoDebugError::postInfo("SwitchboardOperator::handleEvent", "not implemented yet");          break;        default:          break;        }      }    }  }}// *************************************************************************SoNode *find(SoNode * root, const char * name){  SoSearchAction searcher;  searcher.setName(SbName(name));  searcher.setInterest(SoSearchAction::FIRST);  searcher.apply(root);  if ( !searcher.getPath() ) return NULL;  return searcher.getPath()->getTail();} // find()static SoSwitch * message = NULL;voidcallback(void * closure, SoAction * action){  if ( action->isOfType(SoHandleEventAction::getClassTypeId()) ) {    SoHandleEventAction * heaction = (SoHandleEventAction *) action;    const SoEvent * ev = heaction->getEvent();    if ( ev->isOfType(SoMouseButtonEvent::getClassTypeId()) ) {      SoMouseButtonEvent * event = (SoMouseButtonEvent *) ev;      if ( event->getState() == SoButtonEvent::DOWN ) {        message->whichChild.setValue(0);      } else {        message->whichChild.setValue(-1);      }    }  }#if 0  SoPerspectiveCamera * camera = (SoPerspectiveCamera *) find((SoNode *) closure, "camera");  assert(camera != NULL && camera->isOfType(SoPerspectiveCamera::getClassTypeId()));  SoDebugError::postInfo("callback", "dumping camera parameters");  SbVec3f position = camera->position.getValue();  SbRotation orientation = camera->orientation.getValue();  float x, y, z, w;  orientation.getValue(x, y, z, w);  fprintf(stdout, "position %g %g %g\n", position[0], position[1], position[2]);  fprintf(stdout, "orientation %g %g %g %g\n", x, y, z, w);#endif} // callback()intmain(  int argc,  char ** argv ){  @WIDGET@ window = So@Gui@::init( argv[0] );  Switchboard::initClass();  SwitchboardOperator::initClass();  So@Gui@ExaminerViewer * viewer = new So@Gui@ExaminerViewer( window );  viewer->setDecoration(FALSE);  viewer->setViewing(FALSE);  viewer->show();  So@Gui@::show(window);  unsigned int totlen;  char * buf = strconcat(keyboard_iv, totlen);  SoInput in;  in.setBuffer(buf, totlen);  SoNode * root = NULL;  if ( !SoDB::read(&in, root) ) {    SoDebugError::postInfo("main", "error reading file");    exit(-1);  }  delete [] buf;  root->ref();  SoCallback * cb = (SoCallback *) find(root, "callback");  assert(cb != NULL);  cb->setCallback(callback, root);  message = (SoSwitch *) find(root, "message");  assert(message != NULL);  viewer->setSceneGraph(root);  root->unref();  So@Gui@::show(window);  viewer->setFullScreen(TRUE);  viewer->setTitle("Type-O-Matic");  So@Gui@::mainLoop();  delete viewer;  return 0;} // main()// *************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -