根据2点缩放窗口的代码,与你比例因素缩放一个道理,可以参考下。 void Zoom(AcGePoint3d pt1, AcGePoint3d pt2) { AcDbViewTableRecord view; struct resbuf rb; struct resbuf wcs, dcs, ccs; // ads_trans coord system flags ads_point vpDir; ads_point wmin, wmax; // min and max corners of the zoom window ads_point wdcsmax, wdcsmin; // windows corners in device coords AcGeVector3d viewDir; AcGePoint2d cenPt; ads_real lenslength,viewtwist,frontz,backz; ads_point target; int viewmode,tilemode,cvport; // Get window to zoom to: ads_point pt3 = {pt1.x,pt1.y,pt1.z}, pt4 = {pt2.x,pt2.y,pt2.z}; // sort window corners to upper right and lower left if (pt3[X] >= pt4[X]) { wmax[X] = pt3[X]; wmin[X] = pt4[X]; } else { wmax[X] = pt4[X]; wmin[X] = pt3[X]; }
if (pt3[Y] >= pt4[Y]) { wmax[Y] = pt3[Y]; wmin[Y] = pt4[Y]; } else { wmax[Y] = pt4[Y]; wmin[Y] = pt3[Y]; } wmax[Z] = 0.0; wmin[Z] = 0.0; 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; // Get the 'VPOINT' direction vector ads_getvar("VIEWDIR", &rb); ads_trans(rb.resval.rpoint, &ccs, &wcs, 0, vpDir); viewDir.set(vpDir[X], vpDir[Y], vpDir[Z]); // convert upper right window corner to DCS ads_trans(wmax, &ccs, &dcs, 0, wdcsmax); // convert lower left window corner to DCS ads_trans(wmin, &ccs, &dcs, 0, wdcsmin); // calculate and set view center point cenPt.set(wdcsmin[X] + ((wdcsmax[X] - wdcsmin[X]) / 2.0), wdcsmin[Y] + ((wdcsmax[Y] - wdcsmin[Y]) / 2.0) ); view.setCenterPoint(cenPt); // set view height and width and direction view.setHeight(fabs(wdcsmax[Y] - wdcsmin[Y])); view.setWidth(fabs(wdcsmax[X] - wdcsmin[X])); view.setViewDirection(viewDir); // get and set other properties ads_getvar("LENSLENGTH", &rb); lenslength = rb.resval.rreal; view.setLensLength(lenslength); ads_getvar("VIEWTWIST", &rb); viewtwist = rb.resval.rreal; view.setViewTwist(viewtwist); ads_getvar("FRONTZ", &rb); frontz = rb.resval.rreal; ads_getvar("BACKZ", &rb); backz = rb.resval.rreal; ads_getvar("VIEWMODE", &rb); viewmode = rb.resval.rint; view.setPerspectiveEnabled(viewmode & 1); view.setFrontClipEnabled(viewmode & 2); view.setBackClipEnabled(viewmode & 4); view.setFrontClipAtEye(!(viewmode & 16)); ads_getvar("TILEMODE", &rb); tilemode = rb.resval.rint; ads_getvar("CVPORT", &rb); cvport = rb.resval.rint; // Paperspace flag Adesk::Boolean paperspace = ((tilemode == 0) && (cvport == 1)) ? Adesk::kTrue : Adesk::kFalse; view.setIsPaperspaceView(paperspace); if (Adesk::kFalse == paperspace) { view.setFrontClipDistance(frontz); view.setBackClipDistance(backz); } else { view.setFrontClipDistance(0.0); view.setBackClipDistance(0.0); } ads_getvar("TARGET", &rb); ads_trans(rb.resval.rpoint, &ccs, &wcs, 0, target); view.setTarget(AcGePoint3d(target[X], target[Y], target[Z])); // update view acedSetCurrentView( &view, NULL ); }
|