User talk:Cool0408


 * 1) include 
 * 2) include 
 * 3) include 

float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 90, angle = 0.0;//posisi

//lukis cube void cube (void) { float i;   for (i=0;i<50;i++) {   glTranslated(1, 0, 1); glPushMatrix; glutSolidCube(1); //lukis cube dengan sizenya glPopMatrix; } }

void init (void) { glEnable (GL_DEPTH_TEST); //buka depth testing glEnable (GL_LIGHTING); //buka lighting effect glEnable (GL_LIGHT0); //buka LIGHT0, our Diffuse Light glShadeModel (GL_SMOOTH); //smoothkan shader tu

}

void camera (void) { glRotatef(xrot,1.0,0.0,0.0); glRotatef(yrot,0.0,1.0,0.0); glTranslated(-xpos,-ypos,-zpos); //cube }

void display (void) { glClearColor (0.0,0.0,0.0,1.0); //tukar warna hitam glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //memadam buffer dan depth glLoadIdentity; gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //camera posisi, x,y,z camera; cube; //buka fungsi memanggil cube glutSwapBuffers; //tukar buffers angle++; //meningkatkan sudut }

void reshape (int w, int h) { glViewport (0, 0, (GLsizei)w, (GLsizei)h); //tukar viewport kepada window specifications glMatrixMode (GL_PROJECTION); //tukar matrix kepada projection

glLoadIdentity ; gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0); //tukar perspective (angle of sight, width, height,, depth) glMatrixMode (GL_MODELVIEW); //tukar jadi normal

}

void keyboard (unsigned char key, int x, int y) { if (key=='q') {   xrot += 1; if (xrot >360) xrot -= 360; }

if (key=='e') {   xrot -= 1; if (xrot < -360) xrot += 360; }

if (key=='w') {   float xrotrad, yrotrad; yrotrad = (yrot / 180 * 3.141592654f); xrotrad = (xrot / 180 * 3.141592654f); xpos += float(sin(yrotrad)) ; zpos -= float(cos(yrotrad)) ; ypos -= float(sin(xrotrad)) ; }

if (key=='s') {   float xrotrad, yrotrad; yrotrad = (yrot / 180 * 3.141592654f); xrotrad = (xrot / 180 * 3.141592654f); xpos -= float(sin(yrotrad)); zpos += float(cos(yrotrad)) ; ypos += float(sin(xrotrad)); }

if (key=='d') {   yrot += 1; if (yrot >360) yrot -= 360; }

if (key=='a') {   yrot -= 1; if (yrot < -360)yrot += 360; }   if (key==27) {   glutLeaveGameMode; //tukar resolution exit(0); //keluar program } }

int main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH); //tukar display kepada Double buffer, dengan depth glutGameModeString( "1024×768:32@75" ); //tukar full screen glutEnterGameMode; //tukar kepada fullscreen init ; //memanggil init fungsi glutDisplayFunc (display); //memanggil displayfunc glutIdleFunc (display); //kemaskini display glutReshapeFunc (reshape); //shape semula

glutKeyboardFunc (keyboard); //semak keyboard glutMainLoop ; //memanggil mainloop return 0; }