Membuat Baling-baling dengan openGL

Posted on Updated on


Untuk membuat baling-baling, kita sudah memasuki materi animasi. Dalam animasi kita hanya memainkan transformasi yang kita beri waktu.Di bawah ini contoh animasi baling-baling. Kita dapat menggunakan algoritma kita sendiri-sendiri.

dari gambar diatas source nya sbb :

//silahkan di coba semoga bermanfaat

#include "stdlib.h"
#include "gl/glut.h"

int x=0;
int z=0;
int z2=180;

void drawQuad1() {
glBegin (GL_POLYGON);
glColor3f(0,1,1);
glVertex2i(0,0);
glVertex2i(-50,125);
glVertex2i(50,125);
glVertex2i(0,0);
glVertex2i(-50,-125);
glVertex2i(50,-125);
glEnd();
}

void renderScene(void){
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1,1,1,1);
glRotatef(x,0,0,1);
drawQuad1();
glFlush();
}

void timer (int value){
if (z <= 360){
x = 1;
z +=1;
}
if (z > 360){
x = -1;
z2 -=1;
}
if (z2 < 0) {
x = 1;
z = 0;
z2 = 360;
}
glutPostRedisplay();
glutTimerFunc(5,timer,0);
}

void main(int argc, char **argv){
glutInit(&argc, argv);
glutInitWindowPosition (100,100);
glutInitWindowSize (300,300);
glutCreateWindow ("BALING-BALING");
gluOrtho2D(-200.0,200.0,-200.0,200.0);
glutDisplayFunc(renderScene);
glutTimerFunc(1,timer,0);
glutMainLoop();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s