Wednesday, 20 March 2019

OpenGL Projek " Tatasurya " dengan Codeblock C++

Projek Tatasurya dengan openGL ini banyak sekali fitur yang ada didalamnya diantaranya adalah bulan, bintang, komet, planet dan matahari. bulan bisa kerlap-kerlip dan komet bisa melintas dan masih banyak fiture yang lainnya. projek ini juga bagus untuk pembelajaran mengenai pemrograman openGL yang ada dikampus-kampus. untuk melihat hasil projeknya anda dapat melihatnya pada video berikut ini.


Namun untuk mencoba projek diatas anda harus mempunyai beberapa hal berikut ini untuk di seting dikomputer anda. diantaranya yaitu :
  1. Open GL download disini :  View openGL
  2. CodeBlock setting dengan openGL caranya lihat disini: view
  3. buka codeblock dan buat projek baru caranya dapat dilihat disini : view
  4. copy semua sourcode yang tersedia di blog ini.
silahkan copy contoh program dibawah ini ke projek yang anda buat. adapun sourcode yang akan anda coba adalah sebagai berikut.

Code Program

#include<stdio.h>
#include<stdlib.h>
#include<GL/glut.h>
#include<math.h>
static int m=0,M=0,v=0,V=0,E=0,e=0,r=0,R=0,j=0,J=0,s=0,S=0,U=0,u=0,n=0,N=0,X=0,z=0,B=0,b=0,c=0;
static GLint axis=2;
GLfloat diffuseMaterial[4]={0.5,0.5,0.5,1.0};
/*initialize material property,light soure,lighting model,and depth buffer*/

