举荐:将 NSDT场景编辑器 退出你的3D开发工具链
介绍
鼠标拾取是一种罕用的直观操作,用于与各种 3D 图形应用程序中的 3D 场景进行交互。CHAI3D 提供了一些基本功能来检测对象是否已被选中。鼠标抉择过程须要首先设置碰撞记录器和所需的碰撞设置。上面的清单阐明了一个根本示例。
using namespace chai3d;cCollisionRecorder recorder;cCollisionSettings settings;// detect for any collision between mouse and scenebool hit = camera->select(x, y, windowWidth, windowHeight, recorder, settings);
碰撞记录器首先是空的,并累积位于鼠标指针下方的选定对象。为每个碰撞事件返回的信息存储在 cCollisionEvent 构造中。这样的构造将蕴含指向对象的指针、鼠标点击的3D地位信息、选定的三角形(cMesh)和外表法线。 能够设置碰撞设置以过滤某些类型的数据或放慢过程。
例07-鼠标抉择:操作员能够用鼠标抉择和挪动对象
在从示例 12 多边形提取的以下清单中,对鼠标单击回调进行了编程。如果抉择了网格对象中的三角形,则其顶点将涂成红色。
using namespace chai3d;void mouseClick(int button, int state, int x, int y){// mouse button downif (state == GLUT_DOWN){cCollisionRecorder recorder;cCollisionSettings settings;// detect for any collision between mouse and scenebool hit = camera->select(x, y, windowW, windowH, recorder, settings);if (hit){// set color to redcColorf color;color.setRed();// retrieve triangle selected by mousecTriangle* triangle = recorder.m_nearestCollision.m_triangle;if (triangle != NULL){// paint each vertex with the selected colortriangle->getVertex0()->setColor(color);triangle->getVertex1()->setColor(color);triangle->getVertex2()->setColor(color);}}}}
3D建模学习工作室翻译整顿,转载请表明出处!
上一篇:Chai 3D :组件工具 (mvrlink.com)
下一篇:Chai 3D之音频 (mvrlink.com)