📄 chart.cpp.in
字号:
setRandomDemoMode(void){ static int prev = -1; int mode; while ( (mode = rand() % 10) == prev ) { } prev = mode; // = 9; int x, y; int w = 12; int d = 12; animateddemo = FALSE; startLevelEditing(); switch ( mode ) { case 0: do { for ( y = 0; y < d; y++ ) for ( x = 0; x < w; x++ ) setLevel( w, d, x, y, 0.1f + float((x+y)*(x+y)) / 100.0f ); } while ( 0 ); break; case 1: do { for ( y = 0; y < d; y++ ) for ( x = 0; x < w; x++ ) setLevel( w, d, x, y, 0.0f ); } while ( 0 ); break; case 2: do { for ( y = 0; y < d; y++ ) { int disty; if ( y >= 6 ) disty = y - 6; else disty = 5 - y; disty = disty * disty; for ( x = 0; x < w; x++ ) { int distx; if ( x >= 6 ) distx = x - 6; else distx = 5 - x; float height = float(distx * distx + disty) * 0.05f; setLevel( w, d, x, y, height ); } } } while ( 0 ); break; case 3: do { for ( y = 0; y < d; y++ ) { int disty; if ( y >= 6 ) disty = 6 - (y - 6); else disty = 6 - (5 - y); disty = disty * disty; for ( x = 0; x < w; x++ ) { int distx; if ( x >= 6 ) distx = 6 - (x - 6); else distx = 6 - (5 - x); float height = float(distx * distx + disty) * 0.05f; setLevel( w, d, x, y, height ); } } } while ( 0 ); break; case 4: do { for ( y = 0; y < d; y++ ) for ( x = 0; x < w; x++ ) setLevel( w, d, x, y, 0.15 * float(x+y) ); } while ( 0 ); break; case 5: do { for ( y = 0; y < d; y++ ) { int disty; if ( y >= 6 ) disty = y - 6; else disty = 5 - y; disty = disty * disty; for ( x = 0; x < w; x++ ) { int distx; if ( x >= 6 ) distx = x - 6; else distx = 5 - x; float height = 4.0f - float(distx * distx + disty) * 0.05f; setLevel( w, d, x, y, height ); } } } while ( 0 ); break; case 6: do { for ( y = 0; y < d; y++ ) { for ( x = 0; x < w; x++ ) { int disty = -6 + y; disty = disty * disty; int distx = 6 - x; distx = distx * distx; float height = 2.0f + float(distx - disty) * 0.05f; setLevel( w, d, x, y, height ); } } } while ( 0 ); break; case 7: do { for ( y = 0; y < d; y++ ) { for ( x = 0; x < w; x++ ) { int disty = -6 + y; disty = disty * disty * disty; int distx = 6 - x; distx = distx * distx * distx; float height = 2.0f + float(distx - disty) * 0.008f; setLevel( w, d, x, y, height ); } } } while ( 0 ); break; case 8: do { for ( y = 0; y < d; y++ ) { for ( x = 0; x < w; x++ ) { float disty = 5.5 - float(y); float distx = 5.5 - float(x); disty = disty * disty; distx = distx * distx; float height = 4.0f; if ( x < 6 ) { if ( y < 6 ) height += distx * disty * 0.004f; else height -= distx * disty * 0.004f; } else { if ( y < 6 ) height += distx * disty * 0.004f; else height -= distx * disty * 0.004f; } setLevel( w, d, x, y, height ); } } } while ( 0 ); break; case 9: do { for ( y = 0; y < d; y++ ) { for ( x = 0; x < w; x++ ) { float disty = 5.5 - float(y); float distx = 5.5 - float(x); disty = disty * disty; distx = distx * distx; float height = 4.0f; if ( x < 6 ) { if ( y < 6 ) height += distx * disty * 0.004f; else height -= distx * disty * 0.004f; } else { if ( y < 6 ) height -= distx * disty * 0.004f; else height += distx * disty * 0.004f; } setLevel( w, d, x, y, height ); } } } while ( 0 ); break; } // case finishLevelEditing();}voidanimateDemoMode(void){}voidevent_cb( void * userdata, SoAction * actio ){ if ( demomode && actio->isOfType(SoGLRenderAction::getClassTypeId()) ) { SoGLRenderAction * action = (SoGLRenderAction *) actio; SbVec2s viewport = action->getViewportRegion().getWindowSize(); if ( viewport != lastviewport ) { lastviewport = viewport; SoTranslation * translation = (SoTranslation *) findNode("menuposition"); float aspect = float(viewport[0]) / float(viewport[1]); float factor = float(100)/float(viewport[1]) * 3.0f; if ( aspect > 1.0f ) { translation->translation.setValue(SbVec3f(-0.5f * aspect, 0.5f, 0.0f)); } else { translation->translation.setValue(SbVec3f(-0.5f, 0.5f / aspect, 0.0f)); factor /= aspect; } SoScale * scale = (SoScale *) findNode("menusize"); scale->scaleFactor.setValue( SbVec3f(factor,factor,1.0f) ); } SbTime now = SbTime::getTimeOfDay(); if ( (now.getMsecValue() - demochange.getMsecValue()) > 4000 ) { demochange = now; setRandomDemoMode(); } else if ( animateddemo ) { animateDemoMode(); } return; } if ( actio->getTypeId() != SoHandleEventAction::getClassTypeId() ) return; SoHandleEventAction * action = (SoHandleEventAction *) actio; const SoEvent * event = action->getEvent(); SoIndexedFaceSet * topfaces = (SoIndexedFaceSet *) findNode("topfaces"); assert(topfaces != NULL); SoIndexedFaceSet * sidefaces = (SoIndexedFaceSet *) findNode("sidefaces"); assert(sidefaces != NULL); SoIndexedFaceSet * demoface = (SoIndexedFaceSet *) findNode( "demoface" ); SoAsciiText * demotext = (SoAsciiText *) findNode( "demotext" ); SoIndexedFaceSet * interactface = (SoIndexedFaceSet *) findNode( "interactface" ); SoAsciiText * interacttext = (SoAsciiText *) findNode( "interacttext" ); if ( event->getTypeId() == SoMouseButtonEvent::getClassTypeId() ) { SoMouseButtonEvent * bevent = (SoMouseButtonEvent *) event; if ( bevent->getState() == SoButtonEvent::DOWN ) { if ( bevent->getButton() != SoMouseButtonEvent::BUTTON1 ) return; if ( ! picker ) picker = new SoRayPickAction(action->getViewportRegion()); else picker->setViewportRegion(action->getViewportRegion()); picker->setPoint( bevent->getPosition() ); SoNode * menu = findNode("menu"); SoNode * scene = findNode("scene"); do { picker->apply(menu); SoPickedPoint * point = picker->getPickedPoint(); if ( ! point ) break; SoPath * path = point->getPath(); if ( ! path ) break; if ( path->getTail() == demoface || path->getTail() == demotext ) { if ( ! demomode ) { demochange = SbTime::getTimeOfDay(); SoRotor * spin = (SoRotor *) findNode("spin"); spin->on.setValue(TRUE); demomode = TRUE; } } else if ( path->getTail() == interactface || path->getTail() == interacttext ) { if ( demomode ) { SoRotor * spin = (SoRotor *) findNode("spin"); spin->on.setValue(FALSE); demomode = FALSE; } } return; } while ( FALSE ); if ( demomode ) return; picker->apply(scene); SoPickedPoint * point = picker->getPickedPoint(); if ( ! point ) return; SoPath * path = point->getPath(); if ( ! path ) return; SoCamera * camera = viewer->getCamera(); if ( ! camera ) return; if ( path->getTail() != topfaces && path->getTail() != sidefaces ) return; attached = TRUE; SbVec3f pos = point->getObjectPoint(); SbVec3f wpos = point->getPoint(); if ( path->getTail() == topfaces ) { row = (int) pos[1]; column = (int) pos[0]; offset = 0.0f; } else { // get row and column from "fixed" pick position _inside_ the bar, // adjusted by the face normal const SoDetail * detail = point->getDetail(); if ( ! detail || ! detail->isOfType(SoFaceDetail::getClassTypeId()) ) return; int faceidx = ((SoFaceDetail *)detail)->getFaceIndex(); SoIndexedFaceSet * faceset = (SoIndexedFaceSet *) findNode("sidefaces"); int normalidx = faceset->normalIndex[faceidx]; SoNormal * normals = (SoNormal *) findNode("normals"); SbVec3f fixedpos = pos - (normals->vector[normalidx] * 0.01f); row = (int) fixedpos[1]; column = (int) fixedpos[0]; offset = getLevel( 12, 12, column, row ) - pos[2]; } mark( 12, 12, column, row, TRUE ); char string[16]; sprintf(string, "(%d,%d) %4.2f", column, row, getLevel(12, 12, column, row) ); SoText2 * positiontext = (SoText2 *) findNode("positiontext"); positiontext->string.setValue(string); SbVec3f point1(wpos[0], wpos[1], 0.0f); SbVec3f point2(wpos[0], wpos[1], 1.0f); SbVec3f point3(0, 0, 0); SbRotation rot( camera->orientation.getValue() ); rot.multVec( SbVec3f( 1, 0, 0 ), point3 ); if ( pickplane != NULL ) delete pickplane; pickplane = new SbPlane( point1, point2, point1 - point3 ); } else if ( bevent->getState() == SoButtonEvent::UP ) { if ( bevent->getButton() != SoMouseButtonEvent::BUTTON1 ) return; mark( 12, 12, column, row, FALSE ); SoText2 * positiontext = (SoText2 *) findNode("positiontext"); positiontext->string.setValue(""); attached = FALSE; } return; } if ( event->getTypeId() == SoLocation2Event::getClassTypeId() ) { if ( ! attached ) return; SoLocation2Event * levent = (SoLocation2Event *) event; if ( ! picker ) picker = new SoRayPickAction(viewer->getGLRenderAction()->getViewportRegion()); picker->setPoint( levent->getPosition() ); picker->apply(actio->getNodeAppliedTo()); SbLine line( picker->getLine() ); SbVec3f ipos; if ( pickplane->intersect(line, ipos)) { if ( (ipos[2] + offset) < 0 ) ipos[2] = 0 - offset; startLevelEditing(); setLevel( 12, 12, (int) column, row, ipos[2] + offset ); finishLevelEditing(); } char string[16]; sprintf(string, "(%d,%d) %4.2f", column, row, getLevel(12, 12, column, row) ); SoText2 * positiontext = (SoText2 *) findNode("positiontext"); positiontext->string.setValue(string); }}/************************************************************************ */// the scene graphchar scene_iv[] = "\#Inventor V2.1 ascii\n\\n\Separator {\n\DEF scene Separator {\n\PerspectiveCamera {}\n\DEF spin Rotor {\n\on TRUE\n\speed 0.05\n\}\n\Translation { translation -6 -6 0 }\n\ShapeHints {\n\vertexOrdering COUNTERCLOCKWISE\n\shapeType SOLID\n\}\n\DEF normals Normal {\n\vector [ 1 0 0, -1 0 0, 0 1 0, 0 -1 0, 0 0 1, 0 0 -1 ]\n\}\n\NormalBinding { value PER_FACE_INDEXED }\n\DEF points Coordinate3 {}\n\Separator {\n"#ifdef HAVE_SOPOLYGONOFFSET"PolygonOffset {\n\factor 1\n\units 1\n\}\n"#endif //!HAVE_SOPOLYGONOFFSET"IndexedFaceSet {\n\coordIndex [\n\0, 1, 2, 3, 0, -1, 4, 7, 6, 5, 4, -1, 0, 4, 5, 1, 0, -1,\n\1, 5, 6, 2, 1, -1, 2, 6, 7, 3, 2, -1, 3, 7, 4, 0, 3, -1\n\]\n\normalIndex [ 4, 5, 3, 0, 2, 1, -1 ]\n\}\n\}\n\MaterialBinding { value PER_FACE_INDEXED }\n\DEF materials Material {}\n\DEF topfaces IndexedFaceSet {}\n\DEF hook Callback {}\n\DEF sidefaces IndexedFaceSet {}\n\}\n\DEF menu Separator {\n\OrthographicCamera { height 1 }\n\DirectionalLight {\n\color 1 1 1\n\direction 0 0 1\n\}\n\Coordinate3 {\n\point [\n\0.01 -0.17 -0.1, 0.01 -0.06 -0.1, 0.39 -0.06 -0.1, 0.39 -0.17 -0.1,\n\0.01 -0.29 -0.1, 0.01 -0.18 -0.1, 0.39 -0.18 -0.1, 0.39 -0.29 -0.1,\n\0.00 0.00 -0.2, 0.40 0.00 -0.2, 0.40 -0.40 -0.2, 0.00 -0.40 -0.2\n\]\n\}\n\DEF menuposition Translation {}\n\DEF menusize Scale {}\n\Separator {\n\Material { diffuseColor 0.7 0.2 0.2 }\n\DEF baseface IndexedFaceSet { coordIndex [ 8, 9, 10, 11, 8, -1 ] }\n\BaseColor { rgb 0 0 0 }\n\Translation { translation 0.02 -0.05 0 }\n\DEF wwwtext Text2 { string \"www.Coin3D.org\" }\n\Translation { translation 0.02 -0.32 0 }\n\DEF positiontext Text2 { string \"\" }\n\}\n\Separator {\n\Material { diffuseColor 0 0.8 0.9 }\n\DEF interactface IndexedFaceSet { coordIndex [ 4, 5, 6, 7, 4, -1 ] }\n\Translation { translation 0.02 -0.27 0 }\n\Scale { scaleFactor 0.01 0.01 0.01 }\n\BaseColor { rgb 0 0 0 }\n\DEF interacttext AsciiText { string \"Interact\" }\n\}\n\Separator {\n\Material { diffuseColor 0 0.9 0.8 }\n\DEF demoface IndexedFaceSet { coordIndex [ 0, 1, 2, 3, 0, -1 ] }\n\Translation { translation 0.02 -0.15 0 }\n\Scale { scaleFactor 0.01 0.01 0.01 }\n\BaseColor { rgb 0 0 0 }\n\DEF demotext AsciiText { string \"Demo\" }\n\}\n}\n}\n";/* EOF ****************************************************************** */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -