SoCaculator SoTimeCounter SoElapsedTimer

/*-------------------------------------------------------------- * A calculator engine computes a closed, planar curve. * The output from the engine is connected to the translation * applied to a flower object, which consequently moves * along the path of the curve. *------------------------------------------------------------*/ #include <Inventor/SoDB.h> #include <Inventor/Win/SoWin.h> #include <Inventor/Win/SoWinRenderArea.h> #include <Inventor/engines/SoCalculator.h> #include <Inventor/engines/SoElapsedTime.h> #include <Inventor/engines/SoTimeCounter.h> #include <Inventor/nodes/SoDirectionalLight.h> #include <Inventor/nodes/SoMaterial.h> #include <Inventor/nodes/SoPerspectiveCamera.h> #include <Inventor/nodes/SoRotationXYZ.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoTransform.h> #include <Inventor/nodes/SoTranslation.h> int main(int, char **argv) { // Initialize Inventor and Win HWND myWindow = SoWin::init(argv[0]); if (myWindow == NULL) exit(1); SoSeparator *root = new SoSeparator; root->ref(); // Add a camera and light SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; myCamera->position.setValue(-0.5f, -3.0f, 19.0f); myCamera->nearDistance = 10.0f; myCamera->farDistance = 26.0f; root->addChild(myCamera); root->addChild(new SoDirectionalLight); // Rotate scene slightly to get better view SoRotationXYZ *globalRotXYZ = new SoRotationXYZ; globalRotXYZ->axis = SoRotationXYZ::X; globalRotXYZ->angle = (float)(M_PI/7.0f); root->addChild(globalRotXYZ); // Read the background path from a file and add to the group SoInput myInput; if (!myInput.openFile("../data/flowerPath.iv")) exit (1); SoSeparator *flowerPath = SoDB::readAll(&myInput); if (flowerPath == NULL) exit(1); root->addChild(flowerPath); / // CODE FOR The Inventor Mentor STARTS HERE // Flower group SoSeparator *flowerGroup = new SoSeparator; root->addChild(flowerGroup); // Read the flower object from a file and add to the group if (!myInput.openFile("../data/flower.iv")) exit (1); SoSeparator *flower= SoDB::readAll(&myInput); if (flower == NULL) exit (1); // Set up the flower transformations SoTranslation *danceTranslation = new SoTranslation; SoTransform *initialTransform = new SoTransform; flowerGroup->addChild(danceTranslation); initialTransform->scaleFactor.setValue(10.0f, 10.0f, 10.0f); initialTransform->translation.setValue(0.0f, 0.0f, 5.0f); flowerGroup->addChild(initialTransform); flowerGroup->addChild(flower); // Set up an engine to calculate the motion path: // r = 5*cos(5*theta); x = r*cos(theta); z = r*sin(theta) // Theta is incremented using a time counter engine, // and converted to radians using an expression in // the calculator engine. SoCalculator *calcXZ = new SoCalculator; SoTimeCounter *thetaCounter = new SoTimeCounter; thetaCounter->max = 360; thetaCounter->step = 4; thetaCounter->frequency = 0.075f; calcXZ->a.connectFrom(&thetaCounter->output); calcXZ->expression.set1Value(0, "ta=a*M_PI/180"); // theta calcXZ->expression.set1Value(1, "tb=5*cos(5*ta)"); // r calcXZ->expression.set1Value(2, "td=tb*cos(ta)"); // x calcXZ->expression.set1Value(3, "te=tb*sin(ta)"); // z calcXZ->expression.set1Value(4, "oA=vec3f(td,0,te)"); danceTranslation->translation.connectFrom(&calcXZ->oA); // CODE FOR The Inventor Mentor ENDS HERE / SoWinRenderArea *myRenderArea = new SoWinRenderArea(myWindow); myRenderArea->setSceneGraph(root); myRenderArea->setTitle("Flower Dance"); myRenderArea->show(); SoWin::show(myWindow); SoWin::mainLoop(); return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值