ObjectARX, AutoCAD. Среда программирования библиотеки C++

         

Пример 4: Вычисление Круга, чтобы Рисовать - часть 2


// Get the number of pixels on the X- and Y-edges of

// a unit square centered at (0.0, 0.0, 0.0), in

// world coordinates.

//

AcGePoint3d center(0.0, 0.0, 0.0);

AcGePoint2d area;

pV->viewport().getNumPixelsInUnitSquare(center, area);

// If the area values are negative, then we are in

// perspective mode and the center is too close or

// in back of the viewport.

//

if (area.x > 0.0) {

// Print out the number of pixels along the

// Y-axis of the unit square used in

// getNumPixelsInUnitSquare.

//

AcGeVector3d norm(0.0, 0.0, 1.0);

AcGeVector3d dir(1.0, 0.0, 0.0);

char buf[100];

sprintf(buf, "%7.3lf", area.y);

pV->geometry().text(center, norm, dir, 1.0, 1.0, 0.0, buf);

// Draw a circle that depends on how big the circle

// is in the viewport. This requires

// figuring out the fewest number of segments needed

// by a polyline so that it doesn’t look segmented.

//

// The worldDraw() and viewportDraw() of

// an entity in a viewport are only called during a

// regen and not necessarily during a ZOOM or PAN.

// The reason is that a regen produces something

// akin to a very high resolution image internally,

// which AutoCAD can zoom in or pan around. That is,

// until you get too close to this image or any of

// its edges, at which point a regen is internally

// invoked for that viewport and a new internal

// image is created (ready to be mildly zoomed and

// panned).

//

double radius = 0.5;

double half_pixel_hgt = 2.0 / area.x; // In WCS

int num_segs = 8;

double angle = two_pi / num_segs;

if (half_pixel_hgt > radius / 2) {

// The circle is approximately the same or less

// than the size of a pixel. So, generate a very

// small octagon.

//

num_segs = 8;

} else {

// Given a circle centered at the origin of a

// given radius in the XY-plane, and given a

// vertical line that intersects the X-axis at

// ’radius - half a pixel’, what is the angle

// from the X-axis of a line segment from the

// origin to the point where the vertical line




Содержание  Назад  Вперед