week7

problem 1 

float count1;
float count2;

void drawWireframeCylinder(float r, float h, float step){

glPushMatrix();
glRotatef(count1,1,0,0);
glRotatef(mouseY,0,0,1);
glColor3f(1,1,1);

glBegin(GL_LINE_LOOP);
for(int i=0;i<step;i++){
glBegin(GL_LINE_LOOP);
for(int j=0;j<20;j++){
float angle=2*PI*j/20;
float x=r*cos(angle);
float y=i*h/step;
float z=r*sin(angle);
glVertex3f(x,y,z);
}
glEnd();
}
glEnd();


for(int j=0;j<20;j++){
glBegin(GL_LINE_STRIP);
for(int i=0;i<step;i++){
float angle=2*PI*j/20;
float x=r*cos(angle);
float y=i*h/step;
float z=r*sin(angle);
glVertex3f(x,y,z);
}
glEnd();
}
glPopMatrix();
//count1 = count1 +0.04;
count1=mouseY;

}

 

void drawProblem1(){
drawWireframeCylinder(300, 1000,mouseX);

}

problem2

void drawWireframeExtrusion(){
Vec2d center;
Vec2d distortV[numPoints];
Vec2d xp[numPoints];
Vec2d yp[numPoints];


for(int i=0;i<numPoints;i++){
glVertex2f(pointList[i].x,pointList[i].y);
center.x+=pointList[i].x;
center.y+=pointList[i].y;
}
center.x=center.x/numPoints;
center.y=center.y/numPoints;

glPushMatrix();
//glTranslatef( -500,-300, 0 );
glRotatef(count2,1,0,0);
glRotatef(count2,0,1,0);


glColor3f(1,0,0);
glRectf(center.x-5,center.y-5,center.x+5,center.y+5);



//glBegin(GL_LINE_LOOP);
glColor4f(1,1,1,0.3);


for(int j=0;j<100;j++){
glBegin(GL_LINE_STRIP);
for(int i=0;i<numPoints;i++){
distortV[i]=pointList[i]-center;
float d=distortV[i].length();
d=d/100;
float h= j*5;
float w=j*1;
xp[i].x=d_cos(w*d);
xp[i].y=d_sin(w*d);
yp[i].x=-1*d_sin(w*d);
yp[i].y=d_cos(w*d);
distortV[i]=xp[i]*distortV[i].x + yp[i]*distortV[i].y;
distortV[i]=distortV[i]+center;
glVertex3f(distortV[i].x,distortV[i].y,h);
}
glEnd();
}



for(int j=0;j<numPoints;j++){
glBegin(GL_LINE_STRIP);
for(int i=0;i<100;i++){
distortV[j]=pointList[j]-center;
float d=distortV[j].length();
d=d/100;
float h= i*5;
float w=i*1;
xp[j].x=d_cos(w*d);
xp[j].y=d_sin(w*d);
yp[j].x=-1*d_sin(w*d);
yp[j].y=d_cos(w*d);
distortV[j]=xp[j]*distortV[j].x + yp[j]*distortV[j].y;
distortV[j]=distortV[j]+center;
glVertex3f(distortV[j].x,distortV[j].y,h);
}
glEnd();
}



/*
glBegin(GL_LINE_LOOP);
glColor3f(1,1,1);
for(int j=0;j<numPoints;j++){
for(int i=0;i<100;i++){
float h= i*10;
glVertex3f(pointList[j].x,pointList[j].y,h);
}
}
glEnd();
*/

glPopMatrix();
count2 = count2 +0.07;
}