Vec3d* Flower(float radius, Vec3d center,int petals,float petalSize, Vec3d pointA[], int points){
Vec3d cp(0,0,0); //circle points as vector
float pointRatio = points/petals;
glColor3f( 1,0,0 );
glBegin( GL_LINE_STRIP );
for (int i = 0; i< points; i++){//number of points (x) x/number gives number of arcs how many points are in one arc of 360
float x = i; // watch the i's
float angle = ((360)/(float)points)*x; //2*pi is 360 divided into degree segments based on points multiplied by what point your on
float addOn = petalSize * helpers::d_sin(((x/pointRatio)*360) );// to make a sine wave map to radius
// float addOn= 10;
cp.x= helpers::d_cos(angle) * (radius+addOn); //gets the length of x in unit circle and muiltiplies by radius the size out
cp.y= helpers::d_sin(angle) * (radius+addOn); //gets the length of y and muiltiplies by radius
pointA[i] = cp;
glVertex3f(cp.x,cp.y,cp.z);
}
glEnd();
return pointA;
}
// constructor
mesh::mesh(int W,int H){
gridW = W;
gridH = H;
//gets a bloc of memory for the first array of pointers to pointers
grid = (Vec3d**)malloc(sizeof(Vec3d)*gridW); //calls malloc to give a block of memory gives back a pointer to a pointer of Vec3ds
for (int i =0;i<gridW;i++)
{
//gives memory to each array that holds Vec3ds returns a pointer to a Vec3d
grid[i] = (Vec3d*)malloc(sizeof(Vec3d)*gridH);
}
// empty fill
Vec3d zeropoint = Vec3d(0,0,0);
for (int i= 0; i< gridW; i++)
{
for (int j=0; j<gridH; j++)
{
grid[i][j] = zeropoint;
}
}
}
void mesh :: drawShadedFrame(Vec3d _light){
Vec3d VP= Vec3d();
//draw
glColor3f( 0,1,1 );
float counter=0;
//_light.print();
for( int x=0; x<gridW-1; x++ )
{
//glBegin(GL_LINE_STRIP); //each row gets a strip
for( int y=0; y<gridH-1; y++ )
{
Vec3d A = grid[x][y] ;
Vec3d B = grid[x+1][y] ;
Vec3d C = grid[x+1][y+1] ;
Vec3d D = grid[x][y+1] ;
shadedTriangleDraw( A, B, C, _light);
shadedTriangleDraw(D ,A ,C, _light );
}
// glEnd();
}
}
void mesh::shadedTriangleDraw( Vec3d _A, Vec3d _B, Vec3d _C,Vec3d L){
//define triangle vectors
Vec3d AB = _B - _A;
Vec3d AC = _C - _A;
Vec3d normal = AB.cross(AC); // get perp vector
// printf(" %f",normal.vectorLength());
normal = normal/normal.vectorLength(); // gets the perpedicular line at the smallest vect length
// printf(" %f",normal.vectorLength());
float shade = L.dot(normal); // gets smallest vect length
//printf(" %f",shade);
// draw
/* glColor3f( 1,0,0 );
glBegin(GL_LINE_STRIP);
glVertex3f( normal.x,normal.y,normal.z );
glVertex3f( _C.x,_C.y,_C.z );
glEnd();
glColor3f( 0,1,1 );
glBegin(GL_LINE_LOOP);
glVertex3f( _A.x,_A.y,_A.z );
glVertex3f( _B.x,_B.y,_B.z );
glVertex3f( _C.x,_C.y,_C.z );
glEnd();
*/
glColor3f(shade,shade,shade);
glBegin(GL_TRIANGLES);
glVertex3f( _A.x,_A.y,_A.z );
glVertex3f( _B.x,_B.y,_B.z );
glVertex3f( _C.x,_C.y,_C.z );
glEnd();
}
void mesh :: makeExtrusion(Vec3d * _p,int _numP,int _depth ){
for (int i= 0; i< gridW; i++)
{
for (int j=0; j<gridH; j++)
{
grid[i][j].x = _p[i].x ;
grid[i][j].y = _p[i].y;
// grid[i][j].z = _p[j].y ;
}
}
}
void mesh :: drawWireframe()
{
for (int i= 0; i< gridW-1; i++)
{
for (int j= 0; j<gridH-1; j++)
{
glBegin(GL_LINE_STRIP);
// std::cout <<grid[i][j].z ;
glVertex3f(grid[i][j].x,grid[i][j].y,grid[i][j].z);
glVertex3f(grid[i+1][j].x,grid[i+1][j].y,grid[i+1][j].z);
glVertex3f(grid[i+1][j+1].x,grid[i+1][j+1].y,grid[i+1][j+1].z);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(grid[i][j+1].x,grid[i][j+1].y,grid[i][j+1].z);
glVertex3f(grid[i][j].x,grid[i][j].y,grid[i][j].z);
glVertex3f(grid[i+1][j+1].x,grid[i+1][j+1].y,grid[i+1][j+1].z);
glEnd();
}
}
}
void mesh :: makeGrid(){
// std::cout << "making";
for (int i= 0; i< gridW; i++)
{
for (int j=0; j<gridH; j++)
{
int k = i;
grid[i][j].x = helpers::d_cos(k*(360/(float)gridW))*20;
grid[i][j].y = helpers::d_sin(k*(360/(float)gridH))*20 ;
grid[i][j].z = j; //helpers::d_sin(k*(360/(float)gridH))*20;
}
}
}