计算机图形学
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
计算机图形学
姓名:李倩倩 班级:硕研10-14
学号:
第一题:
#include <> #include <> void MidpintLine( HDC hDC,int x0,int y0,int x1,int y1,unsigned long color) { int a,b,delta1,delta2,d,x,y; a=y0-y1; b=x1-x0; d=2*a+b; delta1=2*a; delta2=2*(a+b); x=x0; y=y0; SetPixel(hDC,x,y,color); while(x else if(dx>dy) { int p=2*dy-dx; int inc1=2*dy,inc2=2*(dy-dx); for(i=0;i { SetPixel(pdc,x,y,color); x+=xinc; if(p<0) p+=inc1; else { y+=yinc; p+=inc2; } } } else { int p=2*dx-dy; int inc1=2*dx,inc2=2*(dx-dy); for(i=0;i { SetPixel(pdc,x,y,color); y+=yinc; if(p<0) p+=inc1; else { x+=xinc; p+=inc2; } } } } void circlePlotPoints(HDC pdc, int xc,int yc,int x,int y,COLORREF color) { SetPixel(pdc,xc+x,yc+y,color); SetPixel(pdc,xc+x,yc-y,color); SetPixel(pdc,xc-x,yc+y,color); SetPixel(pdc,xc-x,yc-y,color); SetPixel(pdc,xc+y,yc+x,color); SetPixel(pdc,xc+y,yc-x,color); SetPixel(pdc,xc-y,yc+x,color); SetPixel(pdc,xc-y,yc-x,color); } void MidpointCircle(HDC pdc,int xc,int yc,int r,COLORREF color) { int x=0; int y=r; int p=1-r; while(x<=y) { circlePlotPoints(pdc, xc,yc,x,y,color); x++; if(p<0) p+=2*x+1; else { y--; p+=2*(x-y)+1; } } } void drawCircle(HDC pdc,int xc,int yc,int radius,COLORREF color) { int x,y,p; x=0; y=radius; p=3-2*radius; while (x circlePlotPoints(pdc,xc,yc,x,y, color); if (p<0) p=p+4*x+6; else{ p=p+4*(x-y)+10; y-=1; } x+=1; } if(x==y) circlePlotPoints(pdc, xc,yc,x,y,color); } int main(int argc, char* argv[]) { char arg[200]={0}; arg[0]='\"'; strcpy(arg+1,argv[0]); int len=int(strlen(arg)); arg[len]='\"'; HWND hWnd=FindWindow(NULL,arg); HDC hDC=GetDC(hWnd); unsigned long color=0xffffff; MidpintLine(hDC,10,30,100,100,color ); bresenham(hDC,10,10,600,600,color); MidpointCircle(hDC,50,50,30,color); drawCircle(hDC,100,100,30,color); return 0; } 第二题: #include #include <> #include <> void init() { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0f, 800.0f, 0.0f, 600.0f); } class wcPt2D { public: wcPt2D(float _x, float _y) { x = _x, y = _y; } GLfloat x, y; }; wcPt2D pt[] = {wcPt2D(0,0), wcPt2D(100,0), wcPt2D(50,50)}; = verts[k].x + tx; verts[k].y = verts[k].y + ty; } glBegin(GL_POLYGON); for(k = 0;k glVertex2f(verts[k].x, verts[k].y); glEnd(); } wcPt2D vertsRot[3] = {wcPt2D(0,0), wcPt2D(0,0), wcPt2D(0,0)}; = + (verts[k].x - * cos(theta) - (verts[k].y - * sin(theta); vertsRot[k].y = + (verts[k].x - * sin(theta) + (verts[k].y - * cos(theta); } glBegin(GL_POLYGON); for(k = 0;k glVertex2f(vertsRot[k].x, vertsRot[k].y); glEnd(); } wcPt2D vertsNew[3] = {wcPt2D(0,0), wcPt2D(0,0), wcPt2D(0,0)}; = verts[k].x * sx + * (1 - sx); vertsNew[k].y = verts[k].y * sy + * (1 - sy); } glBegin(GL_POLYGON); for(k = 0;k vertsNew[k].y); glEnd(); } void Render() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 0.0f, 0.0f); translatePolygon(pt, 3, 200,20); //rotatePolygon(pt, 3, pt[0], 10); scalePolygon(pt, 3, pt[0], 5,5); glFlush(); } int main(int argc, char** argv)