2023-03-31

推荐:将 NSDT场景编辑器 加入你的3D开发工具链

介绍

  鼠标拾取是一种常用的直观操作,用于与各种 3D 图形应用程序中的 3D 场景进行交互。CHAI3D 提供了一些基本功能来检测对象是否已被选中。鼠标选择过程需要首先设置碰撞记录器和所需的碰撞设置。下面的清单说明了一个基本示例。

using namespace chai3d;

cCollisionRecorder recorder;

cCollisionSettings settings;

// detect for any collision between mouse and scene

bool 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 down

if (state == GLUT_DOWN)

{

cCollisionRecorder recorder;

cCollisionSettings settings;

// detect for any collision between mouse and scene

bool hit = camera->select(x, y, windowW, windowH, recorder, settings);

if (hit)

{

// set color to red

cColorf color;

color.setRed();

// retrieve triangle selected by mouse

cTriangle* triangle = recorder.m_nearestCollision.m_triangle;

if (triangle != NULL)

{

// paint each vertex with the selected color

triangle->getVertex0()->setColor(color);

triangle->getVertex1()->setColor(color);

triangle->getVertex2()->setColor(color);

}

}

}

}

3D建模学习工作室翻译整理,转载请标明出处!

上一篇:Chai 3D :组件工具 (mvrlink.com)

下一篇:Chai 3D之音频 (mvrlink.com)

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容