void shadedTriangleDraw( Vec3d _A, Vec3d _B, Vec3d _C,float _counter){

 //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());

 Vec3d L(mouseX/windowW,0,mouseY/windowH); // lighting

 

 float shade = L.dot(normal); // gets smallest vect length

// printf(" %f",_counter);

 // draw

 


  glColor3f(shade ,shade - _counter*2,shade +_counter);

 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 gridTdraw(){

   Vec3d VP= Vec3d();

float  counter = 0;

//set 

for( int x=0; x<meshW; x++ )

{

for( int y=0; y<meshH; y++ )

{

    VP.x = x;

VP.y = y;

VP.z = -(float(y)/5);

mesh[x][y] = VP ;

    }

}


  

//draw

glColor3f( 0,1,1 );

for( int x=0; x<meshW-1; x++ )

{

//glBegin(GL_LINE_STRIP); //each row gets a strip

for( int y=0; y<meshH-1; y++ )

{

   

Vec3d A = mesh[x][y] ;

Vec3d B = mesh[x+1][y] ;

Vec3d C = mesh[x+1][y+1] ;

Vec3d D = mesh[x][y+1] ;

/*glVertex3f( A.x, A.y, A.z);

glVertex3f( B.x, B.y, B.z);

glVertex3f( C.x, C.y, C.z);

glVertex3f( D.x, D.y, D.z);*/

shadedTriangleDraw( A, B, C,counter);

counter+= .003;

shadedTriangleDraw(D ,A ,C,counter );

    }

// glEnd();

}

   



}