明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3488|回复: 1

问获取当前视口(Viewport)坐标值的函数

[复制链接]
发表于 2005-3-2 17:11 | 显示全部楼层 |阅读模式
rt

3x a lot!
 楼主| 发表于 2005-3-3 10:36 | 显示全部楼层
在ObjectARX Developer's Guide 里找到了
Example 3: Obtaining the Window Coordinates

This example shows the use of AcGiViewportDraw::polylineDc() and AcGiViewport::getViewportDcCorners() to obtain the display coordinates of the viewport. This function is convenient when you are drawing graphics that depend on the physical layout of the viewport, such as icons and markers that vary with the size or borders of the viewport. The graphics drawn will change with panning and zooming.

The example draws a box in the upper-right corner of the viewport. The box's width and height are always one-tenth of the viewport's shortest dimension, and the box is centered one-tenth of the viewport's shortest dimension down and to the left of the upper-right-hand corner of the viewport:

void
AsdkIconSamp::viewportDraw(AcGiViewportDraw* pV)
{
// Get the current viewport's display coordinates.
//
AcGePoint2d lower_left, upper_right;
pV->viewport().getViewportDcCorners(lower_left, upper_right);
double xsize = upper_right.x - lower_left.x;
double ysize = upper_right.y - lower_left.y;
xsize /= 10.0;
ysize /= 10.0;
double xcenter = upper_right.x - xsize;
double ycenter = upper_right.y - ysize;
double half_xsize = xsize / 2.0;
double half_ysize = ysize / 2.0;
// Create a unit square.
//
const int num_verts = 5;
AcGePoint3d verts[num_verts];
for (int i = 0; i < num_verts; i++) {
verts.x = xcenter;
verts.y = ycenter;
verts.z = 0.0;
}
verts[0].x -= half_xsize;
verts[0].y += half_ysize;
verts[1].x += half_xsize;
verts[1].y += half_ysize;
verts[2].x += half_xsize;
verts[2].y -= half_ysize;
verts[3].x -= half_xsize;
verts[3].y -= half_ysize;
verts[4] = verts[0];
pV->subEntityTraits().setColor(kRed);
pV->geometry().polylineDc(num_verts, verts);
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 07:39 , Processed in 0.307011 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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