/*

 *  mesh.cpp

 *  week9

 *

 *  Created by stull on 11/15/07.

 *  Copyright 2007 __MyCompanyName__. All rights reserved.

 *

 */


#include "mesh.h"


// 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 :: 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++)

  {

  grid[i][j].x = i;

  grid[i][j].y = 0;

  grid[i][j].z = j;

  }

  

    }

 

 }