void DrawScene(void) { // this is the variable declerations int e; float X, Y, Z; // all of this stuff is just for the lighting of the // scene. GLfloat groundAmbient[4]={ 0.02f, 0.3f, 0.1f, 1.0f }; GLfloat local_ambient[4]={ 0.7f, 0.7f, 0.7f, 1.0f }; GLfloat ambient0[4]={ 0.0f, 0.0f, 0.0f, 1.0f }; GLfloat diffuse0[4]={ 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat specular0[4]={ 1.0f, 0.0f, 0.0f, 1.0f }; GLfloat position0[4]= { 2.0f, 100.5f, 1.5f, 1.0f }; GLfloat ambient1[4]={ 0.0f, 0.0f, 0.0f, 1.0f }; GLfloat diffuse1[4]={ 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat specular1[4]={ 1.0f, 0.0f, 0.0f, 1.0f }; GLfloat position1[4]= { -2.0f, 100.5f, 1.0f, 0.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, local_ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightfv(GL_LIGHT0, GL_POSITION, position0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1); glLightfv(GL_LIGHT1, GL_POSITION, position1); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1); glLightfv(GL_LIGHT1, GL_SPECULAR, specular1); // end of lighting X = xcell.cg.NED[0]; // North = Xcomputer frame Y = -xcell.cg.NED[2]; // Down = -Ycomputer frame Z = xcell.cg.NED[1]; // East = Zcomputer frame glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // R/C Pilot's point of view gluLookAt(1.0, 6.0, 30.0, X, Y, Z, 0.0, 1.0, 0.0); glEnable(GL_NORMALIZE); glDisable(GL_LIGHTING); glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, 5.0f, 0.0f); glEnd(); //this is the ground glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, groundAmbient); glBegin(GL_POLYGON); glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(31200.0f, -0.0f, -31200.0f); glVertex3f(-31200.0f, -0.0f, -31200.0f); glVertex3f(-31200.0f, -0.0f, 31200.0f); glVertex3f(31200.0f, -0.0f, 31200.0f); glEnd(); glDisable(GL_LIGHTING); for(e=-1000; e<=1000; e+=50) { glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_LINES); glVertex3f(e, 0.8, -1000.0f); glVertex3f(e, 0.8, 1000.0f); glVertex3f(-1000.0f, 0.8, e); glVertex3f(1000.0f, 0.8, e); glEnd(); } glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(X, Y, Z); glRotatef(xcell.cg.THETA[2]*C_RAD2DEG, 0.0f, -1.0f, 0.0); glRotatef(xcell.cg.THETA[1]*C_RAD2DEG, 0.0f, 0.0f, 1.0f); glRotatef(xcell.cg.THETA[0]*C_RAD2DEG, 1.0f, 0.0f, 0.0f); DrawXcellModel(); glPopMatrix(); glPushMatrix(); // Draw the shadows // make the neccessary squashing matrix float mat[16]; mat[0]=1.0; mat[1]=0.0; mat[2]=0.0; mat[3]=0.0; mat[4]=0.0; mat[5]=0.0; mat[6]=0.0; mat[7]=0.0; mat[8]=0.0; mat[9]=0.0; mat[10]=1.0; mat[11]=0.0; mat[12]=0.0; mat[13]=0.0; mat[14]=0.0; mat[15]=1.0; glMultMatrixf(mat); // Everything now is flattened onto the ground glTranslatef(X, 0.01, Z); glRotatef(xcell.cg.THETA[2]*C_RAD2DEG, 0.0f, -1.0f, 0.0); glRotatef(xcell.cg.THETA[1]*C_RAD2DEG, 0.0f, 0.0f, 1.0f); glRotatef(xcell.cg.THETA[0]*C_RAD2DEG, 1.0f, 0.0f, 0.0f); DrawXcellShadowModel(); glPopMatrix(); }
/** * @param {short} xi_type 0 : RC pilot view * 1 : fly behind view * 2 : upper view * @return helicopter model, ground, sky and shadow on screen drawing **/ void DrawScene(short xi_type) { // statics (scene lighting definitions) static const GLfloat groundAmbient[4] = {0.02f, 0.3f, 0.1f, 1.0f}, local_ambient[4] = {0.7f, 0.7f, 0.7f, 1.0f}, ambient0[4] = {0.0f, 0.0f, 0.0f, 1.0f}, diffuse0[4] = {1.0f, 1.0f, 1.0f, 1.0f}, specular0[4] = {1.0f, 0.0f, 0.0f, 1.0f}, position0[4] = {2.0f, 100.5f, 1.5f, 1.0f}, ambient1[4] = {0.0f, 0.0f, 0.0f, 1.0f}, diffuse1[4] = {1.0f, 1.0f, 1.0f, 1.0f}, specular1[4] = {1.0f, 0.0f, 0.0f, 1.0f}, position1[4] = {-2.0f, 100.5f, 1.0f, 0.0f}; // statics (squashing matrix; 3D -> 2D) static const float mat[16] = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; // locals int e; float X, Y, Z; double camera[3], destination[3], up[3]; // view port // scene light definitions glLightModelfv(GL_LIGHT_MODEL_AMBIENT, local_ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightfv(GL_LIGHT0, GL_POSITION, position0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1); glLightfv(GL_LIGHT1, GL_POSITION, position1); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1); glLightfv(GL_LIGHT1, GL_SPECULAR, specular1); // A/V position X = heli.cg.NED[_NORTH]; // North = X computer frame Y = -heli.cg.NED[_DOWN]; // Down = -Y computer frame Z = heli.cg.NED[_EAST]; // East = Z computer frame // clear view port glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // view port if (xi_type == 0) { camera[_X] = 1.0; camera[_Y] = 6.0; camera[_Z] = 30.0; destination[_X] = X; destination[_Y] = Y; destination[_Z] = Z; up[_X] = 0.0; up[_Y] = 1.0; up[_Z] = 0.0; } else if (xi_type == 1) { camera[_X] = X - 10 * cos(heli.cg.THETA[_PSI]); camera[_Y] = Y + 1; camera[_Z] = Z - 10 * sin(heli.cg.THETA[_PSI]); destination[_X] = X; destination[_Y] = Y; destination[_Z] = Z; up[_X] = 0.0; up[_Y] = 1.0; up[_Z] = 0.0; } else if (xi_type == 2){ camera[_X] = X; camera[_Y] = 50; camera[_Z] = Z; destination[_X] = X; destination[_Y] = Y; destination[_Z] = Z; up[_X] = 1.0; up[_Y] = 1.0; up[_Z] = 0.0; } gluLookAt(camera[_X], camera[_Y], camera[_Z], destination[_X], destination[_Y], destination[_Z], up[_X], up[_Y], up[_Z]); glEnable(GL_NORMALIZE); glDisable(GL_LIGHTING); // origin heli pad lines glLineWidth(3.0f); glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_LINES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); glEnd(); // origin heli pad circle DrawCircle(0.0, 0.0, 1.0, 8); glLineWidth(1.0f); //ground glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, groundAmbient); glBegin(GL_POLYGON); glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(31200.0f, -0.0f, -31200.0f); glVertex3f(-31200.0f, -0.0f, -31200.0f); glVertex3f(-31200.0f, -0.0f, 31200.0f); glVertex3f(31200.0f, -0.0f, 31200.0f); glEnd(); glDisable(GL_LIGHTING); for(e = -1000; e <= 1000; e += 50) { glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_LINES); glVertex3f(e, 0.8, -1000.0f); glVertex3f(e, 0.8, 1000.0f); glVertex3f(-1000.0f, 0.8, e); glVertex3f(1000.0f, 0.8, e); glEnd(); } glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(X, Y, Z); glRotatef(heli.cg.THETA[_PSI]*C_RAD2DEG, 0.0f, -1.0f, 0.0); glRotatef(heli.cg.THETA[_THETA]*C_RAD2DEG, 0.0f, 0.0f, 1.0f); glRotatef(heli.cg.THETA[_PHI]*C_RAD2DEG, 1.0f, 0.0f, 0.0f); DrawXcellModel(); glPopMatrix(); /* for (i = 0; i < 6; i++) { glPushMatrix(); glTranslatef(X + pow(-1, i)*i*6, Y + 2*i, Z - i*7); glRotatef(xcell.cg.THETA[_PSI]*C_RAD2DEG + i*50, 0.0f, -1.0f, 0.0); // heading glRotatef(xcell.cg.THETA[_THETA]*C_RAD2DEG - i*3, 0.0f, 0.0f, 1.0f); // pitch glRotatef(xcell.cg.THETA[_PHI]*C_RAD2DEG + i*4, 1.0f, 0.0f, 0.0f); // roll DrawXcellModel(); glPopMatrix(); } */ glPushMatrix(); // Draw the shadows glMultMatrixf(mat); // Everything now is flattened onto the ground glTranslatef(X, 0.01, Z); glRotatef(heli.cg.THETA[_PSI] * C_RAD2DEG, 0.0f, -1.0f, 0.0); glRotatef(heli.cg.THETA[_THETA] * C_RAD2DEG, 0.0f, 0.0f, 1.0f); glRotatef(heli.cg.THETA[_PHI] * C_RAD2DEG, 1.0f, 0.0f, 0.0f); DrawXcellShadowModel(); glPopMatrix(); }