Insyaalloh tidak ada yang sulit didunia ini asalkan kita ada niat untuk berusaha bisa, berikut adalah contoh membuat rumah berputar menggunakan visual c++
#include
#include
#include
#include
typedef struct {
float x,y;
}point2D_t;
typedef struct {
float r,g,b;
}color_t;
void userdraw(void);
void drawLine(float x1, float y1, float x2, float y2){
glBegin(GL_LINES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glEnd();
}
void drawLines(point2D_t pnt[],int n)
{
int i;
glBegin(GL_LINES);
for(i=0;i
}
glEnd();
}
void drawPolygon(point2D_t pnt[],int n)
{
int i;
glBegin(GL_LINE_LOOP);
for(i=0;i
}
glEnd();
}
void setColor(float red,float green,float blue)
{
glColor3f(red, green, blue);
}
void setColor(color_t col)
{
glColor3f(col.r, col.g, col.b);
}
void gradatePolygon(point2D_t a[],color_t w[],int n)
{
int i;
glBegin(GL_POLYGON);
for(i=0;i
glColor3f(w[i].r,w[i].g,w[i].b);
glVertex2f(a[i].x,a[i].y);
}
glEnd();
}
void fillPolygon(point2D_t pnt[],int n,color_t color)
{
int i;
setColor(color);
glBegin(GL_POLYGON);
for (i=0;i
}
glEnd();
}
void gradasi(point2D_t pnt[],int n,color_t color[])
{
int i;
glBegin(GL_POLYGON);
for (i=0;i
setColor(color[i]);
}
glEnd();
}
void userdraw(void){
static float tick=0;
int a;
color_t abu={0.5,0.5,0.5};
color_t merah={1,0,0};
color_t kuning={1,1,0};
color_t merahh={1,0,0};
point2D_t atap[4]={{70,70},{220,70},{205,130},{35,130}};
point2D_t atapp[4];
point2D_t pintu[4]={{40,0},{40,50},{65,50},{65,0}};
point2D_t pintuu[4];
point2D_t dpn[5]={{0,0},{0,70},{35,130},{70,70},{70,0}};
point2D_t dpan[5];
point2D_t grs[2]={{0,70},{70,70}};
point2D_t gris[2];
point2D_t smpg[4]={{70,0},{70,70},{210,70},{210,0}};
point2D_t smping[4];
point2D_t jen1[4]={{5,20},{5,50},{20,50},{20,20}};
point2D_t jen2[4]={{22,20},{22,50},{37,50},{37,20}};
point2D_t jen3[4]={{80,20},{80,50},{95,50},{95,20}};
point2D_t jen4[4]={{97,20},{97,50},{112,50},{112,20}};
point2D_t jen5[4]={{124,20},{124,50},{139,50},{139,20}};
point2D_t jen6[4]={{141,20},{141,50},{156,50},{156,20}};
point2D_t jen7[4]={{168,20},{168,50},{183,50},{183,20}};
point2D_t jen8[4]={{185,20},{185,50},{200,50},{200,20}};
point2D_t jend1[4];point2D_t jend2[4]; point2D_t jend3[4];point2D_t jend4[4]; point2D_t jend5[4]; point2D_t jend6[4]; point2D_t jend7[4]; point2D_t jend8[4];
point2D_t lbng1[4]={{5,53},{5,59},{37,59},{37,53}};
point2D_t lbng2[4]={{40,53},{40,59},{65,59},{65,53}};
point2D_t lbng3[4]={{80,53},{80,59},{112,59},{112,53}};
point2D_t lbng4[4]={{124,53},{124,59},{156,59},{156,53}};
point2D_t lbng5[4]={{168,53},{168,59},{200,59},{200,53}};
point2D_t lbang1[4];
point2D_t lbang2[4];
point2D_t lbang3[4];
point2D_t lbang4[4];
point2D_t lbang5[4];
point2D_t dlm1[4]={{7,54},{7,57},{35,57},{35,54}};
point2D_t dlm2[4]={{42,54},{42,57},{63,57},{63,54}};
point2D_t dlm3[4]={{82,54},{82,57},{110,57},{110,54}};
point2D_t dlm4[4]={{126,54},{126,57},{154,57},{154,54}};
point2D_t dlm5[4]={{170,54},{170,57},{198,57},{198,54}};
point2D_t dlam1[4];
point2D_t dlam2[4];
point2D_t dlam3[4];
point2D_t dlam4[4];
point2D_t dlam5[4];
point2D_t crbg[4]={{20,105},{20,135},{30,135},{30,120}};
point2D_t crbong[4];
point2D_t jln[4]={{20,-48},{50,0},{60,0},{80,-48}};
point2D_t jlan[4];
for(a=0;a<4;a++){
atapp[a].x=atap[a].x*cos(tick/30)-atap[a].y*sin(tick/30);
atapp[a].y=atap[a].x*sin(tick/30)+atap[a].y*cos(tick/30);}
for(a=0;a<4;a++){
pintuu[a].x=pintu[a].x*cos(tick/30)-pintu[a].y*sin(tick/30);
pintuu[a].y=pintu[a].x*sin(tick/30)+pintu[a].y*cos(tick/30);}
for(a=0;a<5;a++){
dpan[a].x=dpn[a].x*cos(tick/30)-dpn[a].y*sin(tick/30);
dpan[a].y=dpn[a].x*sin(tick/30)+dpn[a].y*cos(tick/30);}
for(a=0;a<2;a++){
gris[a].x=grs[a].x*cos(tick/30)-grs[a].y*sin(tick/30);
gris[a].y=grs[a].x*sin(tick/30)+grs[a].y*cos(tick/30);}
for(a=0;a<4;a++){
smping[a].x=smpg[a].x*cos(tick/30)-smpg[a].y*sin(tick/30);
smping[a].y=smpg[a].x*sin(tick/30)+smpg[a].y*cos(tick/30);
}
for(a=0;a<4;a++){
jend1[a].x=jen1[a].x*cos(tick/30)-jen1[a].y*sin(tick/30);
jend1[a].y=jen1[a].x*sin(tick/30)+jen1[a].y*cos(tick/30);
jend2[a].x=jen2[a].x*cos(tick/30)-jen2[a].y*sin(tick/30);
jend2[a].y=jen2[a].x*sin(tick/30)+jen2[a].y*cos(tick/30);
jend3[a].x=jen3[a].x*cos(tick/30)-jen3[a].y*sin(tick/30);
jend3[a].y=jen3[a].x*sin(tick/30)+jen3[a].y*cos(tick/30);
jend4[a].x=jen4[a].x*cos(tick/30)-jen4[a].y*sin(tick/30);
jend4[a].y=jen4[a].x*sin(tick/30)+jen4[a].y*cos(tick/30);
jend5[a].x=jen5[a].x*cos(tick/30)-jen5[a].y*sin(tick/30);
jend5[a].y=jen5[a].x*sin(tick/30)+jen5[a].y*cos(tick/30);
jend6[a].x=jen6[a].x*cos(tick/30)-jen6[a].y*sin(tick/30);
jend6[a].y=jen6[a].x*sin(tick/30)+jen6[a].y*cos(tick/30);
jend7[a].x=jen7[a].x*cos(tick/30)-jen7[a].y*sin(tick/30);
jend7[a].y=jen7[a].x*sin(tick/30)+jen7[a].y*cos(tick/30);
jend8[a].x=jen8[a].x*cos(tick/30)-jen8[a].y*sin(tick/30);
jend8[a].y=jen8[a].x*sin(tick/30)+jen8[a].y*cos(tick/30);
lbang1[a].x=lbng1[a].x*cos(tick/30)-lbng1[a].y*sin(tick/30);
lbang1[a].y=lbng1[a].x*sin(tick/30)+lbng1[a].y*cos(tick/30);
lbang2[a].x=lbng2[a].x*cos(tick/30)-lbng2[a].y*sin(tick/30);
lbang2[a].y=lbng2[a].x*sin(tick/30)+lbng2[a].y*cos(tick/30);
lbang3[a].x=lbng3[a].x*cos(tick/30)-lbng3[a].y*sin(tick/30);
lbang3[a].y=lbng3[a].x*sin(tick/30)+lbng3[a].y*cos(tick/30);
lbang4[a].x=lbng4[a].x*cos(tick/30)-lbng4[a].y*sin(tick/30);
lbang4[a].y=lbng4[a].x*sin(tick/30)+lbng4[a].y*cos(tick/30);
lbang5[a].x=lbng5[a].x*cos(tick/30)-lbng5[a].y*sin(tick/30);
lbang5[a].y=lbng5[a].x*sin(tick/30)+lbng5[a].y*cos(tick/30);
dlam1[a].x=dlm1[a].x*cos(tick/30)-dlm1[a].y*sin(tick/30);
dlam1[a].y=dlm1[a].x*sin(tick/30)+dlm1[a].y*cos(tick/30);
dlam2[a].x=dlm2[a].x*cos(tick/30)-dlm2[a].y*sin(tick/30);
dlam2[a].y=dlm2[a].x*sin(tick/30)+dlm2[a].y*cos(tick/30);
dlam3[a].x=dlm3[a].x*cos(tick/30)-dlm3[a].y*sin(tick/30);
dlam3[a].y=dlm3[a].x*sin(tick/30)+dlm3[a].y*cos(tick/30);
dlam4[a].x=dlm4[a].x*cos(tick/30)-dlm4[a].y*sin(tick/30);
dlam4[a].y=dlm4[a].x*sin(tick/30)+dlm4[a].y*cos(tick/30);
dlam5[a].x=dlm5[a].x*cos(tick/30)-dlm5[a].y*sin(tick/30);
dlam5[a].y=dlm5[a].x*sin(tick/30)+dlm5[a].y*cos(tick/30);
crbong[a].x=crbg[a].x*cos(tick/30)-crbg[a].y*sin(tick/30);
crbong[a].y=crbg[a].x*sin(tick/30)+crbg[a].y*cos(tick/30);
jlan[a].x=jln[a].x*cos(tick/30)-jln[a].y*sin(tick/30);
jlan[a].y=jln[a].x*sin(tick/30)+jln[a].y*cos(tick/30);
}
fillPolygon(atapp,4,abu);
fillPolygon(pintuu,4,merah);
setColor(0.,0.,0.);
drawPolygon(dpan,5);
drawLines(gris,2);
drawPolygon(smping,4);
fillPolygon(jend1,4,kuning);
fillPolygon(jend2,4,kuning);
fillPolygon(jend3,4,kuning);
fillPolygon(jend4,4,kuning);
fillPolygon(jend5,4,kuning);
fillPolygon(jend6,4,kuning);
fillPolygon(jend7,4,kuning);
fillPolygon(jend8,4,kuning);
setColor(0.,0.,0.);
drawPolygon(lbang1,4);
drawPolygon(lbang2,4);
drawPolygon(lbang3,4);
drawPolygon(lbang4,4);
drawPolygon(lbang5,4);
fillPolygon(dlam1,4,merah);
fillPolygon(dlam2,4,merah);
fillPolygon(dlam3,4,merah);
fillPolygon(dlam4,4,merah);
fillPolygon(dlam5,4,merah);
setColor(0,0,1);
drawPolygon(crbong,4);
setColor(0,1,0);
drawLines(jlan,4);
tick=tick-0.1;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
userdraw();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,150);
glutInitWindowSize(640,480);
glutCreateWindow("Rumah munyer by yudha ");
glClearColor(0,0.6,1,0.0);
gluOrtho2D(-320., 320., -240.0, 240.0);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Setitik ilmu akan menjadikan bulatan yang sempurna suatu saat. Semoga bermanfaat ^_^
0 komentar:
Silakan Bekomentar.!!!
Semakin banyak berkomentar, semakin banyak backlink, semakin cinta Search Engine terhadap blog anda
:7: :8: :9: :10: :11: :12:
Posting Komentar