void table(double topWid, double topThick, double legThick, double legLen) { glPushMatrix(); glTranslated(0, legLen, 0); glScaled(topWid, topThick, topWid); glutSolidCube(1.0); glPopMatrix(); double dist = 0.95 * topWid / 2.0 - legThick / 2.0; glPushMatrix(); glTranslated(dist, 0 ,dist); tableLeg(legThick, legLen); glTranslated(0.0, 0.0, -2 * dist); tableLeg(legThick,legLen); glTranslated(-2 * dist, 0, 2 * dist); tableLeg(legThick, legLen); glTranslated(0, 0, -2 * dist); tableLeg(legThick, legLen); glPopMatrix(); }
//function to create table and pass parameter to tabel leg void table(double tableWid, double tableThick, double legThick, double legLen) { //create table leg glColor3f(0.5,0.1,0.1); //set color to brown double d = 0.95*tableWid/2.0 - legThick/2.0; glPushMatrix(); glTranslated(d,0, d); tableLeg(legThick,legLen); glPushMatrix(); glTranslated(-2*d,0, 0); tableLeg(legThick,legLen); glPushMatrix(); glTranslated(0,0,-2*d); tableLeg(legThick,legLen); glPushMatrix(); glTranslated(2*d,0,0); tableLeg(legThick,legLen); //create chair leg glPushMatrix(); glColor3f(1,0.4,0); glTranslated(-d,-0.02,d/0.45); tableLeg(legThick/1.75,0.7); glPopMatrix(); //create table top glPushMatrix(); glColor3f(0.3,0,0); glTranslatef(-tableWid/2.0+legThick-tableWid/20 ,legLen,tableWid/2.0-legThick/2.0 ); glScaled(tableWid,tableThick,tableWid); glutSolidCube(1); glPopMatrix(); glPopMatrix(); glPopMatrix(); glPopMatrix(); glPopMatrix(); }