在用mfc绘图类作图时候遇到了问题,上来请教一下各位大虾~#include<cmath>
#define fnx(x,y) (int)(x*cos(theta)-y*sin(theta))
#define fny(x,y) (int)(x*cos(theta)+y*sin(theta))//这里是想要进行坐标变换,就是将图形旋转45°而进行的宏定义,theta变量是定义在VIEW类中的DOUBLE变量void CHomework10_1View::OnDraw(CDC* pDC)
{
CHomework10_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rc;//这里主要是对坐标系进行控制,将逻辑坐标移到窗口中央。
GetClientRect(&rc);
pDC->SetMapMode(7);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
pDC->SetWindowExt(1000,1000);
pDC->SetViewportExt(700,-700); const double pi=3.1415926;
theta=(double)45/(double)180*(float)pi; //旋转45° 这个变量定义在VIEW类里 POINT p,q;
int r=300;
int a1=0,a2=0,b1=0,b2=0;//一下是在尝试的时候遇到的问题:
pDC->MoveTo( fnx(0,-50) , fny(0,-50) );//大家注意这一句的fnx(0,-50);现在这样写会报错,可是一旦我把“-
//”去掉就不会有错。错误是:error C2105: '--' needs l-value
pDC->LineTo(fnx(0,50),fny(0,50));
}
如果这个问题解决不了的话后面的诸多东西都没法做,有没有那位明白的能告诉小弟一下啊!
#define fnx(x,y) (int)(x*cos(theta)-y*sin(theta))
#define fny(x,y) (int)(x*cos(theta)+y*sin(theta))//这里是想要进行坐标变换,就是将图形旋转45°而进行的宏定义,theta变量是定义在VIEW类中的DOUBLE变量void CHomework10_1View::OnDraw(CDC* pDC)
{
CHomework10_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rc;//这里主要是对坐标系进行控制,将逻辑坐标移到窗口中央。
GetClientRect(&rc);
pDC->SetMapMode(7);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2);
pDC->SetWindowExt(1000,1000);
pDC->SetViewportExt(700,-700); const double pi=3.1415926;
theta=(double)45/(double)180*(float)pi; //旋转45° 这个变量定义在VIEW类里 POINT p,q;
int r=300;
int a1=0,a2=0,b1=0,b2=0;//一下是在尝试的时候遇到的问题:
pDC->MoveTo( fnx(0,-50) , fny(0,-50) );//大家注意这一句的fnx(0,-50);现在这样写会报错,可是一旦我把“-
//”去掉就不会有错。错误是:error C2105: '--' needs l-value
pDC->LineTo(fnx(0,50),fny(0,50));
}
如果这个问题解决不了的话后面的诸多东西都没法做,有没有那位明白的能告诉小弟一下啊!
#define fnx(x,y) (int)((x)*cos(theta)-(y)*sin(theta))
#define fny(x,y) (int)((x)*cos(theta)+(y)*sin(theta))
fnx(0,-50)
变成
(int)(0*cos(theta)--50*sin(theta))
显然变成个--50,是不对的,加上括号是宏定义必须注意的,否则展开后效果会很奇特的