描述:
本人用VC通过ActiveX来对AutoCAD进行二次开发。
有一个功能是对一条直线通过矩阵来实现平移、缩放。
代码如下:
void CWanDlg::OnButtonRelativeScale()
{
UpdateData(true);
IAcadLine Line;
IAcadModelSpace m_IMSpace;
SAFEARRAYBOUND RSbound;
RSbound.lLbound = 0;
RSbound.cElements = 4*4;
SAFEARRAY * pStartPoint = NULL;
pStartPoint= ::SafeArrayCreate(VT_R8,1,&RSbound);
if(!pStartPoint) AfxMessageBox("SafeArrayCreate error!");
double TransMatrix[4][4];
int index1,index2;
for(index1=0;index1<4;index1++)
{
for(index2=0;index2<4;index2++)
{
TransMatrix[index1][index2]=0;
}
}
TransMatrix[0][0]=m_RSFactor;//4*4矩阵的对角线上的变量
TransMatrix[1][1]=m_RSFactor;
TransMatrix[2][2]=m_RSFactor;
TransMatrix[3][3]=1;
long i=0;
for(index1=0;index1<4;index1++)
{
for(index2=0;index2<4;index2++)
{
SafeArrayPutElement(pStartPoint,&i,&TransMatrix[index1][index2]);
i++;
}//把数组赋值道SAFEARRAY里
}
VARIANT pRS;
VariantInit(&pRS);
pRS.vt =VT_ARRAY|VT_R8;
pRS.parray =pStartPoint;
int m_LineNum=m_IMSpace.GetCount();
VARIANT temp;
VariantInit(&temp);
temp.vt =VT_I2;
temp.iVal =m_LineNum-1;
Line=m_IMSpace.Item(temp);
Line.TransformBy(pRS);//转置 (这里出现了问题)
望各位大侠能帮小弟解决!!!
解决方案1:
首先抱歉,这几天事情多没上网,没有看到版主给我的信息。
再者,难道你不能自已看看MSDN吗,那上面讲的很清楚的。
我把你的程序改了一下,我是作过二维数组的,但因为手头没有那时的代码,可能不时非常准确。
void CWanDlg::OnButtonRelativeScale()
{
UpdateData(true);
IAcadLine Line;
IAcadModelSpace m_IMSpace;
SAFEARRAYBOUND RSbound[2];
RSbound[0].lLbound = 0;
RSbound[0].cElements = 4;
RSbound[1].lLbound=0;
RSbound[1].cElements=4;
SAFEARRAY * pStartPoint = NULL;
pStartPoint= ::SafeArrayCreate(VT_R8,2,RSbound);
if(!pStartPoint) AfxMessageBox("SafeArrayCreate error!");
double TransMatrix[4][4];
int index1,index2;
for(index1=0;index1<4;index1++)
{
for(index2=0;index2<4;index2++)
{
TransMatrix[index1][index2]=0;
}
}
TransMatrix[0][0]=m_RSFactor;//4*4矩阵的对角线上的变量
TransMatrix[1][1]=m_RSFactor;
TransMatrix[2][2]=m_RSFactor;
TransMatrix[3][3]=1;
long indice[2];
for(index1=0;index1<4;index1++)
{
indice[0]=index1;
for(index2=0;index2<4;index2++)
{
indice[1]=index2;
SafeArrayPutElement(pStartPoint,indice,&TransMatrix[index1][index2]);
}//把数组赋值道SAFEARRAY里
}
VARIANT pRS;
VariantInit(&pRS);
pRS.vt =VT_ARRAY|VT_R8;
pRS.parray =pStartPoint;
int m_LineNum=m_IMSpace.GetCount();
VARIANT temp;
VariantInit(&temp);
temp.vt =VT_I2;
temp.iVal =m_LineNum-1;
Line=m_IMSpace.Item(temp);
Line.TransformBy(pRS);//转置 (这里出现了问题)