Dec 22, 2010

Polygon 3D Berputar Menggunakan Pelles C

Bagaimana cara membuat bangun segienam 3D menggunakan Pelles C yang dapat berputar ?? Berikut ini coding untuk membuatnya. Ingat, codingan ditulis di bawah tulisan "lakukan penggambaran di sini". Oh iya, sebelumnya tuliskan coding "float sudut=0;" di bawah kurung kurawal pertama ({ ) yang berada di bawah "int main (void);". Kalian juga bisa mengganti kecepatan putaran dengan mengganti "sudut-=0.5" sesuai keinginan anda. Tanda minus (-) di belakang kata sudut menandakan arah putaran searah jarum jam, sedangkan jika diganti plus (+) maka arah putaran akan berlawanan arah jarum jam.

Silahkan dicoba ;)








gluLookAt (10,10,20,0,0,0,0,1,0);
glRotatef(sudut,0,1,0);

glBegin (GL_POLYGON);
//depan
glColor3ub (255,255,0);
glVertex3f (-5,0,0);
glVertex3f (0,0,0);
glVertex3f (2,3,0);
glColor3ub (0,0,0);
glVertex3f (0,6,0);
glVertex3f (-5,6,0);
glVertex3f (-7,3,0);
glEnd();

glBegin (GL_POLYGON);
//belakang
glColor3ub (255,255,0);
glVertex3f (-5,0,-4);
glVertex3f (0,0,-4);
glVertex3f (2,3,-4);
glColor3ub (0,0,0);
glVertex3f (0,6,-4);
glVertex3f (-5,6,-4);
glVertex3f (-7,3,-4);
glEnd();

glBegin (GL_QUADS);
//kanan bawah
glColor3ub (223,105,200);
glVertex3f (0,0,0);
glVertex3f (0,0,-4);
glColor3ub (0,0,0);
glVertex3f (2,3,-4);
glVertex3f (2,3,0);
glEnd();


glBegin (GL_QUADS);
//kanan atas
glColor3ub (109,105,200);
glVertex3f (2,3,0);
glVertex3f (2,3,-4);
glColor3ub (0,0,0);
glVertex3f (0,6,-4);
glVertex3f (0,6,0);
glEnd();


glBegin (GL_QUADS);
//atas
glColor3ub (189,245,210);
glVertex3f (0,6,0);
glVertex3f (0,6,-4);
glColor3ub (0,0,0);
glVertex3f (-5,6,-4);
glVertex3f (-5,6,0);
glEnd();

glBegin (GL_QUADS);
//kiri atas
glColor3ub (109,105,200);
glVertex3f (-5,6,0);
glVertex3f (-5,6,-4);
glColor3ub (0,0,0);
glVertex3f (-7,3,-4);
glVertex3f (-7,3,0);
glEnd();

glBegin (GL_QUADS);
//kiri bawah
glColor3ub (223,105,200);
glVertex3f (-7,3,0);
glVertex3f (-7,3,-4);
glColor3ub (0,0,0);
glVertex3f (-5,0,-4);
glVertex3f (-5,0,0);
glEnd();

glBegin (GL_QUADS);
//bawah
glColor3ub (189,245,210);
glVertex3f (-5,0,0);
glVertex3f (-5,0,-4);
glColor3ub (0,0,0);
glVertex3f (0,0,-4);
glVertex3f (0,0,0);
glEnd();
sudut-=0.5;


OUTPUT

No comments:

Post a Comment