Comp Form: Week 8

3d, cylinder, ellipsoid . . .

//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.

wk8screenshot_2.png

float count=0;
void drawWireframeCylinder(float radius, float height, float steps){

	glPushMatrix();
	glRotatef(count*(windowH/2-mouseY)/100,1,0,0);
	glRotatef(count*(windowW/2-mouseX)/100,0,0,1);
	count=count+.1;
	glColor3f(1,.3,0);
	glBegin(GL_POINTS);
	for(int d=0;d<=height;d+=height/steps){
		for (int a=0;a<360;a++){
			float x=radius*cos(radians(a));
			float y=d+mouseY-400;
			float z=radius*sin(radians(a));
			glVertex3f(x,y,z);
		}
	}
	glEnd();

	glBegin(GL_POINTS);
	for (int a=0;a<360;a+=360/steps){

	for(float d=0;d<height;d++){>
			float x=radius*cos(radians(a));
			float y=d+mouseY-400;
			float z=radius*sin(radians(a));
			glVertex3f(x,y,z);
		}
	}
	glEnd();
	glPopMatrix();
}</height;d++){>

//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.

wk8screenshot_3.png

void drawWireframeExtrusion(Vec2d shape[], int nPoints, float height, int steps){
	glPushMatrix();
	glRotatef(count*(windowH/2-mouseY)/100,1,0,0);
	glRotatef(count*(windowW/2-mouseX)/100,0,0,1);

	count=count+.1;
	glColor3f(1,.3,0);

	glBegin(GL_POINTS);
	for(float d=0;d&lt;=height;d+=height/steps){
		for (int a=0;a<npoints;a++){>
			float z= d;
			glVertex3f(shape[a].x,shape[a].y,z);
		}
	}
	glEnd();

	glBegin(GL_POINTS);
	for (int a=0;a<npoints;a+=npoints>

		for(int d=0;d<height;d++){>

			float z=d;
			glVertex3f(shape[a].x,shape[a].y,z);
		}
	}
	glEnd();
	glPopMatrix();

}</height;d++){></npoints;a+=npoints></npoints;a++){>

//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.

wk8screenshot_4.png

void revolve(Vec2d shape[], int nPoints, int steps){
	glPushMatrix();
	glRotatef(count*(windowH/2-mouseY)/100,1,0,0);
	glRotatef(count*(windowW/2-mouseX)/100,0,0,1);

	count=count+.1;
	glBegin(GL_POINTS);
		for (int a=0;a<npoints;a++){>
			for (float r=0;r&lt;2*PI;r+=2*PI/steps){
				float x=shape[a].x;
				float y= shape[a].y * cos(r);
			float z= shape[a].y * sin(r);
			float depth=dist3f(0,0,-1000,x,y,z);
			glColor4f(1,.3,0,100/depth);
			glVertex3f(x, y, z);
		}
		}
		glEnd();

	glPopMatrix();

}</npoints;a++){>

//Problem 4. Create a function that generates an assymetrical three-dimensional wireframe form.

wk8screenshot_1.png

void as(Vec2d shape[], int nPoints, int steps){
	glPushMatrix();
	glRotatef(count*(windowH/2-mouseY)/100,1,0,0);
	glRotatef(count*(windowW/2-mouseX)/100,0,0,1);

	count=count+.1;
	glBegin(GL_POINTS);
	for (int a=0;a<npoints;a++){>
		for (float r=0;r&lt;2*PI;r+=2*PI/steps){
			float x=shape[a].x;
			float y= shape[a].y * cos(r)+60*cos(shape[a].x/nPoints*4+count);
			float z= shape[a].y * sin(r)+40*sin(shape[a].x/nPoints*7+count);
			float depth=dist3f(0,0,-1000,x,y,z);
			glColor4f(1,.3,0,100/depth);
			glVertex3f(x, y, z);
		}
	}
	glEnd();

	glPopMatrix();
}</npoints;a++){>