选择集的转换
该函数通过将转换矩阵(类型)应用于集合中的实体来转换选择集。acedXformSS()ads_matrix 这为使用 //(或 /)调用 ROTATE、SCALE、MIRROR 或 MOVE 命令或使用 .acedCommandS()acedCommandC()acedCmd()acedCmdC()acdbEntMod() 选择集可以通过任何常用方式获得。矩阵必须进行均匀缩放。即缩放向量中的元素S X S Y S Z 必须都是平等的;在矩阵表示法中,M 00 M 11 M 22 . 如果比例向量不均匀,则报告错误。acedXformSS() 下面的示例代码使用交叉框获取选择集,然后将以下矩阵应用于该选择集。 ![]() 应用此矩阵可将实体缩放一半(从而将它们移向原点),并将其位置平移 (20.0,5.0)。 int rc, i, j;
ads_point pt1, pt2;
ads_matrix matrix;
ads_name ssname;
// Initialize pt1 and pt2 here.
rc = acedSSGet("C", pt1, pt2, NULL, ssname);
if (rc == RTNORM) {
// Initialize to identity.
ident_init(matrix);
// Initialize scale factors.
matrix[0][0] = matrix[1][1] = matrix[2][2] = 0.5;
// Initialize translation vector.
matrix[0][T] = 20.0;
matrix[1][T] = 5.0;
rc = acedXformSS(ssname, matrix);
}
调用 时,必须指定类似的函数,以便用户以交互方式控制转换的效果。函数的声明必须采用以下格式:acedDragGen() int scnf(ads_point pt, ads_matrix mt) 如果它修改了矩阵,如果它没有,或者如果它检测到错误,它应该返回。RTNORMRTNONERTERROR 每次用户移动光标时,该函数都会调用该函数。该函数设置矩阵的新值。当返回状态为 时,将新矩阵应用于选择集。如果不需要修改矩阵(例如,如果只是显示瞬态向量),则应返回 。在这种情况下,忽略并且不转换选择集。acedDragGen()scnfscnf()mtscnf()RTNORMacedDragGen()scnf()acedGrVecs()scnf()RTNONEacedDragGen()mt 在以下示例中,该函数将矩阵设置为简单地移动(平移)选择集,而无需缩放或旋转。 int dragsample(usrpt, matrix)
ads_point usrpt
ads_matrix matrix;
{
ident_init(matrix); // Initialize to identity.
// Initialize translation vector.
matrix[0][T] = usrpt[X];
matrix[1][T] = usrpt[Y];
matrix[2][T] = usrpt[Z];
return RTNORM; // Matrix was modified.
}
相反,以下版本缩放当前 XY 平面中的选择集,但不移动它。dragsample() int dragsample(usrpt, matrix)
ads_point usrpt
ads_matrix matrix;
{
ident_init(matrix); // Initialize to identity.
matrix[0][0] = userpt[X];
matrix[1][1] = userpt[Y];
return RTNORM; // Matrix was modified.
}
对 that 使用 transformation 函数的调用如下所示:acedDragGen() int rc;
ads_name ssname;
ads_point return_pt;
// Prompt the user for a general entity selection:
if (acedSSGet(NULL, NULL, NULL, NULL, ssname) == RTNORM)
rc = acedDragGen(ssname, // The new entities
"Scale the selected objects by dragging", // Prompt
0, // Display normal cursor (crosshairs)
dragsample, // Pointer to the transform function
return_pt); // Set to the specified location
更复杂的转换可以旋转实体、组合转换(如示例中所示)等。acedXformSS() 组合变换矩阵称为矩阵组成。以下函数通过返回 中的乘积来组成两个变换矩阵。resmat
void xformcompose(ads_matrix xf1, ads_matrix xf2,
ads_matrix resmat)
{
int i, j, k;
ads_real sum;
for (i=0; i<=3; i++) {
for (j=0; j<=3; j++) {
sum = 0.0;
for (k=0; k<3; k++) {
sum += xf1[i,k] * xf2[k,j];
}
resmat[i,j] = sum;
}
}
}
父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 07:08
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.