OpenGL >> Kunci Sok

#include <glut.h>
#include <math.h>

void cylinder(float alas,float atas,float tinggi);
void blok(float tebal,int ratiol,float ratiop);

GLfloat  source_light[]={0.30,0.30,0.30,0.50};
double Loop,LoopAll=0;
double all=0.005,sampngz=0,ataz=0,rotation_y_plus=-15,direction;
double panjangz=9,pendekz=4;
double a1=20,b1=-7,c1=-8,d1=-5,e1=1,f1=1,g1=30;
bool on=false;

void Kunci(void)
{
glClearColor(1.0,9.0,1.0,0.0);  //blackground
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50.0,1.5,10.0,1000.0);

glEnable (GL_DEPTH_TEST);
glPolygonMode   (GL_FRONT_AND_BACK,GL_FILL);
glEnable (GL_LIGHTING);
glLightfv (GL_LIGHT7,GL_DIFFUSE,source_light);
glEnable (GL_LIGHT7);
glEnable (GL_COLOR_MATERIAL);
glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT);

}

void display(void)
{

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

/*
Keterangan:
glTranslatef : coba nilainya diubah2 untuk menempatkan pada posisi yang tepat dengan sumbu (x, y, z)
glRotated : coba nilainya diubah2 untuk memutar objek agar sesuai dengan keinginan.
cylinder: untuk membentuk model tabung

*/

glTranslatef(0,0,-150);// besar kecilnya kunci

Loop+=all-0.005;
   glRotatef(Loop,50,4.0,0.6);//rotasi

glPushMatrix();//body
//glpushmatrix();

// glPopMatrix();


glColor3f(1.0,1.0,1.0);

glRotatef(120,ataz,1,sampngz); // Balok Panjang
glTranslatef(7, 0,-4);
blok(1, 4, 39);

glRotatef(130,50,1,0); // Balok Kiri
glTranslatef(0, -0.4,0.5);
blok(1, 4, 6);

glRotatef(0,1,7,0); // Balok Kanan
glTranslatef(-0.5, 30,-30.4);
blok(1, 4, 6);

glColor3f(1.0,1.0,1.0);//lubang mur Kanan
glRotatef(45,-270,10,30);
glTranslatef(0,3,-7);
cylinder(3, 3, 1);

glColor3f(1.0,1.0,1.0);//lubang mur Kiri
glRotatef(0,0,0,0);
glTranslatef(-3.7,-51.5,5);
cylinder(3, 3, 1);

glPopMatrix();


glFlush();
glutSwapBuffers();

}

void cylinder(float alas,float atas,float tinggi)
{
float i;
glPushMatrix();
glTranslatef(0.0,0.0,alas/0.523);
// glutSolidCone(alas,0,32,4);
for(i=0;i<=tinggi;i+=alas/8)
{
glTranslatef(0.0,0.0,alas/16);
glutSolidTorus(alas/4,alas-((i*(alas-atas))/tinggi),6,6);
}
glTranslatef(0.0,0.0,alas/4);
// glutSolidCone(atas,0,20,1);
glColor3f(1.,0.,0.);
glPopMatrix();
}

void blok(float tebal,int ratiol,float ratiop)
{
float i,j;
glPushMatrix();
for(i=0;i<ratiop;i++)
{
glTranslatef(-(ratiol+1)*tebal/2,0.0,0.0);
for(j=0;j<ratiol;j++)
{
glTranslatef(tebal,0.0,0.0);
glutSolidCube(tebal);
}
glTranslatef(-(ratiol-1)*tebal/2,0.0,tebal);
}
glPopMatrix();
}

void Mouse_s(int button, int state, int x, int y)
{
if(state==0 && button==0)
all++;
if(state==0 && button==2)
all--;
}

/*void keyboard_s(int key,int x,int y)
{
if(rotation_y_plus != 0)
direction=(rotation_y_plus/abs(rotation_y_plus));
else
direction=-1;

switch(key)
{
case GLUT_KEY_F1:
ataz++;
break;
case GLUT_KEY_F2:
ataz--;
break;
case GLUT_KEY_F3:
sampngz++;
break;
case GLUT_KEY_F4:
sampngz--;
break;
case GLUT_KEY_F5:
a1++;
break;
case GLUT_KEY_F6:
a1--;
break;
case GLUT_KEY_F7:
b1++;
break;
case GLUT_KEY_F8:
b1--;
break;
case GLUT_KEY_F9:
c1++;
break;
case GLUT_KEY_F10:
c1--;
break;
case GLUT_KEY_F11:
d1++;
break;
case GLUT_KEY_F12:
d1--;
break;
case GLUT_KEY_UP:
e1++;
break;
case GLUT_KEY_DOWN:
e1--;
break;
case GLUT_KEY_RIGHT:
f1++;
break;
case GLUT_KEY_LEFT:
f1--;
break;
case GLUT_KEY_PAGE_UP:
g1++;
break;
case GLUT_KEY_PAGE_DOWN:
g1--;
break;
}
}
*/

void tampil()
{
display();
}


int main(int argc,char **argv)
{


glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);//|GLUT_DEPTH);
glutInitWindowPosition(10,10);
glutInitWindowSize(1000,700);
glutCreateWindow("UAS >>> Kunci ShoocK");
glClearColor(0.5,0.5,0.0,0.0);
glutDisplayFunc(display);
gluOrtho2D(-320., 320., -240.0, 240.0);
glutIdleFunc(tampil);
//glutSpecialFunc(keyboard_s);
glutMouseFunc(Mouse_s); //Untuk menggerakkan
Kunci();
glutMainLoop();
return(0);
}

Berkomentar yang sopan ya, Terimakasih sahabat..
EmoticonEmoticon