- UID
- 1
- 积分
- 15891
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
下面代码可以获得鼠标位置的UCS下的座标,显示的和ACAD状态栏内的相同,有兴趣可以验证。
用这个函数替换...\ObjectARX\SAMPLES\MFCSAMPS目录下的PRETRANSLATE程序中的filterMouse() 函数,编译后,加载,然后用命令WMOUSE 执行。
- BOOL filterMouse(MSG *pMsg)
- {
- if( pMsg->message == WM_MOUSEMOVE )
- {
- acedDwgPoint cpt;
- ads_point ptDCS, ptWCS, norm;
- AcGePoint3d origin;
- AcGeVector3d e0, e1, e2;
- AcGeMatrix3d matUcs2Wcs, matWcs2Ucs;
- // 1: 获得显示座标系下的鼠标位置座标
- CPoint cPnt (pMsg->lParam) ;
- acedCoordFromPixelToWorld (cPnt, cpt) ;
- ads_point_set ( cpt, ptDCS );
- //ads_printf ( "\nMouse in Ucs %f, %f, %f", ptDCS[X], ptDCS[Y],
- ptDCS[Z] );
- //return FALSE;
- // 2: 转换鼠标座标从显示座标系到UCS
- //
- // 使用acdbEcs2Ucs 函数,参数是VIEWDIR 系统变量作为NOMAL向量
- // (Sure we have to transform the VIEWDIR value from UCS to WCS
- //
- struct resbuf rbview;
- ads_getvar( "viewdir", &rbview );
- ads_point_set( rbview.resval.rpoint, norm );
- // If the view direction is 0, 0, 1, then
- acedCoordFromPixelToWorld()
- // needs special handling -> we only have to translate the the
- point
- // by the distance the origin of the current UCS was moved
- double tol = 1e-10;
- if ((fabs(norm[X]) < tol) && (fabs(norm[Y]) < tol) &&
- ((fabs(norm[Z]) - 1.0) < tol)) {
- AcGePoint3d acadPt;
- acadPt.x = cpt[0];
- acadPt.y = cpt[1];
- acadPt.z = cpt[2];
- acdbUcsMatrix ( matUcs2Wcs );
- matUcs2Wcs.invert();
- matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);
- acadPt += origin.asVector();
- ads_printf ( "\nMouse in Ucs %f, %f, %f", acadPt[X],
- acadPt[Y], acadPt[Z] );
- return FALSE;
- }
- //转换 VIEWDIR 到 WCS
- acdbUcs2Wcs ( norm, norm, Adesk::kTrue );
- // 转换鼠标座标从DCS 到 WCS
- acdbEcs2Wcs( ptDCS, ptWCS, norm, Adesk::kTrue );
- // 3: 获得UCS下鼠标位置的座标
- //
- // For this we have to project the WCS coordinates to the UCS
- plane using
- // VIEWDIR 作投影方向.
- //
- // 获得 UCS->WCS 转换矩阵
- acdbUcsMatrix ( matUcs2Wcs );
- matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);
- // 创建一个当前UCS下的平面
- //
- AcGePlane thePlane ( origin, e0, e1);
- AcGePoint3d pntMouseInWCS( ptWCS[X], ptWCS[Y], ptWCS[Z] );
- AcGeVector3d vecViewdir( norm [X], norm [Y], norm [Z] );
- // 投影转换
- AcGePoint3d resPnt = pntMouseInWCS.project (thePlane, vecViewdir
- );
- // 转换点的座标到UCS.
- matWcs2Ucs = matUcs2Wcs.inverse();
- resPnt.transformBy ( matWcs2Ucs );
- //
- //查看ACAD状态行验证
- ads_printf ( "\nMouse in Ucs %f, %f, %f", resPnt[X], resPnt[Y],
- resPnt[Z] );
- }
- return FALSE; // continue
- }
注意:这个函数不能工作在图纸空间,由于acedCoordFromPixelToWorld()全局函数不能在图纸空间内工作。 |
|