打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Chai 3D之鼠标拾取
推荐:将 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);
}
}
}
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
CDR-实用快捷键
一款桌面日历设置
Unity3D学习笔记07:射线Ray实现点击拾取
工业仿真:Chai 3D之点云技术
Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形)
Objective-C入门教程02:定义一个类和实例化一个对象
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服