Tugas 2 Grafik Komputer Membuat Objek 3D Pyramid

Nama Kelompok:
1.    Arifin Dwi Cahya (51414618)
2.    Hary Rusman P.(54414830)
3.    Rayhan Arino (58414965)
4.    Rendy Ferryka H. (59414044)
5.    Yonanda Apriyandi (5C414454)
Kelas: 3 IA 12
Untuk minggu ini kita diberikan project membuat objek 3D dengan OpenGL menggunakan Dev C++ dan kelompok kami membuat objek 3D nya Pyramid, di bawah ini adalah kodingannya dan outpunya.
Listing Pemrograman:


/*
 * OGL02Animation.cpp: 3D Shapes with animation
 */
#include <GL/glut.h>  // GLUT, include glu.h and gl.h

/* Global variables */
char title[] = "3D Shapes with animation";
GLfloat anglePyramid = 0.0f;  // pemutaran sudut piramid
GLfloat angleCube = 0.0f;     // pemutaran sudut pangkat 3
int refreshMills = 15;        // jeda jarak waktu perdetik

/* Initialize OpenGL Graphics */
void initGL() {
   glClearColor(255.0f, 255.0f, 255.0f, 1.0f); //warna latar belakang hitam dan buram
   glClearDepth(1.0f);                   // Mengatur kedalaman latar belakang
   glEnable(GL_DEPTH_TEST);   // Memungkinkan pengujian mendalam untuk pemilihan koordinat z
   glDepthFunc(GL_LEQUAL);    // Mengatur jenis kedalaman test
   glShadeModel(GL_SMOOTH);   // pemodelan bayangan dengan halus
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // koreksi perspektif yang bagus
}

/* Handler for window-repaint event. Called back when the window first appears and
   whenever the window needs to be re-painted. */
void display() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // warna dan kedalaman buffer
   glMatrixMode(GL_MODELVIEW);     // Untuk beroperasi pada pemodelan matrix

   // Render a pyramid consists of 4 triangles
   glLoadIdentity();                  // Ulang model pengelihatan model
   glTranslatef(0.0f, 0.0f, -6.0f);  // Bergerak ke kiri dan ke layar
   glRotatef(anglePyramid, 1.0f, 1.0f, 0.0f);  // Memutar tentang (1,1,0) sumbu [NEW]
  
   glBegin(GL_POLYGON);
   // Alas
      glColor3f(0.0f, 255.0f, 255.0f);    
      glVertex3f( 1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f,  1.0f);
      glVertex3f( 1.0f, -1.0f,  1.0f);
     
  
   glEnd();   // selesai dari penggambaran piramid

  
   glBegin(GL_TRIANGLES);           // Mulailah menggambar piramida dengan 4 segitiga
      // Front
      glColor3f(1.0f, 0.0f, 0.0f);   
      glVertex3f( 0.0f, 1.0f, 0.0f);
      glVertex3f(-1.0f, -1.0f, 1.0f);
      glVertex3f(1.0f, -1.0f, 1.0f);

      // Right
      glColor3f(0.0f, 0.0f, 0.0f);   
      glVertex3f(0.0f, 1.0f, 0.0f);
      glVertex3f(1.0f, -1.0f, 1.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);

      // Back
      glColor3f(0.0f, 1.0f, 0.0f);   
      glVertex3f(0.0f, 1.0f, 0.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);

      // Left
      glColor3f(0.0f,0.0f,1.0f);     
      glVertex3f( 0.0f, 1.0f, 0.0f);
      glVertex3f(-1.0f,-1.0f,-1.0f);
      glVertex3f(-1.0f,-1.0f, 1.0f);
  
     
  
   glEnd();   // Selesai menggambar piramida

   glutSwapBuffers();  // Swap buffer bingkai depan dan belakang (double buffer)
   // Update the rotational angle after each refresh [NEW]
   anglePyramid += 1.2f;
   angleCube -= 0.15f;
}

/* Called back when timer expired [NEW] */
void timer(int value) {
   glutPostRedisplay();      // permintaan repaint posting untuk mengaktifkan display ()
   glutTimerFunc(refreshMills, timer, 0); // berikutnya waktu panggilan milidetik
}

/* Handler for window re-size event. Called back when the window first appears and
   whenever the window is re-sized with its new width and height */
void reshape(GLsizei width, GLsizei height) {  // GLsizei untuk integer non-negatif
   // Compute aspect ratio of the new window
   if (height == 0) height = 1;                // Untuk mencegah dibagi dengan 0
   GLfloat aspect = (GLfloat)width / (GLfloat)height;

   // Set the viewport to cover the new window
   glViewport(0, 0, width, height);

   // Set the aspect ratio of the clipping volume to match the viewport
   glMatrixMode(GL_PROJECTION);  // Untuk beroperasi pada matriks Proyeksi
   glLoadIdentity();             // ulang
   // Enable perspective projection with fovy, aspect, zNear and zFar
   gluPerspective(45.0f, aspect, 0.1f, 100.0f);
}

/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
   glutInit(&argc, argv);            // menginisialisasi GLUT
   glutInitDisplayMode(GLUT_DOUBLE); // Aktifkan mode buffered ganda
   glutInitWindowSize(640, 480);   // Mengatur jendela lebar awal & tinggi
   glutInitWindowPosition(50, 50); // Posisi jendela awal pojok kiri
   glutCreateWindow(title);          // Buat jendela dengan judul yang diberikan
   glutDisplayFunc(display);       // Menampilkan fungsi
   glutReshapeFunc(reshape);       // membentuk kembali jendela
   initGL();                       // inisialisasi OpenGL kita sendiri
   glutTimerFunc(0, timer, 0);     // timer panggilan langsung [NEW]
   glutMainLoop();    // proses pengulangan

   return 0;
}
 Output:

Share this:

CONVERSATION

0 komentar:

Posting Komentar