Use C programming languane and IDE for performing the follow

Use C programming languane and IDE for performing the following tasks. Write an animation program that implements the example two-dimensional rotation procedure rotatePolygon() given below. An input polygon is to be rotated repeatedly in small steps around a pivot point in the xy plane. Small angles are to be used for each successive step in the rotation. Redo Task 1 with OpenGL transformation functions glTranslate*() and glRotate*() instead of rotatePolygon().

Solution

#include #include #include #include #include struct wct { int x; int y; }; typedef double matrix[3][3]; matrix thm; void setid(matrix m) { int i,j; for(i=0;i<3;i++) for(j=0;j<3;j++) m[i][j]=(i=j); } void premul(matrix a) { matrix tmp; int r,c; for(r=0;r<3;r++) for(c=0;c<3;c++) tmp[r][c]=thm[r][0]*a[0][c]+thm[r][1]*a[1][c]+thm[r][2]*a[2][c]; for(r=0;r<3;r++) for(c=0;c<3;c++) thm[r][c]=tmp[r][c]; } void transform(int n,wct *pt) { int i; double tmp; for(i=0;i { tmp=thm[0][0]*pt[i].x+thm[0][1]*pt[i].y+thm[0][2]; pt[i].y=thm[1][0]*pt[i].x+thm[1][1]*pt[i].y+thm[1][2]; pt[i].x=tmp; } } void translation(int tx,int ty) { matrix m; setid(m); m[0][2]=tx; m[1][2]=ty; premul(m); } void rotation(double a,wct pt) { matrix m; a=(22*a)/1260; setid(m); m[0][0]=cos(a); m[0][1]=sin(a); m[0][2]=pt.x*(1-cos(a))-pt.x*sin(a); m[1][0]=sin(a); m[1][1]=cos(a); m[1][2]=pt.y*(1-cos(a))-pt.x*sin(a); premul(m); } void scaling(int sx,int sy,wct pt) { matrix m; setid(m); m[0][0]=sx; m[0][1]=pt.x*(1-sx); m[1][1]=sy; m[1][2]=pt.y*(1-sy); premul(m); } void usrpoly(wct *pt,int n) { int i,j=0; int *a; for(i=0;i { a[j]=pt[i].x; a[j+1]=pt[i].y; j+=2; } j-=2; a[j]=a[0]; a[j+1]=a[1]; drawpoly(n,a); } void main() { int gd,gm,i,j; void translate(wct *,int); void rotate(wct *,int); void scale(wct *,int); void translation(int,int); wct pt[]={200,200,400,200,400,300,200,300,200,200}; int tx,ty; int c; do { clrscr(); printf(\"\ \\t--------------------------- \"); printf(\"\ \\t 2d transformations(Polygon)\"); printf(\"\ \\t--------------------------- \"); printf(\"\ \\t 1.Translation \"); printf(\"\ \\t 2.Rotation \"); printf(\"\ \\t 3.Scaling \"); printf(\"\ \\t 4.Exit \"); printf(\"\ \\t Enter your choice:\"); scanf(\"%d\",&c); detectgraph(&gd,&gm); initgraph(&gd,&gm,\"C:\\\\TC\\\\BGI\"); switch(c) { case 1: translate(pt,6);getch();break; case 2: rotate(pt,6);getch();break; case 3: scale(pt,6);getch();break; case 4: printf(\"\ \\t\\t Exit from the menu\"); getch();break; default: printf(\"\ \\t\\t invalid choice........!\");break; } getch(); closegraph(); }while(c!=4); } void translate(wct *pt,int n) { int x,y; setid(thm); cleardevice(); usrpoly(pt,n); printf(\"\\t\\t Enter point to translate (x,y):\"); scanf(\"%d%d\",&x,&y); translation(x,y); transform(n,pt); usrpoly(pt,n); } void rotate(wct *pt,int n) { double ang; wct rpt; setid(thm); usrpoly(pt,n); printf(\"\\t\\t Enter the angle to rotate\"); scanf(\"%f\",&ang); printf(\"Enter the reference point(x,y)\"); scanf(\"%d%d\",&rpt.x,&rpt.y); rotation(ang,rpt); transform(n,pt); usrpoly(pt,n); } void scale(wct *pt,int n) { double ang; int sx,sy; wct rpt; setid(thm); usrpoly(pt,n); printf(\"\ \\t Enter scaling factor (sx,sy)\"); scanf(\"%d%d\",&sx,&sy); printf(\"Enter the reference point (x,y)\"); scanf(\"%d%d\",&rpt.x,&rpt.y); scaling(sx,sy,rpt); transform(n,pt); usrpoly(pt,n); }
 Use C programming languane and IDE for performing the following tasks. Write an animation program that implements the example two-dimensional rotation procedur

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site