- UID
- 3187
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-3-20
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
一:获得块的相关坐标。见附件
因为我要对块进行管理,如相关块统计、各个块端点的属性等
二:关于钩子问题。
昨天从您处获得的代码加入钩子后所获得的坐标不对,麻烦帮我看看,谢谢!
生成钩子:
m_hHook=::SetWindowsHookEx(WH_MOUSE,MouseHookProc,(HINSTANCE)NULL,GetCurrentThreadId());
钩子函数:
LRESULT CALLBACK MouseHookProc(int nCode,WPARAM wParam,LPARAM lParam)
{
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 (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] );
}
//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 CallNextHookEx(m_hHook,nCode,wParam,lParam);
} |
|