00001 #include <GL/glut.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004
00005
00006
00007
00008 float g_fPropellerAngle = 0.0f;
00009 float g_nPropellerRPS = 0;
00010
00011
00012 float g_fRudderAngle = 0.0f;
00013 float g_fPlaneAngle = 0.0f;
00014 bool g_bRotateLeft = false;
00015 bool g_bRotateRight = false;
00016
00017
00018
00019
00020 const float colorWhite[4] = { 1.0, 1.0, 1.0, 1.0 };
00021 const float colorBlue[4] = { 0.0, 0.2, 1.0, 1.0 };
00022 const float colorGreen[4] = { 0.0, 1, 0.0, 1.0 };
00023 const float colorDarkGreen[4] = { 0.0, 0.5, 0.0, 1.0 };
00024 const float colorNone[4] = { 0.0, 0.0, 0.0, 0.0 };
00025 const float colorDarkGrey[4] = { 0.2, 0.2, 0.2, 0.0 };
00026 const float colorDarkYellow[4] = { 0.8, 0.8, 0.0, 0.0 };
00027 const float colorDarkRed[4] = { 0.5, 0.0, 0.0, 0.0 };
00028 const float colorDarkBrown[4] = { 0.5, 0.3, 0.0, 0.0 };
00029 const float colorSky[4] = { 0.4, 0.6, 1.0, 0.0 };
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 void setDiffuseMaterialColor( const float *mc )
00040 {
00041 glMaterialfv(GL_FRONT, GL_DIFFUSE, mc );
00042 glMaterialfv(GL_FRONT, GL_AMBIENT, mc );
00043 glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone );
00044 glColor4fv(mc);
00045 }
00046
00047
00048
00049 void drawBody()
00050 {
00051 glPushMatrix();
00052
00053
00054 setDiffuseMaterialColor( colorBlue );
00055
00056
00057
00058
00059
00060 glTranslatef( -0.7,0,0 );
00061 glScalef( 3,0.5,0.5 );
00062 glutSolidSphere( 1,20,20 );
00063
00064 glPopMatrix();
00065 }
00066
00067
00068 void drawPropellerBlade()
00069 {
00070
00071 setDiffuseMaterialColor(colorDarkGreen);
00072
00073 glPushMatrix();
00074 glTranslatef( 0,0.5,0 );
00075 glScalef( 0.05, 1,0.15 );
00076 glRotatef( -15, 0,1,0 );
00077 glutSolidCube(1);
00078 glPopMatrix();
00079 }
00080
00081 void drawPropeller()
00082 {
00083
00084 setDiffuseMaterialColor(colorDarkGreen);
00085
00086 glPushMatrix();
00087 glTranslatef( 2.1, 0,0 );
00088 glRotatef( g_fPropellerAngle, 1,0,0 );
00089
00090
00091 glPushMatrix();
00092 glScalef( 0.2, 0.2, 0.2 );
00093 glutSolidSphere( 1,15,15 );
00094 glPopMatrix();
00095
00096 drawPropellerBlade();
00097 glRotatef( 120, 1,0,0 );
00098 drawPropellerBlade();
00099 glRotatef( 120, 1,0,0 );
00100 drawPropellerBlade();
00101
00102 glPopMatrix();
00103 }
00104
00105
00106 void drawWing()
00107 {
00108 setDiffuseMaterialColor(colorDarkYellow);
00109
00110 glPushMatrix();
00111 glTranslatef( -0.5, 0, 1.75 );
00112 glRotatef( -10, 0,1,0 );
00113 glScalef( 2,0.15, 3 );
00114 glutSolidCube(1);
00115 glPopMatrix();
00116 }
00117
00118
00119 void drawTailRudderFrame()
00120 {
00121 setDiffuseMaterialColor(colorDarkYellow);
00122
00123
00124 const float z = 0.1;
00125
00126 const float p0[3] = {0,0,-z};
00127 const float p1[3] = {-0.5,1,-z};
00128 const float p2[3] = { -0.7, 1, -z };
00129 const float p3[3] = { -0.7, 0, -z };
00130
00131 const float p0z[3] = { 0, 0, z };
00132 const float p1z[3] = {-0.5, 1, z };
00133 const float p2z[3] = { -0.7, 1, z };
00134 const float p3z[3] = { -0.7, 0, z };
00135
00136 glBegin( GL_QUADS );
00137
00138
00139 glNormal3f( 0,0,-1 );
00140 glVertex3fv( p3 );
00141 glVertex3fv( p2 );
00142 glVertex3fv( p1 );
00143 glVertex3fv( p0 );
00144
00145
00146 glNormal3f( 0,0,1 );
00147 glVertex3fv( p0z );
00148 glVertex3fv( p1z );
00149 glVertex3fv( p2z );
00150 glVertex3fv( p3z );
00151 glEnd();
00152
00153
00154 glPushMatrix();
00155 glTranslatef( -0.85,0.9,0 );
00156 glScalef( 0.3,0.2,2*z );
00157 glutSolidCube(1);
00158 glPopMatrix();
00159 glPushMatrix();
00160 glTranslatef( -0.85,0.1,0 );
00161 glScalef( 0.3,0.2,2*z );
00162 glutSolidCube(1);
00163 glPopMatrix();
00164
00165
00166 glBegin( GL_QUADS );
00167
00168 glNormal3f( 0,1,0 );
00169 glVertex3fv( p1 );
00170 glVertex3fv( p1z );
00171 glVertex3fv( p0z );
00172 glVertex3fv( p0 );
00173
00174 glNormal3f( 0,1,0 );
00175 glVertex3fv( p1z);
00176 glVertex3fv( p1 );
00177 glVertex3fv( p2 );
00178 glVertex3fv( p2z );
00179
00180 glNormal3f( 1,0,0 );
00181 glVertex3fv( p2z );
00182 glVertex3fv( p2 );
00183 glVertex3fv( p3 );
00184 glVertex3fv( p3z );
00185
00186 glEnd();
00187 }
00188
00189
00190 void drawTailRudder()
00191 {
00192 glPushMatrix();
00193 glTranslatef( -1.5, 0.3, 0 );
00194 glScalef( 1.5,1.5,1 );
00195
00196
00197 drawTailRudderFrame();
00198
00199
00200 setDiffuseMaterialColor( colorDarkRed );
00201 glTranslatef( -0.7,0.5,0 );
00202 glRotatef( g_fRudderAngle, 0,1,0 );
00203 glScalef( 0.3,0.6,0.1 );
00204 glTranslatef( -0.5,0,0 );
00205 glutSolidCube(1);
00206
00207 glPopMatrix();
00208 }
00209
00210
00211 void drawAirplane()
00212 {
00213
00214 drawBody();
00215
00216
00217 glPushMatrix();
00218 glTranslatef( 0,-0.15,0 );
00219 drawWing();
00220 glPopMatrix();
00221
00222
00223 glPushMatrix();
00224 glTranslatef( 0,-0.15,0 );
00225 glRotatef( 180,1,0,0 );
00226 drawWing();
00227 glPopMatrix();
00228
00229
00230 drawPropeller();
00231 drawTailRudder();
00232 }