1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
void Vehicle::drawBody(double length,double height,double width) {
glBegin(GL_QUADS);
// front face
glColor3f(0,1,0);
glVertex3f(length, 0, 0);
glColor3f(1,0,0);
glVertex3f(length, height, 0);
glColor3f(0,0,1);
glVertex3f(length, height, width);
glColor3f(0,1,1);
glVertex3f(length, 0, width);
// back face
glVertex3f(0, 0, 0);
glVertex3f(0, height, 0);
glVertex3f(0, height, width);
glVertex3f(0, 0, width);
// right face
glColor3f(1,0,0); //Red
glVertex3f(0, 0, width);
glVertex3f(0, height, width);
glVertex3f(length, height, width);
glVertex3f(length, 0, width);
// left face
glColor3d(1,1,1);
glVertex3f(0, 0, 0);
glVertex3f(0, height, 0);
glVertex3f(length, height, 0);
glVertex3f(length, 0, 0);
// Top face
glColor3f(0,0,1);
glVertex3f(0, height, 0);
glVertex3f(0, height, width);
glVertex3f(length, height, width);
glVertex3f(length, height, 0);
// Bottom face
glVertex3f(0, 0, 0);
glVertex3f(0, 0, width);
glVertex3f(length, 0, width);
glVertex3f(length, 0 , 0);
glEnd();
};
void Vehicle::drawWheel(double radius, double whlwid) {
GLUquadricObj *qobj;
qobj = gluNewQuadric();
glPushMatrix;
glTranslated(length,0,width);
glRotated(90,0,0,1);
glColor3f(0,1,0);
glBegin(GL_POLYGON);
for(float angle = 0; angle < 360; angle++) {
double x = (cos(angle) * radius);
double y = (sin(angle) * radius);
glVertex2f(x, y);
}
glEnd();
gluCylinder(qobj, radius, radius, whlwid, 8, 1);
glPopMatrix;
};
|