Project Akhir Komputer Grafik : Helikopterku

Sabtu, 12 Juli 2014














  
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "SOIL.h"


void cylinder(float alas,float atas,float tinggi);
void kerucut(float ngisor, float nduwur, float dowo);
void blok(float tebal,int ratiol,int ratiop);
void baling_belakang (float r_inner,float r_outer,float tebal,int batang);

void awan(void);
//GLfloat z_pos = -3.0f;
//GLfloat rot = 0.0f;

double rotation_y=0,rotation_y_plus=-50,direction;
float rotate_y = 0.0;
float rotate_x = 0.0;
float rotate_z = 0.0;

float translate_y = 0.0;
float translate_x = 0.0;
float translate_z = 0.0;


float rot;
int flag=1;

GLUquadricObj *pBadanHeli;
GLUquadricObj *pSilinder;
GLUquadricObj *pMoncong;
GLUquadricObj *tempatpilot;
GLUquadricObj *pawan;
GLuint tex_1;
GLuint tex_2;
GLuint tex_3;
GLuint tex_4;
GLuint tex_5;
GLuint tex_6;

GLuint texture[1];

//GLfloat  source_light[]={0.30,0.30,0.30,0.50};
//double Loop,LoopAll=0 ;

GLuint LoadGLTextures(const char* filename)
{
    GLuint tex;
    tex = SOIL_load_OGL_texture(filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
    if(tex == 0)
        {
            printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
        }
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    return tex;
}




void Helikopter(void)
{

 glClearColor(1.0,9.0,1.0,0.0);
 glShadeModel(GL_SMOOTH);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(50.0,1.5,10.0,1000.0);


    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);



/*
 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 specialKeys( int key, int x, int y ) {


if (key == GLUT_KEY_RIGHT)
  rotate_y += 5.0f;


else if (key == GLUT_KEY_LEFT)
  rotate_y -= 5.0f;

else if (key == GLUT_KEY_UP)
  rotate_x -= 5.0f;

else if (key == GLUT_KEY_DOWN)
  rotate_x += 5.0f;

  else if (key == GLUT_KEY_PAGE_DOWN)
  translate_z += 5.0f;

   else if (key == GLUT_KEY_PAGE_UP)
  translate_z -= 5.0f;



glutPostRedisplay();

}


void display(void)
{

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

glTranslatef(0,0,-110);

//=====================================background awan
glPushMatrix();
glTranslatef(0,0,-70);
glRotated(0,1,0,0);
glRotated(90,0,0,1);
glRotated(0,0,1,0);
glScalef(150,150,0.5);
glBindTexture(GL_TEXTURE_2D,tex_4);
kotak();
glPopMatrix();
//=====================================>end background awan

  glPushMatrix();

  glRotatef( rotate_x, 1.0, 0.0, 0.0 );
  glRotatef( rotate_y, 0.0, 1.0, 0.0 );
  glRotatef( rotate_z, 0.0, 0.0, 1.0 );
  glTranslatef(translate_x,translate_y,translate_z );

//=============================================badan heli
    glPushMatrix();
    glTranslatef(0,0,30);
    glScalef(1.4,1.7,2.5);
    glBindTexture(GL_TEXTURE_2D,tex_1);
    gluSphere(pBadanHeli,7.3,30,30);
    glPopMatrix();
//============================================>end badan heli


//=========================================ekor heli
    glPushMatrix();
    glTranslatef(-1,0,-30);
    glScalef(0.8,1.1,1.1);
    glShadeModel(GL_SMOOTH);
    glBindTexture(GL_TEXTURE_2D, tex_2);
    gluCylinder(pSilinder,1, 3.5, 45, 20, 20);
    glPopMatrix();

//=======================================>end ekor heli



//==========================================kaki kanan
glPushMatrix();
glTranslatef(-3.8,-1.5,0);
glRotated(0,1,0,0);
 glRotated(25,0,0,1);
glRotated(0,0,1,0);
 glPushMatrix();// ruas 1
  glColor3f(9.0,0.0,0.0);
 glTranslatef(3.8,-11.5,30);
 glScalef(0.4,0.6,7);
 glShadeModel(GL_SMOOTH);
 glutSolidCube(2.6);
 glPopMatrix();

 glPushMatrix();// ruas 2
  glColor3f(9.0,0.0,0.0);
 glTranslatef(3.8,-14.5,40);
  glRotated(68,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.4,0.3,2.5);
 glShadeModel(GL_SMOOTH);
 glutSolidCube(3);
 glPopMatrix();

 glPushMatrix();// ruas 3
  glColor3f(9.0,0.0,0.0);
 glTranslatef(3.8,-14.5,20);
  glRotated(115,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.4,0.3,2);
 glShadeModel(GL_SMOOTH);
 glutSolidCube(3);
 glPopMatrix();


 glPushMatrix();// ruas 4
  glColor3f(9.0,0.0,0.0);
 glTranslatef(3.8,-17.5,14);
  glRotated(0,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.4,0.3,2);
 glShadeModel(GL_SMOOTH);
 gluCylinder(tempatpilot, 3.5, 3.5, 15, 20, 20);
    gluDisk(tempatpilot,0.0, 3.5, 20, 20);
 glPopMatrix();
  glPushMatrix();// ruas 4
  glColor3f(9.0,0.0,0.0);
 glTranslatef(3.8,-17.5,14);
  glRotated(0,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.4,0.3,2);
 glShadeModel(GL_SMOOTH);
 gluCylinder(tempatpilot, 3.5, 3.5, 15, 20, 20);
 gluDisk(tempatpilot,0.0, 3.5, 20, 20);
 glPopMatrix();

 glPushMatrix();
 glTranslatef(3.8,-17.5,44);
 glScalef(0.4,0.3,2);
 glShadeModel(GL_SMOOTH);
 glutSolidCone(3.7,2, 100,15);
 glPopMatrix();

 glPopMatrix();
//=============================================>end kaki helikopter kanan



//=============================================kaki helikopter kiri
glPushMatrix();
glTranslatef(3.8,-1.5,0);
glRotated(0,1,0,0);
glRotated(-25,0,0,1);
glRotated(0,0,1,0);

glPushMatrix();//ruas 1
 glColor3f(9.0,0.0,0.0);
 glTranslatef(-3.8,-11.5,30);
 glScalef(0.4,0.6,7);
 glShadeModel(GL_SMOOTH);
 glutSolidCube(2.6);
 glPopMatrix();

 glPushMatrix();// ruas 2
  glColor3f(9.0,0.0,0.0);
 glTranslatef(-3.8,-14.5,40);
  glRotated(68,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.4,0.3,2.5);
 glShadeModel(GL_SMOOTH);
 glutSolidCube(3);
 glPopMatrix();

 glPushMatrix();// ruas 3
  glColor3f(9.0,0.0,0.0);
 glTranslatef(-3.8,-14.5,20);
  glRotated(115,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.4,0.3,2);
 glShadeModel(GL_SMOOTH);
 glutSolidCube(3);
 glPopMatrix();


 glPushMatrix();// ruas 4
  glColor3f(9.0,0.0,0.0);
 glTranslatef(-3.8,-17.5,14);
  glRotated(0,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.4,0.3,2);
 glShadeModel(GL_SMOOTH);
  gluCylinder(tempatpilot, 3.5, 3.5, 15, 20, 20);
    gluDisk(tempatpilot,0.0, 3.5, 20, 20);
 //cylinder(2.5,2.5,12.5);
 glPopMatrix();

 glPushMatrix();
 glTranslatef(-3.8,-17.5,44);
 glScalef(0.4,0.3,2);
 glShadeModel(GL_SMOOTH);
 glutSolidCone(3.7,2, 100,15);
 glPopMatrix();

 glPopMatrix();
//============================================>end kaki helikopter kiri

glPushMatrix();//penyangga baling  belakang
  glColor3f(9.0,0.0,0.0);
 glTranslatef(-1,0,-25);
 glScalef(0.5,1.5,1.5);
 glRotated(-105,1,0,0);
 glShadeModel(GL_SMOOTH);
 glutSolidCone(3,15,35,35);
 glPopMatrix();

glPushMatrix();//====================================model 1 moncong
  glColor3f(9.0,5.0,0.0);
 glTranslatef(-0.2,-3,40);
  glRotated(13,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
 glScalef(1.2,1,2.3);
  glShadeModel(GL_SMOOTH);
  glBindTexture(GL_TEXTURE_2D, tex_3);
  gluCylinder(pMoncong,7.5,0.1, 8.5, 20, 20);

 glPopMatrix();
 //=================================================> end model 1 moncong

 glPushMatrix();
 glTranslatef(8.3,0.0,28);
 glRotated(90,0,1,0);
    glScaled(3,5,2);
    kotak();
    glPopMatrix();

    glPushMatrix();//=========================kaca
 glTranslatef(0,2.5,40);
 //glScalef(1,3,1.5);
 glBindTexture(GL_TEXTURE_2D, tex_2);
    gluSphere(pawan,7.8,50,60);
    glPopMatrix();


//========================================== baling atas
glPushMatrix();
glTranslatef(0,20,29);
glRotatef(rot,0, 1, 0);
glRotatef(-5,1, 0, 0);

glPushMatrix();//baling atas 1 copy
  glColor3f(9.0,0.0,0.0);
  glRotated(0,1,0,0);
   glRotated(25,0,0,1);
   glRotated(90,0,1,0);
  glScalef(9,0.2,0.4);
  glBindTexture(GL_TEXTURE_2D, tex_6);
 glShadeModel(GL_SMOOTH);
 gluSphere(pSilinder,3.5,30,30);
 glPopMatrix();


glPushMatrix();//baling atas 1
  glColor3f(9.0,0.0,0.0);
  glRotated(25,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(9,0.2,0.4);
 glShadeModel(GL_SMOOTH);
 glBindTexture(GL_TEXTURE_2D, tex_6);
 gluSphere(pSilinder,3.5,30,30);
 glPopMatrix();
 glPopMatrix();
//================================================> end baling atas

  glPushMatrix();//sayap belakang
  glColor3f(9.0,0.0,0.0);
 glTranslatef(0,0,-30);
 glScalef(3.5,0.2,0.5);
 glBindTexture(GL_TEXTURE_2D, tex_2);
 glShadeModel(GL_SMOOTH);
 gluSphere(pSilinder,5,30,30);
 glPopMatrix();


  glPushMatrix();//baling_belakang

   glColor3f(9.0,0.0,0.0);
   glTranslatef(0,16,-28.5);
   glRotated(0,1,0,0);
   glRotated(0,0,0,1);
   glRotated(90,0,1,0);
   glShadeModel(GL_SMOOTH);
   //glutWireTorus(5,7,10,64);
   //glutSolidTorus(0.5,9.5,60,64);

   rotation_y+=rotation_y_plus;
   if(rotation_y>1600)rotation_y=0;
   glRotatef(rotation_y,0.0,0.0,1.0);
   baling_belakang(1,8,2,3);
   glPopMatrix();

glPushMatrix();//silinder samping
  glColor3f(9.0,0.0,0.0);
 glTranslatef(-8,-3,29);
 //glScalef(5,8,5);
 glShadeModel(GL_SMOOTH);
 kerucut(3,3,5);
 glPopMatrix();


glPushMatrix();//silinder atas
  glColor3f(9.0,0.0,0.0);
 glTranslatef(-0.4,14,29);
   glRotated(95,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.7,1.5,1.4);
 glShadeModel(GL_SMOOTH);
 glBindTexture(GL_TEXTURE_2D, tex_3);
 cylinder(3,3,5);
 //gluCylinder(pSilinder,3,3,15, 20, 20);
 glPopMatrix();

glPushMatrix();//kerucut atas
  glColor3f(9.0,0.0,0.0);
 glTranslatef(0.2,14,29);
   glRotated(-95,1,0,0);
   glRotated(0,0,0,1);
   glRotated(0,0,1,0);
  glScalef(0.7,1.5,1.4);
 glShadeModel(GL_SMOOTH);
 glBindTexture(GL_TEXTURE_2D, tex_3);
 glutSolidCone(3.5,6.5, 100,15);
 glPopMatrix();



glPushMatrix();//box buntut
  glColor3f(9.0,0.0,0.0);
 glTranslatef(0,0,17);
 glScalef(5,8,5);
 glShadeModel(GL_SMOOTH);
 glutSolidCube(2);
 glPopMatrix();

//============================================knalpot heli
 glPushMatrix();//kerucut buntut
  glColor3f(9.0,0.0,0.0);
 glTranslatef(-10,7,10);
 glScalef(5,8,5);
 glShadeModel(GL_SMOOTH);
 kerucut(0.4,0.1,2);
 glPopMatrix();



 glPushMatrix();//kerucut buntut
 glColor3f(9.0,0.0,0.0);
 glTranslatef(0.5,7,10);
 glScalef(5,8,5);
 glShadeModel(GL_SMOOTH);
 kerucut(0.4,0.1,2);
 glPopMatrix();
//========================================================> end knalpot
/*
glPushMatrix();
glTranslatef(30,0,0);

awan();
glPopMatrix();
*/


glPopMatrix();





 glFlush();
 glutSwapBuffers();

}





