Week 7 Assignment
Yasmin Elayat
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 rad=100.0, float height=10, int step=50) {
//rotate around x, y, or z axis
glPushMatrix();
glRotatef(mouseY, 1,0,0);
glColor4f( 1.0,1.0,1.0, 0.5 );
for(int D=0; D < height; D++) {
glBegin(GL_LINE_LOOP);
for(int A=0; A<30; A++) //to draw 3d flat circle
{
float ang = A/30.0 * 3.14159*2.0;
float x= rad*cos(ang);
float y=D*step - rad; //mouseY-400;
float z= rad*sin(ang);
glVertex3f(x,y,z);
}
glEnd();
}
for(int A=0; A<30; A++) //to draw 3d flat circle
{
float ang = A/30.0 * 3.14159*2.0;
float x= rad*cos(ang);
float y1=0*step - rad;
float y2=(height-1)*step - rad;
float z=rad*sin(ang);
glBegin(GL_LINES);
glVertex3f(x,y1,z);
glVertex3f(x,y2,z);
glEnd();
}
glPopMatrix();
}
|
 |
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=10, int step=50) {
glPushMatrix();
glRotatef(mouseY, 1,0,0);
glColor4f(1.0,1.0,1.0,0.5);
for(int D=0; D < height; D++) {
glBegin(GL_LINE_STRIP);
for(int i = 0; i < numPoints; i++){
glVertex3f(points[i].x, D*step, points[i].y);
}
glEnd();
}
glColor3f(1.0,1.0,1.0);
for(int i = 0; i < numPoints; i++){
glBegin(GL_LINE_STRIP);
for(int D=0; D < height; D++) {
glVertex3f(points[i].x, D*step, points[i].y);
}
glEnd();
}
glPopMatrix();
}
|
 |
Problem 3. Create a function called drawWireframeRevolution that takes as input an array of points (Vec2d) and the number of points (int). The function should uses the array of points as a revolution profile. To do this, draw a circle for each point in the array where the circle's radius is equal to the point's X component, and the the circle's vertical height is equal to the circle's Y value. Complete the wireframe by drawing the vertical lines.
|
void drawWireframeRevolution(Vec2d points[], int numPoints=10) {
glPushMatrix();
glRotatef(mouseY, 1,0,0);
glColor4f(1.0,1.0,1.0,0.5);
for(int i = 0; i < numPoints; i++){
glBegin(GL_LINE_LOOP); //POLYGON);
for(int A=0; A<30; A++) //to draw 3d flat circle
{
float ang = A/30.0 * 3.14159*2.0;
float x= points[i].x*cos(ang);
float y=points[i].y; //D*step - rad;
float z= points[i].x*sin(ang);
glVertex3f(x,y,z);
}
glEnd();
}
glColor4f(1.0,1.0,1.0,0.6);
for(int A=0; A<30; A++) //to draw 3d flat circle
{
float ang = A/30.0 * 3.14159*2.0;
glBegin(GL_LINE_STRIP);
for(int i = 0; i < numPoints; i++) {
float x= points[i].x*cos(ang);
float y=points[i].y;
float z= points[i].x*sin(ang);
//glVertex3f(points[i].x, points[i].y, 0);
glVertex3f(x,y,z);
}
glEnd();
}
glPopMatrix();
}
|
 |
|