|
乾坤大挪移ObjectARX延时动画效果简单示意
[code]ads_point pt;
ads_name ent;
if (RTNORM != acedEntSel(_T("\n选择对象: "),ent,pt))
{
return;
}
AcDbObjectId objId;
acdbGetObjectId(objId,ent);
if (objId.isNull())
{
return;
}
AcDbEntityPointer pEnt(objId,AcDb::kForRead);
Acad::ErrorStatus es = pEnt.openStatus();
if (Acad::eOk != es)
{
return;
}
AcDbBlockTableRecordPointer pBlkRcd(curDoc()->database()->currentSpaceId(),AcDb::kForWrite);
es = pBlkRcd.openStatus();
if (Acad::eOk != es)
{
return;
}
for (int i=1;i<50;i++)
{
AcDbEntity *pClone =AcDbEntity::cast(pEnt->clone());
if (pClone == NULL)
{
continue;
}
AcDbEntityPointer pCopy;
es = pCopy.acquire(pClone);
if (Acad::eOk != es)
{
delete pClone;
continue;
}
AcGeMatrix3d mat;
mat.setToTranslation(AcGeVector3d(i*100,0,0));
pCopy->transformBy(mat);
pCopy->setColorIndex(i);
pBlkRcd->appendAcDbEntity(pCopy);
//绘出图形
pCopy->draw();
//更新显示
acedUpdateDisplay();
//延时100ms
Sleep(100);
//_sleep(100);
}
static void MyGroupMyCommand1 () {
ads_point pt;
ads_name ent;
if (RTNORM != acedEntSel(_T("\n选择对象: "),ent,pt))
{
return;
}
AcDbObjectId objId;
acdbGetObjectId(objId,ent);
if (objId.isNull())
{
return;
}
AcDbEntityPointer pEnt(objId,AcDb::kForRead);
Acad::ErrorStatus es = pEnt.openStatus();
if (Acad::eOk != es)
{
return;
}
AcDbBlockTableRecordPointer pBlkRcd(curDoc()->database()->currentSpaceId(),AcDb::kForWrite);
es = pBlkRcd.openStatus();
if (Acad::eOk != es)
{
return;
}
AcDbExtents ext;
es= pEnt->getGeomExtents(ext);
AcGePoint3d ptMin=ext.minPoint();
AcGePoint3d ptMax=ext.maxPoint();
AcGePoint3d ptMid=GetMiddlePoint(ptMin,ptMax);
double ddd= ptMax.distanceTo(ptMin);
AcGePoint3d PptMax = acdbHostApplicationServices()->workingDatabase()->extmax(); //右上角点
AcGePoint3d PptMin = acdbHostApplicationServices()->workingDatabase()->extmin(); //左下角点
acutPrintf(TEXT("\n PptMax=%9.4f %9.4f %9.4f :"), PptMax.x,PptMax.y,PptMax.z);
acutPrintf(TEXT("\n PptMin=%9.4f %9.4f %9.4f :"), PptMin.x,PptMin.y,PptMin.z);
for (int i=1;i<200;i++)
{
AcDbEntity *pClone =AcDbEntity::cast(pEnt->clone());
if (pClone == NULL)
{
continue;
}
AcDbEntityPointer pCopy;
es = pCopy.acquire(pClone);
if (Acad::eOk != es)
{
delete pClone;
continue;
}
AcGePoint3d tempts;
int x = random(int(PptMin.x), int(PptMax.x));
int y = random(int(PptMin.y), int(PptMax.y));
int c = random(1, 6);
double sc= c/2.0;
tempts.x=x;
tempts.y=y;
tempts.z=0;
AcGeMatrix3d mat;
mat.setToTranslation(AcGeVector3d(x-ptMid.x,y-ptMid.y,0));
mat.setToScaling(sc,tempts);
pCopy->transformBy(mat);
pCopy->setColorIndex(c);
pBlkRcd->appendAcDbEntity(pCopy);
//绘出图形
pCopy->draw();
pCopy->erase();
//更新显示
acedUpdateDisplay();
//延时100ms
Sleep(100);
//_sleep(100);
}
}
[/code] |
|