Week 7 Assignment (desc)
Younghyun Chung
Problem 1.
Create a function called drawWireframeCylinder that takes as input a radius (float), a height (float) and a number of steps (int). The function should draw a series of circles stacked vertically as specified. Draw vertical lines between the circles to complete wireframe effect.
|
void drawWireframeCylinder ( float radius, float height, int numSteps )
{
glPushMatrix();
glRotatef( mouseY, 1,0,0 );
for( int i=0; i<numSteps; i++ )
{
glBegin( GL_LINE_LOOP );
for( int A=0; A<30; A++ )
{
float ang = A / 30.0 * PI * 2.0;
float x = radius*cos(ang);
float y = height * i/numSteps - 300;
float z = radius*sin(ang);
glVertex3f( x,y,z );
}
glEnd();
}
glBegin( GL_LINES );
for( int A=0; A<30; A++ )
{
float ang = A / 30.0 * PI * 2.0;
float x = radius*cos(ang);
float z = radius*sin(ang);
glVertex3f( x,-300,z );
glVertex3f( x,height * (numSteps-1)/numSteps -300,z );
}
glEnd();
glPopMatrix();
}
|
 :
drawWireframeCylinder( 200.0, 600.0, 10 );
|
Problem 2.
Create a function called drawWireframeExtrusion that takes as input an array of points (Vec2d*), the number of points (int), a height (float) and a number of steps (int). The function should draw a wireframe extrusion of the two-dimensional form that is passed in.
|
void drawWireframeExtrusion ( Vec2d* Points, int numPoints, float height, int numSteps )
{
glColor3f( 0,0,0 );
glPushMatrix();
glRotatef( mouseY, 1,0,0 );
for( int i=0;i<numSteps;i++ )
{
glBegin( GL_LINE_LOOP );
for ( int j=0;j<numPoints;j++ )
{
float z = height * i/numSteps;
glVertex3f( Points[j].x-300,Points[j].y,z );
}
glEnd();
}
glPopMatrix();
}
void drawW8_2( void )
{
Points = new Shape();
Points->addPoint( Vec2d( 100,100 ) );
Points->addPoint( Vec2d( 500,200 ) );
Points->addPoint( Vec2d( 600,200 ) );
Points->addPoint( Vec2d( 600,300 ) );
Points->addPoint( Vec2d( 500,300 ) );
Points->addPoint( Vec2d( 450,250 ) );
Points->draw();
drawWireframeExtrusion( Points->PointList, Points->numPoints, 500, 10 );
}
|
 : extrusion of shape
|
|