几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-05-06, 08:21 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】oddbviewport transformation from model space to paper space

oddbviewport transformation from model space to paper space
oddbviewport transformation from model space to paper space
i have a question on obtaining the matrix for transforming a oddbviewport object from model space to paper space. in order to obtain the matrix that transforms entities in model space to fit the viewport in paper space, i'm doing the following:
odabstractviewpeptr pview(pvp);
odgematrix3d modeltopaper = pview->worldtoeye(pvp);
but, this doesn't seem to work. what am i doing wrong?
i use the following code, hope this helps :
void od_ms2ps( oddbviewportptr pvp, odgematrix3d &resultmat) {
// first get all the data
odgevector3d viewdirection = pvp->viewdirection();
odgepoint2d centre2d = pvp->viewcenter();
odgepoint3d viewcenter = odgepoint3d( centre2d.x, centre2d.y, 0);
odgepoint3d viewtarget = pvp->viewtarget ();
double twistangle = -pvp->twistangle();
odgepoint3d centerpoint = pvp->centerpoint();
double viewheight = pvp->viewheight();
double height = pvp->height();
double width = pvp->width();
double scaling = viewheight / height;
double lenslength = pvp->lenslength();
// prepare the transformation
odgevector3d xaxis, yaxis, zaxis;
zaxis = viewdirection.normal();
xaxis = odgevector3d::kzaxis.crossproduct( viewdirection );
if( !xaxis.iszerolength() ) {
xaxis.normalize();
yaxis = zaxis.crossproduct( xaxis );
} else if( zaxis.z < 0 ) {
xaxis = -odgevector3d::kxaxis;
yaxis = odgevector3d::kyaxis;
zaxis = -odgevector3d::kzaxis;
} else {
xaxis = odgevector3d::kxaxis;
yaxis = odgevector3d::kyaxis;
zaxis = odgevector3d::kzaxis;
}
odgematrix3d dcs2wcs; // display coordinate system (dcs) to world coordinate system (wcs)
odgematrix3d ps2dcs; // paperspace to dcs
// first initialise with a transformation to centerpoint
ps2dcs = odgematrix3d::translation( odgepoint3d::korigin - centerpoint );
// then scale for the view
ps2dcs = ps2dcs * odgematrix3d::scaling( scaling, centerpoint );
// then adjust to the viewcenter
dcs2wcs = odgematrix3d::translation( viewcenter - odgepoint3d::korigin );
// then transform for the view direction
odgematrix3d matcoords;
matcoords.setcoordsystem( odgepoint3d::korigin, xaxis, yaxis, zaxis);
dcs2wcs = matcoords * dcs2wcs;
// then adjust for the viewtarget
dcs2wcs = odgematrix3d::translation( viewtarget - odgepoint3d::korigin ) * dcs2wcs;
// then the twist angle
dcs2wcs = odgematrix3d::rotation(twistangle, zaxis, viewtarget ) * dcs2wcs;
odgematrix3d perspmat;
if( pvp->isperspectiveon()) {
// we do special perspective handling
double viewsize = viewheight;
double aspectratio = width / height;
double adjustfactor = 1.0 / 42.0;
double adjustedlenslength = viewsize * lenslength * sqrt ( 1.0 +
aspectratio * aspectratio ) * adjustfactor;
double eyedistance = viewdirection.length();
double lensdistance = eyedistance - adjustedlenslength;
double ed = eyedistance;
double ll = adjustedlenslength;
double l = lensdistance;
perspmat.entry[2][2] = (ll - l ) / ll;
perspmat.entry[2][3] = l * ( ed - ll ) / ll;
perspmat.entry[3][2] = -1.0 / ll;
perspmat.entry[3][3] = ed / ll;
}
resultmat = ps2dcs.inverse() * perspmat * dcs2wcs.inverse();
}
// it gets a viewport and returns a transformation matrix,
// with which we can move a paperspace coordinate to the model space
// as looked from the given viewport
void od_ps2ms ( oddbviewportptr pvp, odgematrix3d &resultmat ) {
// keep life simple, just invert the other way
odgematrix3d mat;
od_ms2ps( pvp, mat );
resultmat = mat.inverse();
}
cheers
jason anderssen
jason,
thanks - i've been looking for this also, and yours is working much better than what i had put together. thanks again!
pete
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】loading paper space entities yang686526 DirectDWG 0 2009-05-06 05:15 PM
【转帖】conversion of model space entity to paper space yang686526 DirectDWG 0 2009-05-04 06:10 PM
【转帖】changing paper space background color yang686526 DirectDWG 0 2009-05-04 05:44 PM
【转帖】请教用arx实现model space与 paper space之间的相互切换 yang686526 ObjectARX(C++) 0 2009-04-18 08:40 PM
【转帖】model 3d space in winforms yang686526 SolidWorks二次开发 0 2009-04-12 09:48 PM


所有的时间均为北京时间。 现在的时间是 11:05 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多