SoCaculator SoTimeCounter SoElapsedTimer

本文介绍了一个使用Inventor编程实现的花朵沿特定曲线路径移动的示例。通过计算器引擎计算路径坐标,并利用时间计数器引擎控制花朵的移动速度,使得花朵能够沿着预定的路径进行舞蹈式的移动。

/*-------------------------------------------------------------- * 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; }

基于Java语言实现模板驱动的PDF文档动态生成 在软件开发过程中,经常需要根据预设的结构化模板自动生成格式规范的PDF文档。本文阐述一种基于Java技术栈的实现方案,该方案通过分离文档格式定义与数据填充逻辑,实现高效、灵活的PDF生成功能。 核心实现原理在于预先设计PDF模板文件,该模板定义了文档的固定布局、样式及占位符区域。应用程序运行时,通过解析业务数据,将动态内容精确填充至模板的指定位置,最终合成完整的PDF文档。这种方法确保了输出文档在格式上的一致性,同时支持内容的个性化定制。 技术实现层面,可选用成熟的Java开源库,例如Apache PDFBox或iText库。这些库提供了丰富的API,支持对PDF文档进行创建、编辑和内容注入操作。开发者需构建模板解析引擎,用于识别模板中的变量标记,并将其替换为相应的实际数据值。数据源通常来自数据库查询结果、用户输入或外部系统接口。 为提升系统性能与可维护性,建议采用分层架构设计。将模板管理、数据预处理、文档生成与渲染输出等功能模块化。此外,可引入缓存机制存储已编译的模板对象,避免重复解析开销。对于复杂排版需求,如表格、图表嵌入,需在模板设计中预留相应区域,并在数据填充阶段调用专门的渲染组件。 该方案适用于报告自动生成、电子票据打印、合同文档签发等多种业务场景,能够显著减少人工操作,提升文档处理的准确性与效率。通过调整模板与数据映射规则,可轻松适应不断变化的文档格式要求。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值