Week 7 Assignment - Computational Forms

Lucas Longo

 

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 steps)
{
glPushMatrix();
glRotatef(mouseX, -1,0,0);
glRotatef(mouseY, 0,0,-1);

// place your drawing code here
for (int D = 0; D <= steps; D++){
glBegin(GL_LINE_LOOP);
glColor3f( 1,0,0 );
for (int A = 0; A < 30; A++){
float ang = A / 30.0 * PI * 2.0;
float x = radius*cos(ang);
float y = D*(height/steps) - 300;
float z = radius*sin(ang);
glVertex3f(x,y,z);
}
glEnd();
}

for (int D = 0; D <= steps; D++){
for (int A = 0; A < 30; A++){
glBegin(GL_LINE_STRIP);
glColor3f( 0,1,0 );
if (D%20 == 0){
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-300,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* pointList, float height, int steps)
{
printf("pointList size %i\n", sizeof(pointList));

glPushMatrix();

glRotatef(mouseX, -1,0,0);
glRotatef(mouseY, 0,-1,0);

// place your drawing code here
for (int D = 0; D <= steps; D++){
glBegin(GL_LINE_LOOP);
glColor3f( 1,0,0 );
for (int i = 0; i < sizeof(pointList)*2; i++){
float x = pointList[i].x;
float y = pointList[i].y;
float z = D*(height/steps);
glVertex3f(x-300,y,z);
}
glEnd();
}
glPopMatrix();
}

void drawProblem2()
{
Vec2d pointList[8];

pointList[0] = Vec2d(50, 40);
pointList[1] = Vec2d(150, 200);
pointList[2] = Vec2d(300, 40);
pointList[3] = Vec2d(450, 250);
pointList[4] = Vec2d(550, 30);
pointList[5] = Vec2d(650, 100);
pointList[6] = Vec2d(750, 15);
pointList[7] = Vec2d(790, -100);

glBegin(GL_LINE_LOOP);
glColor3f(1,1,0);
for (int i = 0; i < 8; i++){
glVertex2f(pointList[i].x-300, pointList[i].y);
}
glEnd();

drawWireframeExtrusion(pointList, mouseX, 10);
}

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* pointList, int points)
{
glPushMatrix();
glRotatef(mouseX, -1,0,0);
glRotatef(mouseY, 0,-1,0);

for (int i = 0; i < points; i++){
glBegin(GL_LINE_LOOP);
glColor3f( 1,0,0 );
for (int A = 0; A < 100; A++){
float ang = A / 100.0 * PI * 2.0;
float x = pointList[i].x * cos(ang) ;
float y = pointList[i].x * sin(ang);
float z = pointList[i].y;

float x2 = pointList[i+1].x * cos(ang) ;
float y2 = pointList[i+1].x * sin(ang);
float z2 = pointList[i+1].y;

glVertex3f(x,y,z);
glVertex3f(x2,y2,z2);
// glVertex3f(x,y,z);
}
glEnd();
}
glPopMatrix();
}

void drawProblem3()
{
Vec2d pointList[8];

pointList[0] = Vec2d(50, 40);
pointList[1] = Vec2d(70, 200);
pointList[2] = Vec2d(100, 40);
pointList[3] = Vec2d(250, 250);
pointList[4] = Vec2d(300, 30);
pointList[5] = Vec2d(310, 100);
pointList[6] = Vec2d(350, 15);
pointList[7] = Vec2d(400, -100);

drawWireframeRevolution(pointList, 8);
}

 

Version 1

 

void drawWireframeRevolution(Vec2d* pointList, int points)
{
glPushMatrix();
glRotatef(mouseX, -1,0,0);
glRotatef(mouseY, 0,-1,0);

for (int i = 0; i < points; i++){
glBegin(GL_LINE_LOOP);
for (int A = 0; A < 100; A++){
float ang = A / 100.0 * PI * 2.0;
float x = pointList[i].x * cos(ang) ;
float y = pointList[i].x * sin(ang);
float z = pointList[i].y;

glColor3f( 1,0,0 );
glVertex3f(x,y,z);
}
glEnd();
}

for (int i = 0; i < points; i++){
for (int A = 0; A < mouseY; A++){
float ang = A / 100.0 * PI * 2.0;
float x = pointList[i].x * cos(ang) ;
float y = pointList[i].x * sin(ang);
float z = pointList[i].y;

glColor3f( 1,0,0 );
glVertex3f(x,y,z);

if (A%2==0){
glBegin(GL_LINE_STRIP);
glColor3f(0,1,0);
float x2 = pointList[i+1].x * cos(ang) ;
float y2 = pointList[i+1].x * sin(ang);
float z2 = pointList[i+1].y;
glVertex3f(x,y,z);
glVertex3f(x2,y2,z2);
glEnd();
}
}
}
glPopMatrix();
}

void drawProblem3()
{
Vec2d pointList[8];

pointList[0] = Vec2d(50, 40);
pointList[1] = Vec2d(70, 200);
pointList[2] = Vec2d(100, 40);
pointList[3] = Vec2d(250, 250);
pointList[4] = Vec2d(300, 30);
pointList[5] = Vec2d(310, 100);
pointList[6] = Vec2d(350, 15);
pointList[7] = Vec2d(400, -100);

drawWireframeRevolution(pointList, 8);
}

Version 2

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

void drawWireframeRevolution2(Vec2d* circlePoint, int points)
{
glPushMatrix();
glRotatef(45, -1,0,0);
glRotatef(45, 0,-1,0);

for (int i = 0; i < points; i++){
for (int A = 0; A < 100; A++){
float ang = A / 100.0 * PI * 2.0;
float x = circlePoint[i].x * cos(ang) ;
float y = circlePoint[i].x * sin(ang);
float z = circlePoint[i].y;

glColor3f( 1,0,0 );

if (A%2==0){
glBegin(GL_POINTS);
glColor3f(0,1,0);
float x2 = circlePoint[i+1].x * cos(ang) ;
float y2 = circlePoint[i+1].x * sin(ang);
float z2 = circlePoint[i+1].y;
glVertex3f(x,y,z);
glVertex3f(x2,y2,z2);
glEnd();
}
}
}

glPopMatrix();
}

void drawProblem4(){

glPushMatrix();
glRotatef(45, -1,0,0);
glRotatef(45, 0,-1,0);

Vec2d dist[100];
float w[100];

dist[0] = Vec2d(50, 40);
dist[1] = Vec2d(150, 500);
dist[2] = Vec2d(300, 40);
dist[3] = Vec2d(450, 450);
dist[4] = Vec2d(550, 30);
dist[5] = Vec2d(650, 350);
dist[6] = Vec2d(750, 15);
dist[7] = Vec2d(790, 500);

w[0] = 1000;
w[1] = 2000;
w[2] = 1500;
w[3] = 3000;
w[4] = 500;
w[5] = 400;
w[6] = 200;
w[7] = 100;

glPointSize(2);
glColor3f(1,1,0);
glBegin(GL_POINTS);
for (int i = 0; i < 8; i++){
glVertex3f(dist[i].x-300,dist[i].y-300, dist[i].y);
}
glEnd();

Vec2d center(mouseX, mouseY);
int numCirclePoints = 360;
Vec2d S(center);
float radius = 100;

glPointSize(1);
glColor3f(1,0,0);
glBegin(GL_POINTS);

Vec2d circlePoint[numCirclePoints];

for(int i = 0; i < numCirclePoints; i++){
float A = 2 * PI / numCirclePoints * i;

S.x = cos(A)*radius + center.x;
S.y = sin(A)*radius + center.y;

circlePoint[i] = Vec2d(S.x, S.y);

for(int z = 0; z < 8; z++){
Vec2d N = circlePoint[i] - dist[z];
float nLength = N.vLength();
N.normalize();

// FALL OF offset = - 2 ^ -(deltaDistPoint^2)
//float offset = pow(-2.0, -1.0 * (nLength * nLength));
float offset = 1/nLength * w[z];

circlePoint[i] = circlePoint[i] + N * offset;
}

glVertex3f(center.x-300, center.y-300, center.y);
glVertex3f(circlePoint[i].x-300, circlePoint[i].y-300, circlePoint[i].y);
}

glEnd();

glPopMatrix();
drawWireframeRevolution2(circlePoint, numCirclePoints);

}

Not really assymetrical but deforming

>