Tampilan Output:
Kode Program:
/*
* Tanggal: Minggu, 04 November 2012 18:11:00
* Program Pesawat Terbang 2 Dimensi
* Dikembangkan Oleh Firmansyah Maulana
* Referensi: http://aliphoemarley.blogspot.com/2011/10/membuat-baling-baling-dengan-animasi-di.html
* Pada Tanggal 24 Oktober 2011 Oleh ALIVI NUR ROSIDA
*
*/
#include <GL/gl.h>
#include <GL/glut.h>
//Deklarasi Perputaran Pesawat
int x=0;
int z=0;
//Fungsi Membuat Pesawat
void pesawat()
{
glBegin(GL_LINES);
glColor3f (0.0, 0.0, 1.0);
//Senjata Pesawat Kiri 1
glVertex3f (0.40, 0.48, 0.0);
glVertex3f (0.40, 0.42, 0.0);
//Senjata Pesawat Kiri 2
glVertex3f (0.35, 0.46, 0.0);
glVertex3f (0.35, 0.40, 0.0);
//Senjata Pesawat Kiri 3
glVertex3f (0.30, 0.44, 0.0);
glVertex3f (0.30, 0.40, 0.0);
//Senjata Pesawat Kanan 1
glVertex3f (0.60, 0.48, 0.0);
glVertex3f (0.60, 0.42, 0.0);
//Senjata Pesawat Kanan 2
glVertex3f (0.65, 0.46, 0.0);
glVertex3f (0.65, 0.40, 0.0);
//Senjata Pesawat Kanan 3
glVertex3f (0.70, 0.44, 0.0);
glVertex3f (0.70, 0.40, 0.0);
glEnd();
glLineWidth(5);
glBegin(GL_POLYGON);
glColor3f (0.0, 1.0, 0.0);
//Kepala Pesawat
glVertex3f (0.50, 0.50, 0.00);
glVertex3f (0.47, 0.50, 0.00);
glVertex3f (0.47, 0.55, 0.00);
glVertex3f (0.50, 0.62, 0.00);
glVertex3f (0.53, 0.55, 0.00);
glVertex3f (0.53, 0.50, 0.00);
//Sayap Pesawat
glVertex3f (0.50, 0.50, 0.00);
glVertex3f (0.50, 0.42, 0.00);
glVertex3f (0.20, 0.38, 0.00);
glVertex3f (0.20, 0.40, 0.00);
glVertex3f (0.50, 0.45, 0.00);
glVertex3f (0.80, 0.40, 0.00);
glVertex3f (0.80, 0.38, 0.00);
glVertex3f (0.50, 0.42, 0.00);
//Badan Pesawat
glVertex3f (0.50, 0.50, 0.00);
glVertex3f (0.47, 0.55, 0.0);
glVertex3f (0.47, 0.33, 0.0);
glVertex3f (0.50, 0.35, 0.0);
glVertex3f (0.53, 0.33, 0.0);
glVertex3f (0.53, 0.55, 0.0);
glVertex3f (0.50, 0.45, 0.0);
//Sayap Pesawat Bawah
glVertex3f (0.50, 0.35, 0.00);
glVertex3f (0.50, 0.42, 0.00);
glVertex3f (0.40, 0.28, 0.00);
glVertex3f (0.40, 0.30, 0.00);
glVertex3f (0.50, 0.45, 0.00);
glVertex3f (0.60, 0.30, 0.00);
glVertex3f (0.60, 0.28, 0.00);
glVertex3f (0.50, 0.42, 0.00);
glEnd();
}
//Fungsi Tempat Menampilkan Pesawat
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glClearColor(0.0,1.1,1.1,1.1);
glShadeModel (GL_SMOOTH);
glColor3f (1.0, 1.0, 0.0);
//Ambil Fungsi Pesawat
pesawat();
glRotatef(x,0,0,45); //Untuk Membuat Rotasi Perputaran
glFlush ();
}
//Fungsi Keluar dengan Keyboard 'q'
void kunci(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
}
glutPostRedisplay();
}
//Fungsi Waktu Berputar
void timer (int value){
if (z <= 360){
x = 1;
z +=1;
}
glutPostRedisplay();
glutTimerFunc(15,timer,0);
}
//Fungsi Utama
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize(500,500); //Ukuran Layar Window
glutInitWindowPosition(100,100); //Posisi Window
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutCreateWindow("UTS | Animasi 2D - Firmansyah Maulana"); //Nama Judul Window
glutDisplayFunc(display); //Ambil Fungsi Tempat Menampilkan Pesawat
glutKeyboardFunc(kunci); //Ambil Fungsi Keluar dengan Keyboard 'q'
glutTimerFunc(1,timer,0); //Ambil Fungsi Waktu Berputar
glutMainLoop();
return 0;
}
Tidak ada komentar:
Posting Komentar