📄 styx.cpp.in
字号:
if ( points[1][0] < 0.0f || points[1][0] > 300.0f ) p2dir[0] = 0.0f - p2dir[0]; if ( points[1][1] < 0.0f || points[1][1] > 200.0f ) p2dir[1] = 0.0f - p2dir[1]; if ( points[1][2] < 0.0f || points[1][2] > 200.0f ) p2dir[2] = 0.0f - p2dir[2]; for ( i = 0; i < (LINES * 2); i++ ) { if ( points[i][0] < 0.0f ) points[i][0] = 0.0f - points[i][0]; else if ( points[i][0] > 300.0f ) points[i][0] = 600.0f - points[i][0]; if ( points[i][1] < 0.0f ) points[i][1] = 0.0f - points[i][1]; else if ( points[i][1] > 200.0f ) points[i][1] = 400.0f - points[i][1]; if ( points[i][2] < 0.0f ) points[i][2] = 0.0f - points[i][2]; else if ( points[i][2] > 200.0f ) points[i][2] = 400.0f - points[i][2]; } p1dir[0] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir[1] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir[2] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir.normalize(); p2dir[0] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir[1] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir[2] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir.normalize(); coords->point.finishEditing();}voidtickLines2(SoCoordinate3 * coords){ static SbBool initialized = FALSE; static SbVec3f p1dir; static SbVec3f p2dir; int i; if ( ! initialized ) { initialized = TRUE; p1dir.setValue(0, 1, 0); p2dir.setValue(0, 1, 0); } SbVec3f * points = coords->point.startEditing(); for ( i = 0; i < (LINES * 2); i++ ) { if ( (i / 2) == 0 ) { if ( (i&1) == 0 ) points[i] += p1dir * 5; else points[i] += p2dir * 5; } else { SbVec3f gravity = points[i-2] - points[i]; if ( (i&1) == 0 ) points[i] += (gravity * 0.2f); else points[i] += (gravity * 0.2f); } } if ( points[0][0] < 0.0f || points[0][0] > 300.0f ) p1dir[0] = 0.0f - p1dir[0]; if ( points[0][1] < 0.0f || points[0][1] > 200.0f ) p1dir[1] = 0.0f - p1dir[1]; if ( points[0][2] < 0.0f || points[0][2] > 200.0f ) p1dir[2] = 0.0f - p1dir[2]; if ( points[1][0] < 0.0f || points[1][0] > 300.0f ) p2dir[0] = 0.0f - p2dir[0]; if ( points[1][1] < 0.0f || points[1][1] > 200.0f ) p2dir[1] = 0.0f - p2dir[1]; if ( points[1][2] < 0.0f || points[1][2] > 200.0f ) p2dir[2] = 0.0f - p2dir[2]; for ( i = 0; i < (LINES * 2); i++ ) { if ( points[i][0] < 0.0f ) points[i][0] = 0.0f - points[i][0]; else if ( points[i][0] > 300.0f ) points[i][0] = 600.0f - points[i][0]; if ( points[i][1] < 0.0f ) points[i][1] = 0.0f - points[i][1]; else if ( points[i][1] > 200.0f ) points[i][1] = 400.0f - points[i][1]; if ( points[i][2] < 0.0f ) points[i][2] = 0.0f - points[i][2]; else if ( points[i][2] > 200.0f ) points[i][2] = 400.0f - points[i][2]; } p1dir[0] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir[1] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir[2] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir.normalize(); p2dir[0] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir[1] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir[2] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir.normalize(); coords->point.finishEditing();}voidtickLines3(SoCoordinate3 * coords){ static SbBool initialized = FALSE; static SbVec3f p1dir; static SbVec3f p2dir; int i; if ( ! initialized ) { initialized = TRUE; p1dir.setValue(0, 1, 0); p2dir.setValue(0, 1, 0); } SbVec3f * points = coords->point.startEditing(); for ( i = 0; i < (LINES * 2); i++ ) { if ( (i / 2) == 0 ) { if ( (i&1) == 0 ) points[i] += p1dir * 5; else points[i] += p2dir * 5; } else { SbVec3f gravity = points[i-2] - points[i]; if ( (i&1) == 0 ) points[i] += (gravity * 0.2f); else points[i] += (gravity * 0.2f); } } if ( points[0][0] < 0.0f || points[0][0] > 300.0f ) p1dir[0] = 0.0f - p1dir[0]; if ( points[0][1] < 0.0f || points[0][1] > 200.0f ) p1dir[1] = 0.0f - p1dir[1]; if ( points[0][2] < 0.0f || points[0][2] > 200.0f ) p1dir[2] = 0.0f - p1dir[2]; if ( points[1][0] < 0.0f || points[1][0] > 300.0f ) p2dir[0] = 0.0f - p2dir[0]; if ( points[1][1] < 0.0f || points[1][1] > 200.0f ) p2dir[1] = 0.0f - p2dir[1]; if ( points[1][2] < 0.0f || points[1][2] > 200.0f ) p2dir[2] = 0.0f - p2dir[2]; for ( i = 0; i < (LINES * 2); i++ ) { if ( points[i][0] < 0.0f ) points[i][0] = 0.0f - points[i][0]; else if ( points[i][0] > 300.0f ) points[i][0] = 600.0f - points[i][0]; if ( points[i][1] < 0.0f ) points[i][1] = 0.0f - points[i][1]; else if ( points[i][1] > 200.0f ) points[i][1] = 400.0f - points[i][1]; if ( points[i][2] < 0.0f ) points[i][2] = 0.0f - points[i][2]; else if ( points[i][2] > 200.0f ) points[i][2] = 400.0f - points[i][2]; } p1dir[0] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir[1] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir[2] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p1dir.normalize(); p2dir[0] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir[1] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir[2] += (fmod(float(rand())/200.0f,10.0f)-5.0f) / 50.0f; p2dir.normalize(); coords->point.finishEditing();}voidinitPoints(SoCoordinate3 * coords){ float floats[POINTS][3]; // = new float [ POINTS ][ 3 ]; for ( int i = 0; i < POINTS; i++ ) { if ( i < POINTS/4 ) { floats[i][0] = (float) (rand() % 301); floats[i][1] = 0.0f; floats[i][2] = (float) (rand() % 201); } else if ( i < POINTS/2 ) { floats[i][0] = (float) (rand() % 301); floats[i][1] = (float) (rand() % 201); floats[i][2] = 0.0f; } else if ( i < (3*POINTS)/4 ) { floats[i][0] = (float) (rand() % 301); floats[i][1] = 200.0f; floats[i][2] = (float) (rand() % 201); } else { floats[i][0] = (float) (rand() % 301); floats[i][1] = (float) (rand() % 201); floats[i][2] = 200.0f; } } coords->point.setValues(0, POINTS, floats);}voidtickPoints(SoCoordinate3 * coords){ static float * speed = NULL; int i; if ( ! speed ) { speed = new float [ POINTS ]; for ( i = 0; i < POINTS; i++ ) { speed[i] = 2.0f + fmod(float(rand())/20.0f, 3.0f); } } SbVec3f * points = coords->point.startEditing(); for ( i = 0; i < POINTS; i++ ) { points[i][0] -= speed[i]; if ( points[i][0] < 0 ) points[i][0] += 300.0f; } coords->point.finishEditing();}/* ********************************************************************** */voidevent_cb(void * closure, SoAction * action){ So@Gui@ExaminerViewer * viewer = (So@Gui@ExaminerViewer *) closure; if ( action->isOfType(SoGLRenderAction::getClassTypeId()) ) { SoGLRenderAction * raaction = (SoGLRenderAction *) action; SoNode * scene = action->getNodeAppliedTo(); if ( scene ) { tickLines1((SoCoordinate3 *) getNodeByName(scene, "redlines")); tickLines2((SoCoordinate3 *) getNodeByName(scene, "greenlines")); tickLines3((SoCoordinate3 *) getNodeByName(scene, "bluelines")); tickPoints((SoCoordinate3 *) getNodeByName(scene, "points")); } }}/* ********************************************************************** */intmain( int argc, char ** argv ){ setbuf(stderr, NULL); setbuf(stdout, NULL); @WIDGET@ window = So@Gui@::init(argv[0]); srand(SbTime::getTimeOfDay().getMsecValue()); So@Gui@ExaminerViewer * viewer = new So@Gui@ExaminerViewer(window); viewer->setTransparencyType(SoGLRenderAction::DELAYED_BLEND); viewer->setDecoration(FALSE); SoInput * in = new SoInput; unsigned int len; char * buffer = strconcat(scenegraph, len); in->setBuffer(buffer, len); SoNode * scene; if ( ! SoDB::read(in, scene) ) { delete [] buffer; delete in; delete viewer; fprintf(stderr, "%s: error in scene - exiting.\n", argv[0]); exit(-1); } delete [] buffer; delete in; scene->ref(); // FIXME: for some reason, getNodeByName() doesn't work with SGI // Inventor. Investigate. 20010919 mortene. SoCallback * hook = (SoCallback *) getNodeByName(scene, "hook"); if ( ! hook ) { fprintf(stderr, "hook not installed.\n"); } else { hook->setCallback(event_cb, viewer); } initLines((SoCoordinate3 *) getNodeByName(scene, "redlines")); initLines((SoCoordinate3 *) getNodeByName(scene, "greenlines")); initLines((SoCoordinate3 *) getNodeByName(scene, "bluelines")); initPoints((SoCoordinate3 *) getNodeByName(scene, "points")); scene->unrefNoDelete(); viewer->setSceneGraph(scene);#ifdef HAVE_SOCOMPONENT_SETFULLSCREEN viewer->setFullScreen(TRUE); // might be too slow?#endif // HAVE_SOCOMPONENT_SETFULLSCREEN viewer->show(); viewer->viewAll(); viewer->setTitle("Styx Demo"); So@Gui@::show(window); So@Gui@::mainLoop(); delete viewer; return 0;}/* EOF ****************************************************************** */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -