- UID
- 1
- 积分
- 15892
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
发表于 2002-5-9 01:49:04
|
显示全部楼层
// 1: 获得DCS下鼠标 Mouse coords
CPoint cPnt (pMsg->lParam) ;
acedCoordFromPixelToWorld (cPnt, cpt) ;
去OBJECTARX安装目录:...\ObjectARX\SAMPLES\MFCSAMPS\PRETRANSLATE可以看到下面代码:
- [FONT=courier new]
- 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: Get the Mouse coords in DCS
- CPoint cPnt (pMsg->lParam) ;
- acedCoordFromPixelToWorld (cPnt, cpt) ;
- acdbPointSet ( cpt, ptDCS );
- //acutPrintf ( "\nMouse in Ucs %f, %f, %f", ptDCS[X], ptDCS[Y],ptDCS[Z] );
- //return FALSE;
- // 2: Transform the Mouse coords from DCS to WCS
- // For this we use the acdbEcs2Ucs function with the
- // value of the VIEWDIR system variable as the input normalvector of ECS
- // (Sure we have to transform the VIEWDIR value from UCS to WCS
- struct resbuf rbview;
- acedGetVar( "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 thepoint
- // 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();
- acutPrintf ( "\nMouse in Ucs %f, %f, %f", acadPt[X],acadPt[Y], acadPt[Z] );
- return FALSE;
- }
- //transfoming VIEWDIR to WCS
- acdbUcs2Wcs ( norm, norm, Adesk::kTrue );
- // Transforming the mouse coords from DCS to WCS
- acdbEcs2Wcs( ptDCS, ptWCS, norm, Adesk::kTrue );
- // 3: Get the Mouse coordinates in UCS //
- // For this we have to project the WCS coordinates to the UCSplane using
- // the VIEWDIR vector as projection direction. //
- // Getting the UCS->WCS transformation matrix
- acdbUcsMatrix ( matUcs2Wcs );
- matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);
- // Creating a plane which lies on the current UCS
- //
- AcGePlane thePlane ( origin, e0, e1);
- AcGePoint3d pntMouseInWCS( ptWCS[X], ptWCS[Y], ptWCS[Z] );
- AcGeVector3d vecViewdir( norm [X], norm [Y], norm [Z] );
- // Making the projection
- AcGePoint3d resPnt = pntMouseInWCS.project (thePlane, vecViewdir);
- // Transforming the point coordinates to UCS.
- matWcs2Ucs = matUcs2Wcs.inverse();
- resPnt.transformBy ( matWcs2Ucs );
- //this line prints the same coordinates as the coordinates
- //shown in AutoCAD's status bar
- acutPrintf ( "\nMouse in Ucs %f, %f, %f", resPnt[X], resPnt[Y],resPnt[Z] ); }
- return FALSE; // continue
- }
- NOTE: This doesn't work in perspective view because acedCoordFromPixelToWorld()
- doesn't work in perspective view.
- [/FONT]
|
|