PDA

View Full Version : Moving an airplane flap



gerire
11-25-2002, 07:20 AM
The following is code that I have written for a basic Airplane tail fin:
void Tail()
{
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(4,0,0.4);
glVertex3f(2,8,0.4);
glVertex3f(0,8,0);
glEnd();

glBegin(GL_POLYGON);//Back FACE green
glColor3f(0.0,0.0,1.0);
glVertex3f(0,0,1);
glVertex3f(4,0,0.6);
glVertex3f(2,8,0.6);
glVertex3f(0,8,1);

glEnd();

glBegin(GL_POLYGON);//lhs blue
glColor3f(0.0,0.0,1.0);
glVertex3f(4,0,0.4);
glVertex3f(4,0,0.6);
glVertex3f(2,8,0.6);
glVertex3f(2,8,0.4);

glEnd();
glBegin(GL_POLYGON);//RHS white
glColor3f(1.0,1.0,1.0);
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glVertex3f(0,8,1);
glVertex3f(0,8,0);

glEnd();
glBegin(GL_POLYGON);//Top color
glColor3f(1.0,0.0,1.0);
glVertex3f(0,8,0);
glVertex3f(0,8,1);
glVertex3f(2,8,0.6);
glVertex3f(2,8,0.4);

glEnd();
glBegin(GL_POLYGON);//BOTTOM
glColor3f(0.0,1.0,1.0);
glVertex3f(0,0,0);
glVertex3f(4,0,0.4);
glVertex3f(4,0,.6);
glVertex3f(0,0,1);

glEnd();
glBegin(GL_POLYGON);//flaps
glColor3f(0,0,1);
glVertex3f(2,8,0.5);
glVertex3f(4,0,0.5);
glVertex3f(4.75,0,0.5);
glVertex3f(2.75,8,0.5);
glEnd();

}
The last polygon is for a flap, as it is on the slanted side of the wing I cannot seem to be able to move it up and down, Any help please

nexusone
11-25-2002, 08:58 AM
You need to make use of glPush/pop matrix commands.


I have edited your code below


Originally posted by gerire:
The following is code that I have written for a basic Airplane tail fin:
void Tail()
{
glPushMatrix();
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(4,0,0.4);
glVertex3f(2,8,0.4);
glVertex3f(0,8,0);
glEnd();

glBegin(GL_POLYGON);//Back FACE green
glColor3f(0.0,0.0,1.0);
glVertex3f(0,0,1);
glVertex3f(4,0,0.6);
glVertex3f(2,8,0.6);
glVertex3f(0,8,1);

glEnd();

glBegin(GL_POLYGON);//lhs blue
glColor3f(0.0,0.0,1.0);
glVertex3f(4,0,0.4);
glVertex3f(4,0,0.6);
glVertex3f(2,8,0.6);
glVertex3f(2,8,0.4);

glEnd();
glBegin(GL_POLYGON);//RHS white
glColor3f(1.0,1.0,1.0);
glVertex3f(0,0,0);
glVertex3f(0,0,1);
glVertex3f(0,8,1);
glVertex3f(0,8,0);

glEnd();
glBegin(GL_POLYGON);//Top color
glColor3f(1.0,0.0,1.0);
glVertex3f(0,8,0);
glVertex3f(0,8,1);
glVertex3f(2,8,0.6);
glVertex3f(2,8,0.4);

glEnd();
glBegin(GL_POLYGON);//BOTTOM
glColor3f(0.0,1.0,1.0);
glVertex3f(0,0,0);
glVertex3f(4,0,0.4);
glVertex3f(4,0,.6);
glVertex3f(0,0,1);

glEnd();

glPushMatrix();
glRotatef(angle_rotate, 0,1,0); // not sure which axis will work best, just try one at a time X,Y,Z to get correct motion.
glBegin(GL_POLYGON);//flaps
glColor3f(0,0,1);
glVertex3f(2,8,0.5);
glVertex3f(4,0,0.5);
glVertex3f(4.75,0,0.5);
glVertex3f(2.75,8,0.5);
glEnd();
glPopMatrix();

glPopMatrix();
}
The last polygon is for a flap, as it is on the slanted side of the wing I cannot seem to be able to move it up and down, Any help please