栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

OpenCascade 实现模型的缩放、平移、旋转

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

OpenCascade 实现模型的缩放、平移、旋转

在 Open Cascade 中如果想对某个模型进行调整,如移动、旋转、缩放,可以使用自带的模型操纵器(AIS_Manipulator)组件。

代码示例 第一步:创建模型操纵器
// 先创建一个长方体
gp_Ax2 boxPos;
boxPos.SetLocation(gp_Pnt(10.0, 10.0, 10.0));
TopoDS_Shape boxShape = BRepPrimAPI_MakeBox(boxPos, 15, 20, 30).Shape();
Handle(AIS_Shape) aisBoxShape = new AIS_Shape(boxShape);
aisBoxShape->SetColor(Quantity_NOC_ORANGE2);
m_context->Display(aisBoxShape, Standard_False);

// 再创建一个模型操纵器
Handle(AIS_Manipulator) aManipulator = new AIS_Manipulator();
// 可以用 SetPart 禁用或启用某些轴的平移、旋转或缩放的可视部分
aManipulator->SetPart(0, AIS_ManipulatorMode::AIS_MM_Scaling, Standard_False);  // 禁用了 X 轴的缩放
aManipulator->SetPart(1, AIS_ManipulatorMode::AIS_MM_Rotation, Standard_False); // 禁用了 Y 轴的旋转
// 将操纵器附在创建的长方体上
aManipulator->Attach(aisBoxShape);
// 启用指定的操纵模式
aManipulator->EnableMode(AIS_ManipulatorMode::AIS_MM_Translation);  // 启用移动
aManipulator->EnableMode(AIS_ManipulatorMode::AIS_MM_Rotation);     // 启用旋转
aManipulator->EnableMode(AIS_ManipulatorMode::AIS_MM_Scaling);      // 启用缩放
// 激活操纵器
aManipulator->SetModeActivationOnDetection(Standard_True);

m_context->UpdateCurrentViewer();

此时运行,可以看到模型操纵器已经显示在界面中了。但是还无法响应操作。

第二步:事件绑定
// 在 mouse button 事件中加入如下代码:
if (aManipulator->HasActiveMode())
{
	aManipulator->StartTransform(anXPix, anYPix, aV3dView);	// 初始化转换,记录起始位置
}

// ...

// 在 mouse move 事件中加入如下代码:
if (aManipulator->HasActiveMode())
{
	aManipulator->Transform(anXPix, anYPix, aV3dView); // 应用鼠标从起始位置开始移动而产生的变换
	aV3dView->Redraw();
}

// ...

// 在 mouse release 事件中加入如下代码:
aManipulator->StopTransform(Standard_True);	// 重置起始变换参数(函数参数为 Standard_False 则撤销本次的变换)
第三步:停止模型操纵器
aManipulator->DeactivateCurrentMode();
第四步:将模型操纵器与模型分离
aManipulator->Detach();
效果演示

参考资料
  • OpenCASCADE AIS Manipulator - eryar - C++博客 (cppblog.com)
  • AIS_Manipulator Class Reference - Open CASCADE Technology documentation
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/352983.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号