Pada postingan kali ini saya akan membahas tentang pembuatan program translate, scale dan rotate objek pada grafik komputer. langkah - langkahnya adalah kita harus memasukan code - code dibawah ini :
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
gluLookAt(0.0,0.0,10.0,0.0,0.0,0.0,0.0,10.0,0.0);
//glRotated(260,2,1,1);
//polygon depan
glBegin(GL_QUADS);
glColor3f(255,255,0);
glVertex3d(-1.0, -1.0, 1.0);
glVertex3d( 1.0, -1.0, 1.0);
glVertex3d( 1.0, 1.0, 1.0);
glVertex3d(-1.0, 1.0, 1.0);
glEnd();
//polygon belakang
glBegin(GL_QUADS);
glColor3f(255,0,0);
glVertex3d(-1.0, -1.0, -1.0);
glVertex3d( 1.0, -1.0, -1.0);
glVertex3d( 1.0, 1.0, -1.0);
glVertex3d(-1.0, 1.0, -1.0);
glEnd();
//polygon kanan
glBegin(GL_QUADS);
glColor3f(0,0,255);
glVertex3d( 1.0, -1.0, 1.0);
glVertex3d( 1.0, -1.0, -1.0);
glVertex3d( 1.0, 1.0, -1.0);
glVertex3d( 1.0, 1.0, 1.0);
glEnd();
//polygon kiri
glBegin(GL_QUADS);
glColor3f(0,0,255);
glVertex3d(-1.0, -1.0, 1.0);
glVertex3d(-1.0, -1.0, -1.0);
glVertex3d(-1.0, 1.0, -1.0);
glVertex3d(-1.0, 1.0, 1.0);
glEnd();
//polygon atas
glBegin(GL_QUADS);
glColor3f(0,255,0);
glVertex3d(-1.0, 1.0, 1.0);
glVertex3d( 1.0, 1.0, 1.0);
glVertex3d( 1.0, 1.0, -1.0);
glVertex3d(-1.0, 1.0, -1.0);
glEnd();
//polygon bawah
glBegin(GL_QUADS);
glColor3f(0,255,0);
glVertex3d(-1.0, -1.0, 1.0);
glVertex3d( 1.0, -1.0, 1.0);
glVertex3d( 1.0, -1.0, -1.0);
glVertex3d(-1.0, -1.0, -1.0);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0,255,0);
glVertex3d(-1.0,-1.0,1.0);
glVertex3d(-1.0,1.0,1.0);
glVertex3d(0.0,0.0,2.0);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0,0,255);
glVertex3d(-1.0,1.0,1.0);
glVertex3d(1.0,1.0,1.0);
glVertex3d(0.0,0.0,2.0);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0,255,0);
glVertex3d(1.0,1.0,1.0);
glVertex3d(1.0,-1.0,1.0);
glVertex3d(0.0,0.0,2.0);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0,0,255);
glVertex3d(1.0,-1.0,1.0);
glVertex3d(-1.0,-1.0,1.0);
glVertex3d(0.0,0.0,2.0);
glEnd();Outputnya sebagai berikut :
Gambar asli tampak dari atas
Gambar setelah dirotasi
0 komentar:
Posting Komentar