// function definition to draw a blade and the trunk of the mill together void calRotate(int x1,int y1,int x2,int y2,int x3,int y3,int a) { // declaring and initializing variables int nx2,ny2,nx3,ny3; double r; r=(a*PI)/180; // converting the rotating angle 'a' to radian // calcluating the new positions of the points (x2,y2) and (x3,y3) after a rotation nx2=R(((x2*(cos(r)))-(y2*(sin(r))))); ny2=R(((x2*(sin(r)))+(y2*(cos(r))))); nx3=R(((x3*(cos(r)))-(y3*(sin(r))))); ny3=R(((x3*(sin(r)))+(y3*(cos(r))))); //drawing a blade for the mill drawBlade(x1,y1,nx2,ny2,nx3,ny3,YELLOW); } // end of function
void drawSaber(float r, float g, float b) { mvstack.push(model_view); set_colour(.3, .3, .4); model_view *= Scale(0.5, 2, 0.5); model_view *= RotateX(90); drawCylinder(); model_view = mvstack.pop(); mvstack.push(model_view); set_colour(.9, 0, 0); model_view *= Translate(0,.4,.5); model_view *= Scale(.15, .15, .15); drawCylinder(); model_view = mvstack.pop(); if (TIME >= 10) { mvstack.push(model_view); model_view *= Translate(0, 7, 0); drawBlade(r, g, b); model_view = mvstack.pop(); } }
void drawHelicopter(void) { glRotatef(180, 0.0f, 1.0f, 0.0f); if (lightingEnabled) { if (headlight) { setHeadlight(); } else { glDisable(GL_LIGHT1); } } glClearColor(0.49f, 0.75f, 0.93f, 1.0f); drawBody(); //Tail glPushMatrix(); glTranslatef(0.0f, 1.5f, -16.0f); glScalef(0.25f, 1.0f, 2.0f); glBegin(GL_POLYGON); gluCylinder(obj, 1.5, 1.5, 6, 100, 100); glEnd(); glPopMatrix(); //Back Body glPushMatrix(); glScalef(1.33f, 1.0f, 1.0f); glTranslatef(0.0f, 0.0f, -6.0f); glutSolidSphere(3, 100, 100); glPopMatrix(); drawCockpit(); glColor3f(0.50f, 0.50f, 0.50f); //Front Left Leg glPushMatrix(); glTranslatef(2.5f, -3.0f, 2.5f); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glBegin(GL_POLYGON); gluCylinder(obj, 0.25, 0.25, 1, 100, 100); glEnd(); glPopMatrix(); //Back Left Leg glPushMatrix(); glTranslatef(2.5f, -3.0f, -2.5f); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glBegin(GL_POLYGON); gluCylinder(obj, 0.25, 0.25, 1, 100, 100); glEnd(); glPopMatrix(); //Front Right Leg glPushMatrix(); glTranslatef(-2.5f, -3.0f, 2.5f); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glBegin(GL_POLYGON); gluCylinder(obj, 0.25, 0.25, 1, 100, 100); glEnd(); glPopMatrix(); //Back Right Leg glPushMatrix(); glTranslatef(-2.5f, -3.0f, -2.5f); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glBegin(GL_POLYGON); gluCylinder(obj, 0.25, 0.25, 1, 100, 100); glEnd(); glPopMatrix(); glColor3f(0.25f, 0.25f, 0.25f); //Landing Ski Left glPushMatrix(); glTranslatef(2.5f, -4.25f, 0.0f); glScalef(1.0f, 0.5f, 10.0f); glutSolidCube(1.0f); glPopMatrix(); //Landing Ski Right glPushMatrix(); glTranslatef(-2.5f, -4.25f, 0.0f); glScalef(1.0f, 0.5f, 10.0f); glutSolidCube(1.0f); glPopMatrix(); glColor3f(0.33f, 0.42f, 0.18f); //Tail Fin glPushMatrix(); glTranslatef(0.0f, 3.0f, -15.0f); glScalef(0.5f, 6.0f, 3.0f); glutSolidCube(1.0f); glPopMatrix(); /*Rotors drawn in separate methods in case we want to rotate them at some point. It would be easier to modify the code that way. */ // Draw top rotor glColor3f(0.50f, 0.50f, 0.50f); glPushMatrix(); glTranslatef(0.0, 4.0, 0.0); glRotatef(bladeAngle, 0.0, 1.0, 0.0); drawBladeCap(); glTranslatef(0.0, 1.0, 0.0); drawBlade(); glRotatef(120.0, 0.0, 1.0, 0.0); drawBlade(); glRotatef(120.0, 0.0, 1.0, 0.0); drawBlade(); glPopMatrix(); // Draw tail rotor glPushMatrix(); glTranslatef(0.5, 4.5, -15.0); glScalef(0.3, 0.3, 0.3); glRotatef(-90.0, 0.0, 0.0, 1.0); glRotatef(bladeAngle, 0.0, 1.0, 0.0); drawBladeCap(); glTranslatef(0.0, 0.5, 0.0); drawBlade(); glRotatef(120.0, 0.0, 1.0, 0.0); drawBlade(); glRotatef(120.0, 0.0, 1.0, 0.0); drawBlade(); glPopMatrix(); glColor3f(0.24f, 0.32f, 0.16f); //Left Wing glPushMatrix(); glTranslatef(6.5f, 0.5f, -2.0f); glRotatef(-30.0f, 0.0f, 0.0f, 1.0f); glScalef(1.0f, 0.075f, 0.60f); glutSolidCube(8.0f); glPopMatrix(); //Right Wing glPushMatrix(); glTranslatef(-6.5f, 0.5f, -2.0f); glRotatef(30.0f, 0.0f, 0.0f, 1.0f); glScalef(1.0f, 0.075f, 0.60f); glutSolidCube(8.0f); glPopMatrix(); //Tail Wings glPushMatrix(); glTranslatef(0.0f, 1.5f, -11.0f); glScalef(1.0f, 0.10f, 0.5f); glutSolidCube(4.0f); glPopMatrix(); glColor3f(0.50f, 0.50f, 0.50f); //Missile Launcher Left glPushMatrix(); glTranslatef(6.0f, -0.25f, -5.0f); glBegin(GL_POLYGON); gluCylinder(obj, 1, 1, 6, 100, 100); glEnd(); glPopMatrix(); //Missile Launcher Right glPushMatrix(); glTranslatef(-6.0f, -0.25f, -5.0f); glBegin(GL_POLYGON); gluCylinder(obj, 1, 1, 6, 100, 100); glEnd(); glPopMatrix(); glColor3f(0.25f, 0.25f, 0.25f); //Left Side Missile Head glPushMatrix(); glTranslatef(6.0f, -0.25f, 1.0f); glutSolidSphere(1.0, 50, 50); glPopMatrix(); //Right Side Missile Head glPushMatrix(); glTranslatef(-6.0f, -0.25f, 1.0f); glutSolidSphere(1.0, 50, 50); glPopMatrix(); //Machine gun glPushMatrix(); glTranslatef(0.0f, -2.5f, 9.0f); glBegin(GL_POLYGON); gluCylinder(obj, 0.25, 0.25, 2, 100, 100); glEnd(); glPopMatrix(); }