Rock Eet
Rock Eet
Rock Eet
#define GL_GLEXT_PROTOTYPES
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <math.h>
//This function draw the cylinder in the middle of the rocket body. Use
glutSolidCube to draw the windows on the cylinder.
void rocket_body(){
glPushMatrix ();
rocketBody = gluNewQuadric();
gluQuadricDrawStyle(rocketBody, GLU_FILL);
gluQuadricNormals(rocketBody, GLU_SMOOTH);
gluQuadricOrientation(rocketBody, GLU_OUTSIDE);
glPopMatrix();
}
// drawing a sphere at the bottom of the cylinder as the bottom of the rocket.
void rocket_bottom(){
glColor3f(0, 0.51, 0.641);
glPushMatrix();
glTranslated(7.5, -18, z_viewPoint);// for spherical bottom of the rocket
glRotated(-90, 1, 0, 0); // Rotate Cylinder along X-axis to
make it look vertical
glutSolidSphere(4.5, 32, 32);
glPopMatrix();
}
//This function draw a cone on top of the cylinder as the top of the rocket.
void rocket_top(){
glColor3f(0.482, 0.937, 0.145);
glPushMatrix();
glTranslated(7.5, 12, z_viewPoint);
glRotated(-90, 1, 0, 0);
glutSolidCone(4.5,10.0,32,32);
glPopMatrix();
}
//draw the right most plate. This plate is not in the most proper position even
thought tried a lot of rotations.
glPushMatrix ();
glTranslated(7.5, -15.5, z_viewPoint);
glRotatef(45, 0, 1, 0);
glRotatef(160, 1, 0, 0);
gluPartialDisk(rocketPlate,4.5,18, 10, 5, 0, 30);
glPopMatrix();
switch (mainKey) {
case 'a':{
glPushMatrix();
glTranslated(0, 0, z_dis - 300);
stars(); // show stars far away.
glPopMatrix();
z_dis += 0.8; //stars go closer to eye. Build the effect of moving.
if(theta>359 && theta < 360) //reset rotation angle and z_dis.
{
z_dis = 100;
z_viewPoint = -120;
}
else{
glPushMatrix();
glTranslated(6.5, 0, z_viewPoint);
glRotated(-50, 1, 0, 0); //rotate around x_axis, goes far away from
origin(eye).
glTranslated(-6.7,0,z_viewPoint*(-1));//moving forward far away
from eye.
glPushMatrix();
glTranslated(6.5, 0, z_viewPoint);
glRotated(alpha, 0, 1, 0);
alpha = alpha+2;
glTranslated(-6.5, 0, z_viewPoint*(-1));
rocket_assembly();
if(z_dis > 3000)
z_viewPoint-=0.10;
glPopMatrix();
glPopMatrix();
}
break;
}
glPopMatrix();
glutSwapBuffers();
}
void idle(void){
theta = (theta <360) ? theta+dt:dt;
tx= tx - 0.02;
ty = ty + 0.02;
glutPostRedisplay();
}
void output_menu(){
fprintf(stdout, "Rocket 3D Manual:BARNABAS OMBAKI NYANSIMERA");
cout<<"\n\nThe program is run by default."<<endl;
cout<<"\033[0;32;32mcontrolls coming soon.\n\n"<<endl;
cout <<"please Press 'a' to run the program again.\n\n"<<endl;
}
output_menu();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}