先上代码
void Draw(CDC *p,double house[28][4],int Color,int DispAxis)
{
double x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3;
int nface=0; CDC MemDC; //首先定义一个显示设备对象
CBitmap MemBitmap;//定义一个位图对象
//HWND hwndIE = FindWindow(CMy3D_ShowDlg,NULL); //随后建立与屏幕显示兼容的内存显示设备
MemDC.CreateCompatibleDC(NULL); //这时还不能绘图,因为没有地方画 ^_^
//下面建立一个与屏幕显示兼容的位图,至于位图的大小嘛,可以用窗口的大小
CRect rect;
GetClientRect(AfxGetMainWnd()->m_hWnd,&rect);
MemBitmap.CreateCompatibleBitmap(p,rect.Width(),rect.Height()); //将位图选入到内存显示设备中
//只有选入了位图的内存显示设备才有地方绘图,画到指定的位图上
CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap); //先用背景色将位图清除干净,这里我用的是黑色作为背景
MemDC.FillSolidRect(0,0,rect.Width(),rect.Height(),BLACK);
CPen pen(PS_SOLID,1,Color);
CBrush brush(MYCOLOR);
MemDC.SelectObject(pen);
MemDC.SelectObject(brush); for(nface=0;nface<6;nface++)
{
MemDC.BeginPath();
x0=house[nface*4][0];
y0=house[nface*4][1];
z0=house[nface*4][2];
x1=house[nface*4+1][0];
y1=house[nface*4+1][1];
z1=house[nface*4+1][2];
x2=house[nface*4+2][0];
y2=house[nface*4+2][1];
z2=house[nface*4+2][2];
x3=house[nface*4+3][0];
y3=house[nface*4+3][1];
z3=house[nface*4+3][2];
moveto2(&MemDC,house[nface*4][0],house[nface*4][1],house[nface*4][2]);
lineto2(&MemDC,house[nface*4+1][0],house[nface*4+1][1],house[nface*4+1][2]);
lineto2(&MemDC,house[nface*4+2][0],house[nface*4+2][1],house[nface*4+2][2]);
lineto2(&MemDC,house[nface*4+3][0],house[nface*4+3][1],house[nface*4+3][2]);
lineto2(&MemDC,house[nface*4][0],house[nface*4][1],house[nface*4][2]); MemDC.EndPath();
MemDC.FillPath();
}
//将内存中的图拷贝到屏幕上进行显示
p->BitBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY);
//绘图完成后的清理
MemBitmap.DeleteObject();
MemDC.DeleteDC();
首先一个奇怪的地方就是红色部分网上都是只有一个参数,但是我必须要两个参数,非要我给个窗口句柄,我只好这样写了,也不知道对不对,不过图是画出来了的,说明应该是对的,但是只要我一拖动(其他地方有相应的处理拖动的函数,都是来调用draw的),还是在狂闪烁,完全没变化,大家帮忙看看吧,到底是咋回事啊。在线等啊,整了两天了!
希望大家帮助!!!谢谢!!!!
void Draw(CDC *p,double house[28][4],int Color,int DispAxis)
{
double x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3;
int nface=0; CDC MemDC; //首先定义一个显示设备对象
CBitmap MemBitmap;//定义一个位图对象
//HWND hwndIE = FindWindow(CMy3D_ShowDlg,NULL); //随后建立与屏幕显示兼容的内存显示设备
MemDC.CreateCompatibleDC(NULL); //这时还不能绘图,因为没有地方画 ^_^
//下面建立一个与屏幕显示兼容的位图,至于位图的大小嘛,可以用窗口的大小
CRect rect;
GetClientRect(AfxGetMainWnd()->m_hWnd,&rect);
MemBitmap.CreateCompatibleBitmap(p,rect.Width(),rect.Height()); //将位图选入到内存显示设备中
//只有选入了位图的内存显示设备才有地方绘图,画到指定的位图上
CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap); //先用背景色将位图清除干净,这里我用的是黑色作为背景
MemDC.FillSolidRect(0,0,rect.Width(),rect.Height(),BLACK);
CPen pen(PS_SOLID,1,Color);
CBrush brush(MYCOLOR);
MemDC.SelectObject(pen);
MemDC.SelectObject(brush); for(nface=0;nface<6;nface++)
{
MemDC.BeginPath();
x0=house[nface*4][0];
y0=house[nface*4][1];
z0=house[nface*4][2];
x1=house[nface*4+1][0];
y1=house[nface*4+1][1];
z1=house[nface*4+1][2];
x2=house[nface*4+2][0];
y2=house[nface*4+2][1];
z2=house[nface*4+2][2];
x3=house[nface*4+3][0];
y3=house[nface*4+3][1];
z3=house[nface*4+3][2];
moveto2(&MemDC,house[nface*4][0],house[nface*4][1],house[nface*4][2]);
lineto2(&MemDC,house[nface*4+1][0],house[nface*4+1][1],house[nface*4+1][2]);
lineto2(&MemDC,house[nface*4+2][0],house[nface*4+2][1],house[nface*4+2][2]);
lineto2(&MemDC,house[nface*4+3][0],house[nface*4+3][1],house[nface*4+3][2]);
lineto2(&MemDC,house[nface*4][0],house[nface*4][1],house[nface*4][2]); MemDC.EndPath();
MemDC.FillPath();
}
//将内存中的图拷贝到屏幕上进行显示
p->BitBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY);
//绘图完成后的清理
MemBitmap.DeleteObject();
MemDC.DeleteDC();
首先一个奇怪的地方就是红色部分网上都是只有一个参数,但是我必须要两个参数,非要我给个窗口句柄,我只好这样写了,也不知道对不对,不过图是画出来了的,说明应该是对的,但是只要我一拖动(其他地方有相应的处理拖动的函数,都是来调用draw的),还是在狂闪烁,完全没变化,大家帮忙看看吧,到底是咋回事啊。在线等啊,整了两天了!
希望大家帮助!!!谢谢!!!!
解决方案 »
- MFC OCX VS2008控件问题!
- 弱弱的问下?
- Color dialog box [Win32]
- 关于CString的简单问题啊 急 在线等~~~
- 工具栏里的图标怎么使用256色?
- 一个不知道为什么的错误请大家帮忙看一下为什么,错在哪?
- 我的机器遭受攻击的纪录。这个家伙用了一个自动攻击程序。我刚刚开放80端口一个小时就被他嗅到了。
- 用那些API可以读取文件
- 用VC6如何检查磁盘不是本地硬盘,而是USB.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- MFC 读Excel很慢怎么办
- win32 Api 下 SetWindowText()怎样实现换行????????
- 求一个使用连接点的列子
这里我想设成红色的,没成功,晕。急等 谢谢大家了
void CMy3D_ShowDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// & bit-and
// && logical-and
if(nFlags & MK_LBUTTON && RotateMode!=ROTATE_N)
{
if(oldPoint.x<point.x)
Rotate(house,-R_STEP,RotateMode);
else
Rotate(house,R_STEP,RotateMode);
InvalidateRect(NULL,false);
}
else if(nFlags & MK_LBUTTON && flag == 1)
{
if(oldPoint.x!=point.x||oldPoint.y!=point.y)
{
Move(house,point.x-oldPoint.x,oldPoint.y-point.y,0);
InvalidateRect(NULL,false);
}
InvalidateRect(NULL,false); }
oldPoint=point;
CDialog::OnMouseMove(nFlags, point);
}这里是拖动处理的,其中的move函数是自己写的,也贴出来
void Move(double house[28][4],double x,double y,double z)
{
double SMatrix[4][4];
ResetMatrix(SMatrix);
SMatrix[3][0]=x;
SMatrix[3][1]=y;
SMatrix[3][2]=z;
MultiMatrix((double*)house,SMatrix,28,4);
}
这是一个调用矩阵乘法做三维变换的函数,具体的乘法就是一个算法,就是改变了house【28】【4】的点的值,然后InvalidateRect(NULL,false);的时候,传给第一个贴出来的draw的参数就变了,于是图像位置就变了。大体就是这样 帮我看下吧 谢了!!!
Move处理的是整体图像拖动的变换做这两个都还是会闪烁
{
return TRUE;
}背景去掉了吗?加上这两句试试 ON_WM_ERASEBKGND() 填到消息映射里
这时候,不要调用InvalidateRect ,建议先在内存中画好,然后贴图!
还是很感谢大家 这个事情错在我 那段代码没给出来 不然大家都看出来了就 我太笨了~ 呵呵
分给大家,谢谢大家!!