// *********** My Object for the object library ************ // Function: Draws a round tall table for a cafe-like environment. // // The colors of the table can be chosen by the user. // drawTable(...) takes 4 parameters in total. // It takes 4 different colors in the following order: // 1. color of the round top surface of the table // 2. color of the supporting main bar of the table // 3. color of the small outer bar toward the bottom of the table // 4. color of the round base of the table // // Note that there is no option for choosing the measurements of // individual components so that, by default, the proportion and // the shape of the table can remain the same as it was created. // Any affine transformations can be used to resize the table. // By default, the size of the round top surface of the table // is set to radius of 6.0 units with the thickness of 1.0 unit. The bar // that supports the table top surface is 20 times the thickness of // the top surface of the table. Then, the round base of the table // is smaller in scale (about radius of 4.7 units) than the top table surface // with the thickness of less than 1/3 the top table surface thickness. // The bottom surface of the round base ends at the end of the // table support since those two objects overlap. // This means that when objects are placed around this table, // it is good to keep in mind that, at most, the space this table will // occupy is 12.0 units horizontally (x, z direction) // and 21.0 units vertically (y direction). // // The origin of the table is at the bottom surface of the lowest // round base of the table and at the center of the region. // // Since it's a round table, all sides of the table look the same. // Therefore, by default, from positive Z-axis, you'll see one side // of the table - table top surface, supporting bar, and base. void gkim1DrawTable(twTriple _surfaceColor, twTriple _barColor, twTriple _smallBarColor, twTriple _baseColor) { const GLint slices = 30; // roundness const GLint stacks = 30; // roundness - another dimension from slice // table round top surface radius const GLfloat surfaceBaseRadius = 6.0; // dimensions of the table round top surface const GLfloat surfaceTopRadius = surfaceBaseRadius; const GLfloat surfaceHeight = surfaceBaseRadius/6.0; // dimensions of the bar supporting the table round top surface const GLfloat barBaseRadius = surfaceTopRadius/6.0; const GLfloat barTopRadius = barBaseRadius; const GLfloat barHeight = surfaceHeight*20.0; // cylinder scaling primarily used for smaller bar // below the main supporting bar of the table round top surface const float barScaleX = surfaceBaseRadius/4.3; const float barScaleY = barScaleX/27.9; const float barScaleZ = barScaleX; // cylinder scaling primarily used for the bottom round base const float bSurfScaleX = barScaleX/1.8; const float bSurfScaleY = barScaleX/4.5; const float bSurfScaleZ = barScaleX/1.8; // draw bottom round base in _baseColor glPushMatrix(); twColor(_baseColor, 0, 0); // bottom of the table is drawn on top of the ground glTranslatef(0,bSurfScaleY*surfaceHeight,0); glScalef(bSurfScaleX, bSurfScaleY, bSurfScaleZ); // smaller than round top surface twSolidCylinder(surfaceBaseRadius, surfaceTopRadius, surfaceHeight, slices, stacks); glPopMatrix(); // draw smaller supporting bar towards the bottom in _smallBarColor glPushMatrix(); twColor(_smallBarColor, 0, 0); glRotatef(-180,1,0,0); // rotate around x-axis so it comes above the ground glScalef(barScaleX, barScaleY, barScaleZ); // wider, shorter than main supporting bar twSolidCylinder(barBaseRadius, barTopRadius, barHeight, slices, stacks); glPopMatrix(); // draw main supporting bar in _barColor glPushMatrix(); twColor(_barColor, 0, 0); glRotatef(-180,1,0,0); // rotate around x-axis so it comes above the ground twSolidCylinder(barBaseRadius, barTopRadius, barHeight, slices, stacks); glPopMatrix(); // draw table surface in _surfaceColor glPushMatrix(); twColor(_surfaceColor,0,0); glTranslatef(0,barHeight+(surfaceHeight/2.0),0); // move to the top of the bar twSolidCylinder(surfaceBaseRadius, surfaceTopRadius, surfaceHeight, slices, stacks); glPopMatrix(); }