- UID
- 1
- 积分
- 16111
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
发表于 2002-3-7 02:34:05
|
显示全部楼层
Re: [求助]:XD,tooltip找到了,但是获取鼠标坐标没有找到,
最初由 梦宁 发布
[B]关于获取鼠标在autocad的坐标(鼠标滑动时) [/B]
给你贴个资料:如何获得鼠标的在UCS下的座标
How to get the mouse cursor coordinates in UCS?
ID 3115
Applies to: AutoCAD 2000I
Date 1/29/2002
This document is part of UCS Processing User Input
Question
How do I get the mouse cursor coordinates in UCS?
Answer
The following code obtains and prints the mouse coordinates in the UCS. The
coordinates are the same as the coordinates displayed in AutoCAD's status bar
(for you to see and verify).
To test it replace the filterMouse() function in
the...\ObjectARX\SAMPLES\MFCSAMPS\PRETRANSLATE sample with the one that follows,
then compile the project, load it in AutoCAD and enter the WMOUSE command.

- 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() |
|