void myinit(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat light_position[]={1.0,1.0,1.0,0.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuseMaterial);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialf(GL_FRONT,GL_SHININESS,25.0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glColorMaterial(GL_FRONT,GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
}
void display(void)
{
GLfloat position[]={0.0,0.0,1.5,1.0};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,0.5,0.0);
glPushMatrix();
glRotatef((GLfloat)z,1.0,1.0,1.0);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glDisable(GL_LIGHTING);
glutSolidSphere(0.8,40,16);   /*draw sun*/
glPopMatrix();

glPushMatrix();
glLightfv(GL_LIGHT0,GL_POSITION,position);
glDisable(GL_LIGHTING);
glEnable(GL_LIGHTING);
glColor3f(1.5,0.5,0.0);
glutSolidTorus(0.2,0.9,6,20);
glPopMatrix();

glPushMatrix();
glRotatef((GLfloat)M,0.0,1.0,0.0);
glTranslatef(1.5,0.0,0.0);
glRotatef((GLfloat)m,0.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
glutSolidSphere(0.2,20,8);  /*draw smaller planet mercury*/
glPopMatrix();

glPushMatrix();
glRotatef((GLfloat)V,0.0,1.0,0.0);
glTranslatef(2.0,0.0,1.0);
glRotatef((GLfloat)v,0.0,1.0,0.0);
glColor3f(7.5,9.5,1.0);
glutSolidSphere(0.2,20,8);   /*draw smaller plant venus*/
glPopMatrix();

glPushMatrix();
glRotatef((GLfloat)E,0.0,1.0,0.0);
glTranslatef(3.5,0.0,0.0);
glRotatef((GLfloat)e,0.0,1.0,0.0);
glColor3f(0.1,6.5,2.0);
glutSolidSphere(0.2,20,8);    /*draw smaller plant earth*/
glRotatef((GLfloat)X,0.0,1.0,0.0);
glTranslatef(0.3,0.2,0.0);
glColor3f(4.3,3.5,8.0);
glutSolidSphere(0.1,20,14);   /*draw moon*/
glPopMatrix();

glPushMatrix();
glRotatef((GLfloat)R,0.0,1.0,0.0);
glTranslatef(5.0,0.0,3.0);
glRotatef((GLfloat)r,0.0,1.0,0.0);
glColor3f(1.0,0.2,0.0);
glutSolidSphere(0.2,20,8);   /*draw smaller planet mars*/
glPopMatrix();

glPushMatrix();
glRotatef((GLfloat)J,0.0,1.0,0.0);
glTranslatef(-2.5,0.0,1.0);
glRotatef((GLfloat)j,0.0,1.0,0.0);
glColor3f(0.9,0.7,0.3);
glutSolidSphere(0.2,20,8);/*draw smaller planet Jupiter*/
glPopMatrix();

glPushMatrix();
glRotatef((GLfloat)S,0.0,1.0,0.0);
glTranslatef(-5.0,0.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)s,0.0,0.0,5.0);
glColor3f(4.5,0.5,0.0);
glutSolidSphere(0.5,20,16);  /*draw smaller plant Saturn*/
int i=0;
glBegin(GL_QUAD_STRIP);
for(i=0;i<=360;i++)
{
glVertex3f(sin(i*3.1416/180)*0.5,cos(i*3.1416/180)*0.5,0);
glVertex3f(sin(i*3.1416/180)*0.7,cos(i*3.1416/180)*0.7,0);
}
glEnd();
glPopMatrix();

glPushMatrix();
glRotatef ((GLfloat) U, 0.0, 1.0,0.0);
glTranslatef (-6.5, 0.0, 0.0);
gluLookAt (10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 1.0);
glRotatef((GLfloat) u, 0.0, 0.0, 5.0);
glColor3f( 1.2, 0.6,0.2);
glutSolidSphere (0.5, 20, 16); /* draw smaller planet Uranus*/
glBegin(GL_QUAD_STRIP);
for(i=0; i<=360; i++)
{
glVertex3f(sin(i*3.1416/180)*0.5,cos(i*3.1416/180)*0.5, 0);
glVertex3f(sin(i*3.1416/180)*0.7, cos(i*3.1416/180)*0.7,0);
}
glEnd();
glPopMatrix();


glPushMatrix();
glRotatef ((GLfloat) N,0.0, 1.0, 0.0);
glTranslatef (-8.0, 0.0, 0.0);
glRotatef ((GLfloat) n, 0.0, 1.0, 0.0);
glColor3f(1.0, 2.0, 0.0);
glutSolidSphere(0.4, 20, 8);
glPopMatrix();/* draw smaller planet Neptune */

glPushMatrix();
glRotatef ((GLfloat) c, 6.0, -14.0,-6.0);
glTranslatef (5.0,3.0,-1.0);
glScalef(0.60,0.0,2.5);
glColor3f (7.5, 9.5, 2.0);
glutSolidSphere (0.2, 12, 6);
glPopMatrix();/*draw comet*/
//to put the stars as a background
glPushMatrix();
glTranslatef(0.0,-2.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,2.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,-4.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,4.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,-6.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,6.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();


glPushMatrix();
glTranslatef(0.0,-8.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();




glPushMatrix();
glTranslatef(0.0,8.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();


glPushMatrix();
glTranslatef(8.0,0.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();
glPushMatrix();
glTranslatef(-8.0,-2.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(6.0,4.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-6.0,4.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(5.0,-4.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-7.0,3.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

 glPushMatrix();
glTranslatef(-7.0,2.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(7.0,-2.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(7.0,-3.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-7.0,-3.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(7.0,2.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(1.0,-7.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(2.0,-5.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,3.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(5.0,-1.0,0.0);
gluLookAt(0.0,10.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.07,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-6.0,7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.07,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-0.5,3.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.07,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-1.5,4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.07,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-9.0,3.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.07,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(9.0,-5.9,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(6.5,8.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(5.0,7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-9.0,6.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.1,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-10.5,9.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.07,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-11.0,-7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.07,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-11.0,5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-7.0,-5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-10.0,3.7,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-7.0,-2.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-8.0,5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.03,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-8.0,-5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();
glPushMatrix();
glTranslatef(-11.0,-4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(6.0,-5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-6.9,7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(5.0,-4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(6.0,4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(3.0,-4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(4.0,-7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat) b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-4.0,-3.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

  glPushMatrix();
glTranslatef(4.0,-7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
     glTranslatef(11.0,-4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
  glTranslatef(9.0,-9.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
  glTranslatef(8.0,-4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
  glTranslatef(9.0,5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef (7.0,7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.9,7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(1.0,6.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.8,-5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(3.0,-7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(1.0,5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(2.0,4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-9.0,0.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-10.0,4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(9.0,3.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-10.0,-6.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(10.0,0.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-9.0,-7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-3.0,4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-9.9,-7.5,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(1.0,5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(3.0,6.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-2.0,-5.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-3.0,-2.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-4.0,-8.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(8.3,-7.1,0.0);
gluLookAt (0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-10.0,7.6,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-3.0,7.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-1.4,7.5,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(3.0,6.5,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-6.0,4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(-6.0,-6.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.05,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.7,4.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(2.0,2.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,0.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0,-1.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
 glTranslatef(0.0,1.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
 glTranslatef(0.0,2.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,0.0,0.0,0.0);
glScalef(200.0,0.0,0.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();

glPushMatrix();
glTranslatef(8.7,9.0,0.0);
gluLookAt(0.0,10.0,2.0,1.0,0.0,0.0,0.0,0.0,1.0);
glRotatef((GLfloat)b,1.0,7.0,5.0);
glColor3f(4.3,3.5,1.0);
glutSolidSphere(0.04,20,8);
glPopMatrix();
glutSwapBuffers();
}

void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'z':z=(z+50)%360;
   glutPostRedisplay();
   break;
case 'm':m=(m+3)%360;
   glutPostRedisplay();
   break;
case 'M':M=(M+12)%360;
   glutPostRedisplay();
   break;
case 'v':v=(v+2)%360;
   glutPostRedisplay();
   break;
case 'V':V=(V+10)%360;
   glutPostRedisplay();
   break;
case 'e':e=(e+5)%360;
   glutPostRedisplay();
   break;
case 'E':E=(E+8)%360;
   glutPostRedisplay();
         break;
case 'r':r=(r+6)%360;
   glutPostRedisplay();
   break;
case 'R':R=(R+6)%360;
   glutPostRedisplay();
   break;
case 'j':j=(j+10)%360;
   glutPostRedisplay();
   break;
case 'J':J=(J+4)%360;
   glutPostRedisplay();
         break;
case 's':s=(s+9)%360;
   glutPostRedisplay();
         break;
case 'S':S=(S+3)%360;
   glutPostRedisplay();
         break;
case 'u':u=(u+8)%360;
   glutPostRedisplay();
   break;
case 'U':U=(U+2)%360;
   glutPostRedisplay();
   break;
case 'n':n=(n+7)%360;
   glutPostRedisplay();
   break;
case 'N':N=(N+1)%360;
   glutPostRedisplay();
   break;
case 'b':b=(b+10)%360;
   glutPostRedisplay();
   break;
case 'c':c=(c+1)%360;
   b=(b+10)%360;
   glutPostRedisplay();
   break;
case 'X':X=(X+5)%360;
   glutPostRedisplay();
   break;
case 'a':z=(z+50)%360;
   b=(b+10)%360;
   m=(m+3)%360;
   v=(v+2)%360;
   e=(e+5)%360;
   r=(r+6)%360;
   j=(j+10)%360;
   s=(s+9)%360;
   u=(u+8)%360;
   n=(n+7)%360;
   c=(c+1)%360;
   glutPostRedisplay();
   break;
case 'A':z=(z+50)%360;
   b=(b+10)%360;
   M=(M+12)%360;
   V=(V+10)%360;
   E=(E+8)%360;
   R=(R+6)%360;
   J=(J+4)%360;
   S=(S+3)%360;
   U=(U+2)%360;
   N=(N+1)%360;
   c=(c+1)%360;
         glutPostRedisplay();
   break;
case 'B':z=(z+50)%360;
   b=(b+10)%360;
   c=(c+1)%360;
   m=(m+3)%360;M=(M+12)%360;
   v=(v+2)%360;V=(V+10)%360;
   e=(e+5)%360;E=(E+8)%360;
   r=(r+6)%360;R=(R+6)%360;
         j=(j+10)%360;J=(J+4)%360;
         s=(s+9)%360;S=(S+3)%360;
         u=(u+8)%360;U=(U+2)%360;
   n=(n+7)%360;N=(N+1)%360;
   glutPostRedisplay();
     break;
case 27:exit(0);
  break;
default:break;
}
}

void mouse(int btn ,int state,int x,int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
z=(z+50)%360;
b=(b+10)%360;
c=(c+1)%360;
m=(m+3)%360;M=(M+12)%360;
v=(v+2)%360;V=(V+10)%360;
e=(e+5)%360;E=(E+8)%360;
r=(r+6)%360;R=(R+6)%360;
j=(j+10)%360;J=(J+4)%360;
s=(s+9)%360;S=(S+3)%360;
u=(u+8)%360;U=(U+2)%360;
n=(n+7)%360;N=(N+1)%360;
glutPostRedisplay();
}
if(btn==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
{
z=(z+50)%360;
b=(b+10)%360;
c=(c+1)%360;
m=(m+3)%360;M=(M+12)%360;
v=(v-2)%360;V=(V-10)%360;
e=(e+5)%360;E=(E+8)%360;
r=(r-6)%360;R=(R-6)%360;
j=(j+10)%360;J=(J+4)%360;
s=(s-9)%360;S=(S-3)%360;
u=(u+8)%360;U=(U+2)%360;
n=(n-7)%360;N=(N-1)%360;
glutPostRedisplay();
}
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
{
z=(z-50)%360;
b=(b-10)%360;
c=(c+1)%360;
m=(m-3)%360;M=(M-12)%360;
v=(v-2)%360;V=(V-10)%360;
e=(e-5)%360;E=(E-8)%360;
r=(r-6)%360;R=(R-6)%360;
j=(j-10)%360;J=(J-4)%360;
s=(s-9)%360;S=(S-3)%360;
u=(u-8)%360;U=(U-2)%360;
n=(n-7)%360;N=(N-1)%360;
glutPostRedisplay();
}
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Tatasurya");
myinit();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}



Features
didalam projek ini akan ada beberapa desain diantaranya adalah:

  • Komet : komet akan melintasi galaksi bersama bintang-bintang yang berkerlap-kerlip.
  • Bintang : bintang akan kerlap kerlip diangkasa
  • Matahari : matahari adalah pusat dari tatasurya.
  • Pelanet : ada banyak pelanet yang tersedia dinataranya adalah bumi, markurius, venus dll.
Event Control pada Animasi OpenGL
untuk menjalankan animasi berikut ini adalah beberapa panduannya yang bisa anda gunakan.
  • klik kanan digunakan untuk merotasi semua pelanet ke arah kanan.
  • klik kiri digunakan untuk merotasi semua pelanet ke arah kiri.
  • keyboard "b" digunakan untuk membuat bintang berkerlap-kerlip.
  • keyboard "c" digunakan untuk menjalankan komet dengan bintang berkerlap-kerlip.
  • keyboard "m" digunakan untuk memutar ditempat pada planet mars (planet Merah).
  • keyboard "M" digunakan untuk memutar pelanet mars( planet Merah) mengelilingi matahari.
  • keyboard "v" digunakan untuk memutar ditempat pelanet Venus (planet Kuning).
  • keyboard "V" digunakan untuk memutar pelanet venus mengelilingi matahari (planet kuning).
  • keyboard "e" digunakan untuk memutar ditempat pelanet bumi (planet biru laut).
  • keyboard "r" digunakan untuk memutar ditempat planet pluto
  • keyboard "R" digunakan untuk memutar planet Pluto mengelilingi matahari.
  • keyboard "j" digunakan untuk memutar ditempat planet jupiter (planet coklat).
  • keyboard "J" digunakan untuk memutar planet jupiter mengelilingi matahari.
  • keyboard "s" digunakan untuk memutar ditempat planet saturnus.
  • keyboard "S" digunakan untuk memutar planet saturnus mengelilingi matahari.
  • keyboard "u" memutar ditempat planet uranus.
  • keyboard "U" digunakan untuk memutar planet uranus mengelilingi matahari.
  • keyboard "n" digunakan untuk memutar planet neptunus ditempat.
  • keyboard "N" digunakan untuk memutar planet neptunus mengelilingi matahari.
  • kyboard "X" digunakan untuk memutar bulan mengelilingi bumi.
Adapun hasil screen shoot animasi ini dapat anda lihat pada gambar dibawah ini :



Demikian Projek yang dapat Saya Share buat yang membutuhkan untuk bahan pembelajaran dan menyelesaikan tugas kuliah. semoga bermanfaat dan dapat dimanfaatkan dengan sebaik-bainya. terimakasih sudah berkunjung dan nyasar dimari.


Daftar Pustaka

https://cglabprojects.blogspot.com/2014/02/celestial-observatory.html

 

Contoh Projek 3D lainnya.


Baca Juga Projek OpenGL dengan C++ Lainnya  dibawah ini :


 Contoh Projek 2D openGL

Baca juga Animasi 2D untuk projek openGL lainnya dibawah ini


Dasar OpenGL

Baca juga Dasar Dari OpenGL dibawah ini jika kalian ingin menekuninya.




Monday, 18 March 2019

mini projek OpenGL "Parkiran Mobil" dengan Codeblock C++

     Projek paakan anda buat kali ini adalah membuat sebuah parkiran mobil dengan OpenGL CodeBlock C++. dalam projek ini anda akan berinteraksi dengan tampilan yaitu menambahkan rumah untuk parkiran , kemudian melihat view dari kiri ke kanan, maju mundur view serta anda juga dapat melihat posisi parkiran baik dari posisi atas maupun samping kanan dan kiri. adapun hasil yang akan anda dapatkan dapat dilihat dalam video berikut ini :

Namun untuk mencoba projek diatas anda harus mempunyai beberapa hal berikut ini untuk di seting dikomputer anda. diantaranya yaitu :
  1. Open GL download disini :  View openGL
  2. CodeBlock setting dengan openGL caranya lihat disini: view
  3. buka codeblock dan buat projek baru caranya dapat dilihat disini : view
  4. copy semua sourcode yang tersedia di blog ini.
silahkan copy contoh program dibawah ini ke projek yang anda buat. adapun sourcode yang akan anda coba adalah sebagai berikut.

Code Program

/*
 *
 *  Created on: Feb 21, 2014
 *      Author: kamath
 */
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>

static float angle=0.0,ratio;
static float x=0.0f,y=1.75f,z=5.0f;
static float lx=0.10f,ly=0.10f,lz=-1.0f;
static GLint carr_display_list,house_display_list;
float theta=0.01,fxincr=0.1,fzincr=0,temp,theta1,fx=-10,fz=80;
int xxxx=0,yyyy=0,kk=0,housevisible=0,movecarvar=0;
int a[36]={55,97,44,152,55,171,108,86,168,99,147,207,238,55,233,167,105,80,134,29,253,130,32,240,110,199,224,121,93,199,180,61,110,251,77,237};
int b[36]={102,194,110,152,153,184,137,113,55,138,104,43,240,255,203,8,100,53,88,64,127,64,87,5,2,144,211,128,10,89,27,11,175,185,157,241};
int c[36]={159,243,133,253,233,228,141,18,46,195,75,52,253,204,169,30,78,94,68,117,4,2,33,12,2,25,195,76,26,54,98,103,205,173,65,242};


void changeSize(int w, int h)
{

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
ratio = 1.0f * w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Set the viewport to be the entire window
    glViewport(0, 0, w, h);

// Set the clipping volume
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(x, y, z,
      x + lx,y + ly,z + lz,
  0.0f,1.0f,0.0f);


}


void drawcarr()
{

glTranslatef(.0,0.8,0.0);
glEnable(GL_BLEND);//TRANCPARENCY1
glBlendFunc(GL_ONE, GL_ZERO);//TRANCPARENCY2
   //glColor3f(1.0,1.0,1.0);
  // glBegin(
   //glVertex3f(

glBegin(GL_LINE_LOOP);
glVertex3f(-1.12,-.48,0.7);//a
glVertex3f(-0.86,-.48,0.7);//b
glVertex3f(-.74,-0.2,0.7);//c
glVertex3f(-.42,-.2,0.7);//d
glVertex3f(-0.3,-.48,0.7);//e
glVertex3f(.81,-0.48,0.7);//f
glVertex3f(.94,-0.2,0.7);//g
glVertex3f(1.24,-.2,0.7);//h
glVertex3f(1.38,-.48,0.7);//i
glVertex3f(1.52,-.44,0.7);//j
glVertex3f(1.52,.14,0.7);//k
glVertex3f(1.14,0.22,0.7);//l
glVertex3f(0.76,.22,0.7);//m
glVertex3f(.52,0.56,0.7);//n
glVertex3f(-0.1,0.6,0.7);//0
glVertex3f(-1.02,0.6,0.7);//p
glVertex3f(-1.2,0.22,0.7);//q
glVertex3f(-1.2,-.28,0.7);//r
 glEnd();

glBegin(GL_LINE_LOOP);
glVertex3f(-1.12,-.48,-0.7);//a'
glVertex3f(-0.86,-.48,-0.7);//b'
glVertex3f(-.74,-0.2,-0.7);//c'
glVertex3f(-.42,-.2,-0.7);//d'
glVertex3f(-0.3,-.48,-0.7);//e'
glVertex3f(.81,-0.48,-0.7);//f'
glVertex3f(.94,-0.2,-0.7);//g'
glVertex3f(1.24,-.2,-0.7);//h'
glVertex3f(1.38,-.48,-0.7);//i'
glVertex3f(1.52,-.44,-0.7);//j'
glVertex3f(1.52,.14,-0.7);//k'
glVertex3f(1.14,0.22,-0.7);//l'
glVertex3f(0.76,.22,-0.7);//m'
glVertex3f(.52,0.56,-0.7);//n'
glVertex3f(-0.1,0.6,-0.7);//o'
glVertex3f(-1.02,0.6,-0.7);//p'
glVertex3f(-1.2,0.22,-0.7);//q'
glVertex3f(-1.2,-.28,-0.7);//r'
 glEnd();

glBegin(GL_LINES);
glVertex3f(-1.12,-.48,0.7);//a
glVertex3f(-1.12,-.48,-0.7);//a'
glVertex3f(-0.86,-.48,0.7);//b
glVertex3f(-0.86,-.48,-0.7);//b'
glVertex3f(-.74,-0.2,0.7);//c
glVertex3f(-.74,-0.2,-0.7);//c'
glVertex3f(-.42,-.2,0.7);//d
glVertex3f(-.42,-.2,-0.7);//d'
glVertex3f(-0.3,-.48,0.7);//e
glVertex3f(-0.3,-.48,-0.7);//e'
glVertex3f(.81,-0.48,0.7);//f
glVertex3f(.81,-0.48,-0.7);//f'
glVertex3f(.94,-0.2,0.7);//g
glVertex3f(.94,-0.2,-0.7);//g'
glVertex3f(1.24,-.2,0.7);//h
glVertex3f(1.24,-.2,-0.7);//h'
glVertex3f(1.38,-.48,0.7);//i
glVertex3f(1.38,-.48,-0.7);//i'
glVertex3f(1.52,-.44,0.7);//j
glVertex3f(1.52,-.44,-0.7);//j'
glVertex3f(1.52,.14,0.7);//k
glVertex3f(1.52,.14,-0.7);//k'
glVertex3f(1.14,0.22,0.7);//l
glVertex3f(1.14,0.22,-0.7);//l'
glVertex3f(0.76,.22,0.7);//m
glVertex3f(0.76,.22,-0.7);//m'
glVertex3f(.52,0.56,0.7);//n
glVertex3f(.52,0.56,-0.7);//n'
glVertex3f(-0.1,0.6,0.7);//0
glVertex3f(-0.1,0.6,-0.7);//o'
glVertex3f(-1.02,0.6,0.7);//p
glVertex3f(-1.02,0.6,-0.7);//p'
glVertex3f(-1.2,0.22,0.7);//q
glVertex3f(-1.2,0.22,-0.7);//q'
glVertex3f(-1.2,-.28,0.7);//r
glVertex3f(-1.2,-.28,-0.7);//r'
glEnd();


// top filling
glBegin(GL_POLYGON);
glVertex3f(-0.1,0.6,0.7);//o
glVertex3f(-0.1,0.6,-0.7);//o'
glVertex3f(-1.02,0.6,-0.7);//p'
glVertex3f(-1.02,0.6,0.7);//p
glEnd();


glBegin(GL_POLYGON);
glVertex3f(-0.1,0.6,0.7);//o
glVertex3f(-0.1,0.6,-0.7);//o'
glVertex3f(.52,0.56,-0.7);//n'
glVertex3f(.52,0.56,0.7);//n
glEnd();

//back filling
glBegin(GL_POLYGON);
glVertex3f(-1.2,0.22,0.7);//q
glVertex3f(-1.2,0.22,-0.7);//q'
glVertex3f(-1.2,-.28,-0.7);//r'
glVertex3f(-1.2,-.28,0.7);//r
glEnd();






glBegin(GL_POLYGON);
glVertex3f(1.52,.14,0.7);//k
glVertex3f(1.14,0.22,0.7);//l
glVertex3f(1.14,0.22,-0.7);//l'
glVertex3f(1.52,.14,-0.7);//k'
glEnd();

glBegin(GL_POLYGON);
glVertex3f(0.76,.22,0.7);//m
glVertex3f(0.76,.22,-0.7);//m'
glVertex3f(1.14,0.22,-0.7);//l'
glVertex3f(1.14,0.22,0.7);//l
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-1.12,-.48,0.7);//a
glVertex3f(-0.86,-.48,0.7);//b
glVertex3f(-.74,-0.2,0.7);//c
glVertex3f(-0.64,0.22,0.7);//cc
glVertex3f(-1.08,0.22,0.7);//dd
glVertex3f(-1.2,0.22,0.7);//q
glVertex3f(-1.2,-.28,0.7);//r
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-.74,-0.2,0.7);//c
glVertex3f(-0.64,0.22,0.7);//cc
glVertex3f(-0.5,0.22,0.7);//hh
glVertex3f(-0.5,-0.2,0.7);//pp
glEnd();
glBegin(GL_POLYGON);
glVertex3f(0.0,0.22,0.7);//gg
glVertex3f(1.14,0.22,0.7);//l
glVertex3f(1.24,-.2,0.7);//h
glVertex3f(0.0,-0.2,0.7);//oo



glEnd();
//
glBegin(GL_POLYGON);

glVertex3f(-1.12,-.48,-0.7);//a'
glVertex3f(-0.86,-.48,-0.7);//b'
glVertex3f(-.74,-0.2,-0.7);//c'
glVertex3f(-0.64,0.22,-0.7);//cc'
glVertex3f(-1.08,0.22,-0.7);//dd'
glVertex3f(-1.2,0.22,-0.7);//q'
glVertex3f(-1.2,-.28,-0.7);//r'
glEnd();

glBegin(GL_POLYGON);

glVertex3f(-.74,-0.2,-0.7);//c'
glVertex3f(-0.64,0.22,-0.7);//cc'
glVertex3f(-0.5,0.22,-0.7);//hh'
glVertex3f(-0.5,-0.2,-0.7);//pp'

glEnd();
glBegin(GL_POLYGON);
glVertex3f(0.0,0.22,-0.7);//gg'
glVertex3f(1.14,0.22,-0.7);//l'
glVertex3f(1.24,-.2,-0.7);//h'
glVertex3f(0.0,-0.2,-0.7);//oo'

glEnd();


glBegin(GL_POLYGON);
glVertex3f(-1.2,0.22,0.7);//q
glVertex3f(-1.08,0.22,0.7);//dd
glVertex3f(-0.98,0.5,0.7);//aa
glVertex3f(-1.02,0.6,0.7);//p
glEnd();


glBegin(GL_POLYGON);
glVertex3f(-1.02,0.6,0.7);//p
glVertex3f(-0.98,0.5,0.7);//aa
glVertex3f(0.44,0.5,0.7);//jj
glVertex3f(.52,0.56,0.7);//n
glVertex3f(-0.1,0.6,0.7);//0
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-0.64,0.5,0.7);//bb
glVertex3f(-0.64,0.22,0.7);//cc
glVertex3f(-0.5,0.22,0.7);//hh
glVertex3f(-0.5,0.5,0.7);//ee
glEnd();

glBegin(GL_POLYGON);
glVertex3f(0.0,0.5,0.7);//ff
glVertex3f(0.0,0.22,0.7);//gg
glVertex3f(0.12,0.22,0.7);//ll
glVertex3f(0.12,0.5,0.7);//ii
glEnd();

glBegin(GL_POLYGON);
glVertex3f(.52,0.56,0.7);//n
glVertex3f(0.44,0.5,0.7);//jj
glVertex3f(0.62,0.22,0.7);//kk
glVertex3f(0.76,.22,0.7);//m
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-.42,-.2,0.7);//d
glVertex3f(.94,-0.2,0.7);//g
glVertex3f(.81,-0.48,0.7);//f
glVertex3f(-0.3,-.48,0.7);//e
glEnd();

glBegin(GL_POLYGON);
glVertex3f(1.14,0.22,0.7);//l
glVertex3f(1.52,.14,0.7);//k
glVertex3f(1.52,-.44,0.7);//j
glVertex3f(1.38,-.48,0.7);//i
glVertex3f(1.24,-.2,0.7);//h
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-1.2,0.22,-0.7);//q'
glVertex3f(-1.08,0.22,-0.7);//dd'
glVertex3f(-0.98,0.5,-0.7);//aa'
glVertex3f(-1.02,0.6,-0.7);//p'
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-1.02,0.6,-0.7);//p'
glVertex3f(-0.98,0.5,-0.7);//aa'
glVertex3f(0.44,0.5,-0.7);//jj'
glVertex3f(.52,0.56,-0.7);//n'
glVertex3f(-0.1,0.6,-0.7);//0'
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-0.64,0.5,-0.7);//bb'
glVertex3f(-0.64,0.22,-0.7);//cc'
glVertex3f(-0.5,0.22,-0.7);//hh'
glVertex3f(-0.5,0.5,-0.7);//ee'
glEnd();

glBegin(GL_POLYGON);
glVertex3f(0.0,0.5,-0.7);//ff'
glVertex3f(0.0,0.22,-0.7);//gg'
glVertex3f(0.12,0.22,-0.7);//ll'
glVertex3f(0.12,0.5,-0.7);//ii'
glEnd();

glBegin(GL_POLYGON);
glVertex3f(.52,0.56,-0.7);//n'
glVertex3f(0.44,0.5,-0.7);//jj'
glVertex3f(0.62,0.22,-0.7);//kk'
glVertex3f(0.76,.22,-0.7);//m'
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-.42,-.2,-0.7);//d'
glVertex3f(.94,-0.2,-0.7);//g'
glVertex3f(.81,-0.48,-0.7);//f'
glVertex3f(-0.3,-.48,-0.7);//e'
glEnd();

glBegin(GL_POLYGON);
glVertex3f(1.14,0.22,-0.7);//l'
glVertex3f(1.52,.14,-0.7);//k'
glVertex3f(1.52,-.44,-0.7);//j'
glVertex3f(1.38,-.48,-0.7);//i'
glVertex3f(1.24,-.2,-0.7);//h'
glEnd();


// door1 body- rear, near
glBegin(GL_POLYGON);
glVertex3f(-0.5,0.22,0.7);//hh
glVertex3f(0.0,0.22,0.7);//gg
glVertex3f(0.0,-0.2,0.7);//oo
glVertex3f(-0.5,-0.2,0.7);//pp
glEnd();

// door body- rear, far
glBegin(GL_POLYGON);
glVertex3f(-0.5,0.22,-0.7);//hh'
glVertex3f(0.0,0.22,-0.7);//gg'
glVertex3f(0.0,-0.2,-0.7);//oo'
glVertex3f(-0.5,-0.2,-0.7);//pp'
glEnd();

// door2  body- near, driver

glBegin(GL_POLYGON);
glVertex3f(0.12,0.22,0.7);//ll
glVertex3f(0.62,0.22,0.7);//kk
glVertex3f(0.62,-0.2,0.7);//mm
glVertex3f(0.12,-0.2,0.7);//nn
glEnd();



// door2  body- far, driver

glBegin(GL_POLYGON);
 glVertex3f(0.12,0.22,-0.7);//ll'
glVertex3f(0.62,0.22,-0.7);//kk'
glVertex3f(0.62,-0.2,-0.7);//mm'
glVertex3f(0.12,-0.2,-0.7);//nn'
glEnd();

glBegin(GL_POLYGON);//front**
glVertex3f(1.52,.14,0.7);//k
glVertex3f(1.52,.14,-0.7);//k'
glVertex3f(1.52,-.44,-0.7);//j'
glVertex3f(1.52,-.44,0.7);//j
glEnd();

glTranslatef(-.58,-.52,0.7);//translate to 1st tyre
glColor3f(0.09,0.09,0.09);// tyre color********
glutSolidTorus(0.12f, .14f, 10, 25);
glTranslatef(1.68,0.0,0.0);//translate to 2nd tyre
glutSolidTorus(0.12f, .14f, 10, 25);

glTranslatef(0.0,0.0,-1.4);//translate to 3rd tyre
glutSolidTorus(0.12f, .14f, 10, 25);
glTranslatef(-1.68,0.0,0.0);//translate to 4th tyre which is behind 1st tyre i.e rear .back
glutSolidTorus(0.12f, .14f, 10, 25);
glTranslatef(.58,.52,0.7);//translate to origin
glRotatef(90.0,0.0,1.0,0.0);
glTranslatef(0.0,0.0,-1.40);

glutSolidTorus(0.2f, .2f, 10, 25);

glTranslatef(0.0,0.0,1.40);
glRotatef(270.0,0.0,1.0,0.0);


//bottom filling
glBegin(GL_POLYGON);
glColor3f(0.25,0.25,0.25);
glVertex3f(-0.3,-.48,0.7);//e
glVertex3f(-0.3,-.48,-0.7);//e'
glVertex3f(.81,-0.48,-0.7);//f'
glVertex3f(.81,-0.48,0.7);//f
glEnd();




glBegin(GL_POLYGON);
glVertex3f(-.42,-.2,0.7);//d
glVertex3f(-.42,-.2,-0.7);//d'
glVertex3f(-0.3,-.48,-0.7);//e'
glVertex3f(-0.3,-.48,0.7);//e
glEnd();

glBegin(GL_POLYGON);

glVertex3f(-1.2,-.28,0.7);//r
glVertex3f(-1.2,-.28,-0.7);//r'
glVertex3f(-1.12,-.48,-0.7);//a'
glVertex3f(-1.12,-.48,0.7);//a

glEnd();

glBegin(GL_POLYGON);
glVertex3f(-1.12,-.48,0.7);//a
glVertex3f(-1.12,-.48,-0.7);//a'
glVertex3f(-0.86,-.48,-0.7);//b'
glVertex3f(-0.86,-.48,0.7);//b
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-0.86,-.48,0.7);//b
glVertex3f(-0.86,-.48,-0.7);//b'
glVertex3f(-.74,-0.2,-0.7);//c'
glVertex3f(-.74,-0.2,0.7);//c
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-.74,-0.2,0.7);//c
glVertex3f(-.74,-0.2,-0.7);//c'
glVertex3f(-.42,-.2,-0.7);//d'
glVertex3f(-.42,-.2,0.7);//d
glEnd();

glBegin(GL_POLYGON);
glVertex3f(.81,-0.48,0.7);//f
glVertex3f(.81,-0.48,-0.7);//f'
glVertex3f(.94,-0.2,-0.7);//g'
glVertex3f(.94,-0.2,0.7);//g
glEnd();

glBegin(GL_POLYGON);
glVertex3f(.94,-0.2,0.7);//g
glVertex3f(.94,-0.2,-0.7);//g'
glVertex3f(1.24,-.2,-0.7);//h'
glVertex3f(1.24,-.2,0.7);//h
glEnd();

glBegin(GL_POLYGON);
glVertex3f(1.24,-.2,0.7);//h
glVertex3f(1.24,-.2,-0.7);//h'
glVertex3f(1.38,-.48,-0.7);//i'
glVertex3f(1.38,-.48,0.7);//i
glEnd();

glBegin(GL_POLYGON);
glVertex3f(1.38,-.48,0.7);//i
glVertex3f(1.38,-.48,-0.7);//i'
glVertex3f(1.52,-.44,-0.7);//j'
glVertex3f(1.52,-.44,0.7);//j
glEnd();




//********************************************************************************************8


// door outline- rear, front
glBegin(GL_LINE_LOOP);
glColor3f(1.0,1.0,1.0);
glVertex3f(-0.5,0.22,0.7);//hh
glVertex3f(0.0,0.22,0.7);//gg
glVertex3f(0.0,-0.2,0.7);//oo
glVertex3f(-0.5,-0.2,0.7);//pp


glEnd();



// door2 outline- near, driver

glBegin(GL_LINE_LOOP);

glVertex3f(0.12,0.22,0.7);//ll
glVertex3f(0.62,0.22,0.7);//kk
glVertex3f(0.62,-0.2,0.7);//mm
glVertex3f(0.12,-0.2,0.7);//nn
glEnd();


glColor3f(0.0,0.0,0.0);
// door2  outline- far, driver

glBegin(GL_LINE_LOOP);

glVertex3f(0.12,0.22,-0.7);//ll'
glVertex3f(0.62,0.22,-0.7);//kk'
glVertex3f(0.62,-0.2,-0.7);//mm'
glVertex3f(0.12,-0.2,-0.7);//nn'
glEnd();

// door outline- rear, far
glBegin(GL_LINE_LOOP);

glVertex3f(-0.5,0.22,-0.7);//hh'
glVertex3f(0.0,0.22,-0.7);//gg'
glVertex3f(0.0,-0.2,-0.7);//oo'
glVertex3f(-0.5,-0.2,-0.7);//pp'


glEnd();
glBegin(GL_POLYGON);//front**
glVertex3f(1.52,.14,0.7);//k
glVertex3f(1.52,.14,-0.7);//k'
glVertex3f(1.52,-.44,-0.7);//j'
glVertex3f(1.52,-.44,0.7);//j

glEnd();

glColor3f(0.0,0.0,1.0);

// transparent objects are placed next ..

 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);//TRANCPARENCY3

//windscreen
 glBegin(GL_POLYGON);
glColor4f(0.0,0.0,0.0,0.7);   //COLOR =WHITE TRANSPARENT
glVertex3f(0.562,.5,.6);//AAA
glVertex3f(.562,.5,-.6);//AAA'
glVertex3f(.76,.22,-.6);//MMM'
glVertex3f(.76,.22,.6);//MMM

glEnd();
//rear window
glBegin(GL_POLYGON);
   //COLOR =WHITE TRANSPARENT

glVertex3f(-1.068,0.5,0.6);//pp
glVertex3f(-1.068,0.5,-0.6);//pp'
glVertex3f(-1.2,0.22,-0.6);//qq'
glVertex3f(-1.2,0.22,0.6);//qq

glEnd();
//leftmost window front
glBegin(GL_POLYGON);
glVertex3f(-0.98,0.5,0.7);//aa
glVertex3f(-0.64,0.5,0.7);//bb
glVertex3f(-0.64,0.22,0.7);//cc
glVertex3f(-1.08,0.22,0.7);//dd
glEnd();

//leftmost window back
glBegin(GL_POLYGON);

glVertex3f(-0.98,0.5,-0.7);//aa
glVertex3f(-0.64,0.5,-0.7);//bb
glVertex3f(-0.64,0.22,-0.7);//cc
glVertex3f(-1.08,0.22,-0.7);//dd
glEnd();

//middle window front

glBegin(GL_POLYGON);

glVertex3f(-0.5,0.5,0.7);
glVertex3f(0.0,0.5,0.7);
glVertex3f(0.0,0.22,0.7);
glVertex3f(-0.5,0.22,0.7);

glEnd();




//middle window back

glBegin(GL_POLYGON);

glVertex3f(-0.5,0.5,-0.7);
glVertex3f(0.0,0.5,-0.7);
glVertex3f(0.0,0.22,-0.7);
glVertex3f(-0.5,0.22,-0.7);

glEnd();
//rightmost window front

glBegin(GL_POLYGON);

glVertex3f(0.12,0.5,0.7);//ii
glVertex3f(0.44,0.5,0.7);//jj
glVertex3f(0.62,0.22,0.7);//kk
glVertex3f(0.12,0.22,0.7);//ll


glEnd();


//rightmost window back

glBegin(GL_POLYGON);

glVertex3f(0.12,0.5,-0.7);//ii'
glVertex3f(0.44,0.5,-0.7);//jj'
glVertex3f(0.62,0.22,-0.7);//kk'
glVertex3f(0.12,0.22,-0.7);//ll'


glEnd();


////car code ends here
glColor3f(0.0,0.0,1.0);

}
void drawhouse()
{
glBegin(GL_LINE_LOOP);

   glVertex3f(-2.6,-.84,2.5);//m
   glVertex3f(-2.6,0.84,2.5);//n
   glVertex3f(-3.04,0.84,2.8);//o
   glVertex3f(0,1.95,2.8);//p
   glVertex3f(3.04,0.84,2.8);//w
   glVertex3f(2.6,0.84,2.5);//q
   glVertex3f(2.6,-0.84,2.5);//r
       glVertex3f(1.59,-0.84,2.5);//s
   glVertex3f(1.59,0.16,2.5);//t
   glVertex3f(-1.59,0.16,2.5);//u
   glVertex3f(-1.59,-0.84,2.5);//v
   glEnd();
   glBegin(GL_LINES);
   glVertex3f(1.59,-0.84,2.5);//s
       glVertex3f(-1.59,-0.84,2.5);//v
   glEnd();

   glBegin(GL_LINE_LOOP);
       glVertex3f(-2.6,-.84,-2.5);//m'
   glVertex3f(-2.6,0.84,-2.5);//n'
   glVertex3f(-3.04,0.84,-2.8);//o'
   glVertex3f(0,1.95,-2.8);//p'
   glVertex3f(3.04,0.84,-2.8);//w'
   glVertex3f(2.6,0.84,-2.5);//q'
   glVertex3f(2.6,-0.84,-2.5);//r'
       glVertex3f(1.59,-0.84,-2.5);//s'
   glVertex3f(1.59,0.16,-2.5);//t'
   glVertex3f(-1.59,0.16,-2.5);//u'
   glVertex3f(-1.59,-0.84,-2.5);//v'
       glEnd();

       glBegin(GL_LINES);
       glVertex3f(-2.6,-.84,2.5);//m
    glVertex3f(-2.6,-.84,-2.5);//m'
        glVertex3f(-2.6,0.84,2.5);//n
glVertex3f(-2.6,0.84,-2.5);//n'
         glVertex3f(-3.04,0.84,2.8);//o
glVertex3f(-3.04,0.84,-2.8);//o'
glVertex3f(0,1.95,2.8);//p
  glVertex3f(0,1.95,-2.8);//p'

   glVertex3f(3.04,0.84,2.8);//w
       glVertex3f(3.04,0.84,-2.8);//w'
   glVertex3f(2.6,0.84,2.5);//q
   glVertex3f(2.6,0.84,-2.5);//q'
   glVertex3f(2.6,-0.84,2.5);//r
   glVertex3f(2.6,-0.84,-2.5);//r'
       glVertex3f(1.59,-0.84,2.5);//s
       glVertex3f(1.59,-0.84,-2.5);//s'

   glVertex3f(-1.59,-0.84,2.5);//v
       glVertex3f(-1.59,-0.84,-2.5);//v'


   glEnd();
   glColor3ub(255,185,1);//*************

   glBegin(GL_QUADS);
        glVertex3f(-2.6,-.84,2.5);//m
glVertex3f(-2.6,0.16,2.5);//uu
glVertex3f(-1.59,0.16,2.5);//u
glVertex3f(-1.59,-0.84,2.5);//v

       glVertex3f(-2.6,0.16,2.5);//uu
       glVertex3f(-2.6,0.84,2.5);//n
    glVertex3f(2.6,0.84,2.5);//q
glVertex3f(2.6,0.16,2.5);//tt


    glVertex3f(1.59,-0.84,2.5);//s
   glVertex3f(1.59,0.16,2.5);//t
        glVertex3f(2.6,0.16,2.5);//tt
glVertex3f(2.6,-0.84,2.5);//r


        glVertex3f(-2.6,-.84,-2.5);//m'
glVertex3f(-2.6,0.16,-2.5);//uu'
glVertex3f(-1.59,0.16,-2.5);//u'
glVertex3f(-1.59,-0.84,-2.5);//v'

       glVertex3f(-2.6,0.16,-2.5);//uu'
       glVertex3f(-2.6,0.84,-2.5);//n'
    glVertex3f(2.6,0.84,-2.5);//q'
glVertex3f(2.6,0.16,-2.5);//tt'


    glVertex3f(1.59,-0.84,-2.5);//s'
   glVertex3f(1.59,0.16,-2.5);//t'
        glVertex3f(2.6,0.16,-2.5);//tt'
glVertex3f(2.6,-0.84,-2.5);//r'

glVertex3f(-2.6,-.84,2.5);//m
    glVertex3f(-2.6,-.84,-2.5);//m'
        glVertex3f(-2.6,0.84,-2.5);//n'
glVertex3f(-2.6,0.84,2.5);//n

glVertex3f(2.6,0.84,2.5);//q
   glVertex3f(2.6,0.84,-2.5);//q'
   glVertex3f(2.6,-0.84,-2.5);//r'
   glVertex3f(2.6,-0.84,2.5);//r

   glEnd();





  glBegin(GL_TRIANGLES);
glVertex3f(0,1.95,2.5);//p
     glVertex3f(3.04,0.84,2.5);//w
         glVertex3f(-3.04,0.84,2.5);//o
glVertex3f(0,1.95,-2.5);//p'
     glVertex3f(3.04,0.84,-2.5);//w'
         glVertex3f(-3.04,0.84,-2.5);//o'

glEnd();
  glColor3ub(255,102,0);//***********top color

   glBegin(GL_QUADS);

    glVertex3f(0,1.95,2.8);//p
   glVertex3f(0,1.95,-2.8);//p'
       glVertex3f(3.04,0.84,-2.8);//w'
       glVertex3f(3.04,0.84,2.8);//w

    glVertex3f(-3.04,0.84,2.8);//o
glVertex3f(-3.04,0.84,-2.8);//o'
glVertex3f(0,1.95,-2.8);//p'
  glVertex3f(0,1.95,2.8);//p

          glEnd();

   glColor3ub(116,18,0);//*******base color

   glBegin(GL_QUADS);
   glVertex3f(-2.6,-.84,2.5);//m
          glVertex3f(2.6,-0.84,2.5);//r
   glVertex3f(2.6,-0.84,-2.5);//r'
   glVertex3f(-2.6,-.84,-2.5);//m'
   glEnd();



}




GLuint createDL() {
GLuint carrDL;

// Create the id for the list
carrDL = glGenLists(1);

// start list
glNewList(carrDL,GL_COMPILE);

// call the function that contains the rendering commands
drawcarr();

// endList
glEndList();

return(carrDL);
}
GLuint createDL2()//******************
{
GLuint houseDL;

// Create the id for the list
houseDL = glGenLists(1);

// start list
glNewList(houseDL,GL_COMPILE);

// call the function that contains the rendering commands
drawhouse();

// endList
glEndList();

return(houseDL);
}//**************

void initScene()
{

glEnable(GL_DEPTH_TEST);
carr_display_list = createDL();
house_display_list= createDL2();//***********

}





void renderScene(void)
{
int i,j;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(.7,0.85,1.0,1.0);

// Draw ground

glColor3f(0.25f, 0.25f, 0.25f);
glBegin(GL_QUADS);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 0.0f,  100.0f);
glVertex3f( 100.0f, 0.0f,  100.0f);
glVertex3f( 100.0f, 0.0f, -100.0f);
glEnd();

// Draw 36 car

for( i = -3; i < 3; i++)
for( j=-3; j < 3; j++)
{
glPushMatrix();
glTranslatef((i)*10.0,0,(j) * 10.0);
glColor3ub(a[i],b[j],c[i]);
glCallList(carr_display_list);
glPopMatrix();
}
if(housevisible)
{
glPushMatrix();
glScalef(2.0,2.0,2.0);
glTranslatef(0.0,.85,-20.0);
glCallList(house_display_list);
          glTranslatef(10.0,0.0,0.0);
  glCallList(house_display_list);
         glTranslatef(-20.0,0.0,0.0);
  glCallList(house_display_list);

glRotatef(90,0.0,1.0,0.0);
        glTranslatef(-10.0,0.0,-10.0);
glCallList(house_display_list);

glTranslatef(-10.0,0.0,0.0);
glCallList(house_display_list);
glTranslatef(-10.0,0.0,0.0);
glCallList(house_display_list);
glPopMatrix();

glPushMatrix();
        glTranslatef(10.0,3.4,-80.0);
        glScalef(4.0,4.0,4.0);
glCallList(house_display_list);
glTranslatef(-10.0,0.0,0.0);
glCallList(house_display_list);
glPopMatrix();

        glPushMatrix();
          glRotatef(90,0.0,1.0,0.0);
glScalef(2.0,2.0,2.0);
glTranslatef(0.0,0.85,15.0);
          glCallList(house_display_list);
glTranslatef(10.0,0.,0.0);
          glCallList(house_display_list);
                 glTranslatef(-20.0,0.,0.0);
          glCallList(house_display_list);
        glPopMatrix();

}
if(fxincr!=0)
theta1=(atan(fzincr/fxincr)*180)/3.141;
else if(fzincr>0)
theta1=-90.0;
else theta1=90.0;

if(fxincr>0&&fzincr<0)
{
theta1=-theta1;
}
else if(fxincr<0&&fzincr<0)
{
theta1=180-theta1;
}
else if(fxincr<0&&fzincr>0)
{
theta1=-180-theta1;
}else if(fxincr>0&&fzincr>0)
{
theta1=-theta1;
}
//else theta1=90;
//glLoadIdentity();
glPushMatrix();
glTranslatef(fx,0,fz);
glRotatef(theta1,0,1,0);
glColor3f(0.8,0.8,0);
glCallList(carr_display_list);
glPopMatrix();

glutSwapBuffers();

}

void orientMe(float ang)
{
    lx = sin(ang);
lz = -cos(ang);
glLoadIdentity();
gluLookAt(x, y, z,
      x + lx,y + ly,z + lz,
  0.0f,1.0f,0.0f);

}


void moveMeFlat(int i)
{
if(xxxx==1)
y=y+i*(lz)*0.1;//*********

if(yyyy==1)
{
x=x+i*(lz)*.1;
}
else
{
z = z + i*(lz)*0.5;
           x = x + i*(lx)*0.5;}
glLoadIdentity();
gluLookAt(x, y, z,
      x + lx,y + ly,z + lz,
  0.0f,1.0f,0.0f);

}

void processNormalKeys(unsigned char key, int x, int y)
{
glLoadIdentity();


if (key == 'q')
exit(0);
         if(key=='t')
          gluLookAt(1,190,50,0,0 ,-10,0.0,1.0,.0);
if(key=='a') moveMeFlat(4);xxxx=1,yyyy=0;
if(key=='s') moveMeFlat(-4);xxxx=1,yyyy=0;
if(key=='w') moveMeFlat(4);yyyy=1;xxxx=0;
if(key=='d') moveMeFlat(-4);yyyy=1;xxxx=0;




}


void inputKey(int key, int x, int y)
{

switch (key)
{
case GLUT_KEY_LEFT : angle -= 0.05f;orientMe(angle);break;
case GLUT_KEY_RIGHT : angle +=0.05f;orientMe(angle);break;
case GLUT_KEY_UP : moveMeFlat(2);xxxx=0,yyyy=0;break;
case GLUT_KEY_DOWN : moveMeFlat(-2);xxxx=0,yyyy=0;break;

}
}
void movecar(int key, int x, int y)
{

switch (key)
{
case GLUT_KEY_LEFT :temp=fxincr;
fxincr=fxincr*cos(theta)+fzincr*sin(theta);
fzincr=-temp*sin(theta)+fzincr*cos(theta);
fx+=fxincr;
fz+=fzincr;

break;
case GLUT_KEY_RIGHT :temp=fxincr;
fxincr=fxincr*cos(-theta)+fzincr*sin(-theta);
fzincr=-temp*sin(-theta)+fzincr*cos(-theta);
fx+=fxincr;
fz+=fzincr;

break;
case GLUT_KEY_UP :fx+=fxincr;
  fz+=fzincr;break;
case GLUT_KEY_DOWN :fx-=fxincr;
          fz-=fzincr; break;

}
glutPostRedisplay();
}

// Reset flags as appropriate in response to menu selections
void ProcessMenu(int value)
{
    glutPostRedisplay();
}

void ProcessMenu1(int value)
{
switch(value)
{
case 1:if(housevisible==0)
        housevisible=1;
else
housevisible=0;
    glutPostRedisplay();
break;
case 2:if(movecarvar==0)
{
glutSpecialFunc(movecar);
        movecarvar=1;
    }
else{
glutSpecialFunc(inputKey);
movecarvar=0;
    }
break;
}
}
void menu()
{
int control;
    int control1;



control= glutCreateMenu(ProcessMenu);
glutAddMenuEntry("**CONTROLS**",1);
glutAddMenuEntry("1)  UP KEY:to move in Forward Direction.",1);
glutAddMenuEntry("2)  DOWN KEY:to move  in Backward Direction.",1);
glutAddMenuEntry("3)  LEFT KEY:to Turn Left .",1);
glutAddMenuEntry("4)  RIGHT KEY:to Turn Right .",1);
glutAddMenuEntry("5)  d:moves Towards Right. ",1);
glutAddMenuEntry("6)  a:moves Towards Left.",1);
glutAddMenuEntry("7)  s:moves Away.",1);
glutAddMenuEntry("8)  w:moves Near.",1);
glutAddMenuEntry("9)  t:Top view.",1);
glutAddMenuEntry("10) q:Quit.",1);
glutAttachMenu(GLUT_RIGHT_BUTTON);
    control1=glutCreateMenu(ProcessMenu1);
glutAddMenuEntry("HOUSE",1);
glutAddMenuEntry("MOVE CAR",2);
glutAttachMenu(GLUT_LEFT_BUTTON);

}


int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(0,0);
glutInitWindowSize(1010,710);
glutCreateWindow("car lot");

initScene();

glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(inputKey);
    menu();
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);

glutReshapeFunc(changeSize);

glutMainLoop();

return(0);
}



Feature
didalam projek ini anda akan diberi feature diantaranya yaitu :

  • mobil : mobil adalah benda yang sedang diparkirkan di lapangan. mobil dengan warna hitam dan biru hanya bisa dilihat viewnya saja. sedangkan mobil yang warna kuning bisa anda gerakan dengan menerkan tombol arah pada keyboard anda.
  • Rumah : pada awal projek dijalankan, masih belum terdapat rumah tapi jika anda klik kanan dan pilih house maka rumah akan muncul.
Event Control Pengguna 
event yang dilakukan didalam projek ini adalah sebagai berikut :
  • tombol keyboard "d" : digunakan untuk bergerak menuju kanan.
  • tombol keyboard "a" : digunakan untuk bergerak menuju kiri.
  • tombol keyboard "s" : digunakan untuk bergerak menjauhi tampilan.
  • tombol keyboard "w" : digunakan untuk bergerak mendekati tampilan.
  • tombol keyboard "t" : digunakan untuk melihat view dari posisi atas.
  • tombol keyboard "q" : digunakan untuk keluar dari animasi.
  • tombol keyboard "key Up" : untuk berpindah ke forward direction.
  • tombol keybard "key Down" : untuk berpindah ke backward direction.
  • tombol keyboard "key left" : untuk berbelok kekiri.
  • tombol keyboard "key right" : untuk berbelok ke kanan.
  • klik kanan untuk melihat help control.
  • klik kiri digunakan untuk menampilkan rumah maupun menjalankan mobil.
untuk hasil akhir dari projek OpenGL yang  anda buat maka akan menghasilkan projek seperti dibawah ini.




terimasih sudah membaca projek ini, semoga bermanfaat dan dapat dimanfaatkan untuk mengerjakan tugas dari dosen maupun meneliti kodingnya satu persatu untuk dibedah alurnya.


Daftar Pustaka

https://cglabprojects.blogspot.com/2014/02/car-park.html



Contoh Projek 3D lainnya.


Baca Juga Projek OpenGL dengan C++ Lainnya  dibawah ini :

 Contoh Projek 2D openGL

Baca juga Animasi 2D untuk projek openGL lainnya dibawah ini

Dasar OpenGL

Baca juga Dasar Dari OpenGL dibawah ini jika kalian ingin menekuninya.


Tingkat keanekaragaman hayati tingkat gen

Tingkat keanekaragaman hayati tingkat gen -- Keanekaragaman hayati adalah sebuah istilah untuk menggambarkan keanekaragaman mahluk hidup di ...