找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

楼主: XDSoft

“放缩”VIEWPORT的ARX代码...

[复制链接]
发表于 2002-5-7 23:55:24 | 显示全部楼层
acedCoordFromPixelToWorld (cPnt, cpt) ,中cpt到底是升么坐标系下的坐标,如何转到ucs 下,我记得以前你贴过一个,显示鼠标坐标的例子,而且我试过是14下的,今天再看(查找功能,找不出来我是一篇一篇找的)却发现是2000i下的,有几个类14下没有

回复: 最初由 梦宁 发布
关于获取鼠标在autocad的坐标(鼠标滑动时)  




给你贴个资料:如何获得鼠标的在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.

code: 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
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-5-8 01:53:27 | 显示全部楼层
我想我一定是表达的有问题,简单的讲我只是想实现探索者的tab键,` 键的功能
我的代码是
BOOL filterLetterX(MSG *pMsg)
{
if (pMsg->message ==WM_KEYDOWN )
{
//关键代码
                ads_point ptDCS, ptWCS, norm;        
  AcGePoint3d  origin;        
  AcGeVector3d e0, e1, e2;        
  AcGeMatrix3d  matUcs2Wcs, matWcs2Ucs;  
                struct resbuf b1,b2;
                double scal,height,width;
                ads_point cpt,cpt1;
                AcDbViewTableRecord view;
                struct resbuf wcs, dcs, ccs;
         wcs.restype     = RTSHORT;     // WORLD coord system flag
     wcs.resval.rint = 0;
     ccs.restype     = RTSHORT;     // CURRENT coord system flag
     ccs.resval.rint = 1;
     dcs.restype     = RTSHORT;     // DEVICE coord system flag
     dcs.resval.rint = 2;


                if (pMsg->message == WM_LBUTTONDOWN)scal=2;
                if(pMsg->message == WM_RBUTTONDOWN)scal=0.5;       
        ads_getvar("viewsize", &b1);
        height=b1.resval.rreal/scal ;
        view.setHeight( height);
        ads_getvar("screensize", &b2);
        width=b2.resval.rpoint[1]*height/b2.resval.rpoint[0];
        view.setWidth(width);
        CPoint cPnt(pMsg->lParam) ;
        acedCoordFromPixelToWorld (cPnt, cpt) ;
       
//        ptDCS[0]=cpt[0];ptDCS[1]=cpt[1];ptDCS[2]=cpt[2];
//  struct resbuf rbview;        
//  ads_getvar( "viewdir", &rbview );        
//  ads_point_set( rbview.resval.rpoint, norm );
//acdbUcs2Wcs ( norm, norm, Adesk::kTrue );
//acdbEcs2Wcs( ptDCS, ptWCS, norm, Adesk::kTrue );
//acdbUcsMatrix ( matUcs2Wcs );                 
// matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);
//  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);
//matWcs2Ucs = matUcs2Wcs.inverse();        
// resPnt.transformBy ( matWcs2Ucs );

     ads_trans(cpt, &wcs, &dcs, 0, cpt1);
         //acdbUcs2Wcs(cpt,cpt1,0);
        AcGePoint2d cenPt(cpt1[0],cpt1[1]);

        view.setCenterPoint(cenPt);
        acdbSetCurrentView( &view, NULL );
        acedCoordFromWorldToPixel(0,cpt,cPnt);
        pMsg->lParam=MAKELONG(cPnt.x,cPnt.y);

        return TRUE; // throw away the message
        }
    return FALSE; // continue
}
你可以试一下,效果并不好
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-12-22 17:35:42 | 显示全部楼层
正在找,太好了。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-12-26 23:15:07 | 显示全部楼层
IAcadApplicat??AutoCAD应用程序接口直接有Zoom/Pan的函数调用一下不就好了吗?不需要自己变换啊.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-3-26 10:17:47 | 显示全部楼层
好呀,我要了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-22 11:40 , Processed in 0.429196 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表