void awan(void)
{
    glPushMatrix();
    glColor3ub(153, 223, 255);
    glBindTexture(GL_TEXTURE_2D,tex_5);
    gluSphere(pawan,10, 50, 50);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(10,0,1);
    glBindTexture(GL_TEXTURE_2D,tex_5);
    gluSphere(pawan,5, 20, 20);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-2,6,-2);
    glBindTexture(GL_TEXTURE_2D,tex_5);
    gluSphere(pawan,7, 50, 50);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-10,-3,0);
    glBindTexture(GL_TEXTURE_2D,tex_5);
    gluSphere(pawan,7, 50, 50);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(6,-2,2);
    glBindTexture(GL_TEXTURE_2D,tex_5);
    gluSphere(pawan,7, 50, 50);
    glPopMatrix();

}


void myReshape(int w,int h)
{
 if (h==0)
{
h=1;
}
glViewport(0,0,w,h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,w,h,0.0f,-1.0f,1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


 void baling_belakang (float r_inner,float r_outer,float tebal,int batang)
{
float i;
glPushMatrix();
glTranslatef(0.0,0.0,-tebal/4);
cylinder(r_inner,r_inner,tebal);
glTranslatef(0.0,0.0,tebal/2);
glRotatef(90,0.0,1.0,0.0);
for(i=0;i

Tidak ada komentar:

Posting Komentar