Exemple #1
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		double step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double ns;
  int num_steps;
  
  ns = 1.0 / step;
  num_steps = (int)ns;

  temp = new_matrix( 4, num_steps * num_steps );
  //generate the points on the torus
  generate_torus( temp, cx, cy, r1, r2, step );

  int num_points = temp->lastcol;

  int latStop, longStop, latStart, longStart;
  latStart = 0;
  longStart = 0;
  latStop = num_steps;
  longStop = num_steps;

  for ( lat = 0; lat < latStop; lat++ ) {
    for ( longt = 0; longt < longStop; longt++ ) {
      
      index = lat * num_steps + longt;

      add_edge(points,
	       temp->m[0][index], temp->m[1][index], temp->m[2][index],
	       temp->m[0][index], temp->m[1][index], temp->m[2][index]);    }
  }
}
Exemple #2
0
  /*======== void add_torus() ==========
Inputs: struct matrix * points
double cx
double cy
double r1
double r2
double step
Returns:

adds all the points required to make a torus
with center (cx, cy) and radii r1 and r2.

should call generate_torus to create the
necessary points

03/22/12 13:34:03
jdyrlandweaver
====================*/
void add_torus( struct matrix * points,
double cx, double cy, double r1, double r2,
double step ) {
  struct matrix * temp;
  int lt, lng;
  int num_steps;
  num_steps = (int) (1 / step) + 1;
  temp = new_matrix(4, 4);
  generate_torus(temp, cx, cy, r1, r2, step);
  for(lt = 0; lt <= num_steps - 1; lt++) {
    for(lng = 0; lng <= num_steps - 1; lng++) {
      add_polygon(points, temp->m[0][lt * num_steps + (lng % num_steps)],
                  temp->m[1][lt * num_steps + (lng % num_steps)],
                  temp->m[2][lt * num_steps + (lng % num_steps)],
                  temp->m[0][((lt + 1) % num_steps) * num_steps + (lng + 1) % num_steps],
                  temp->m[1][((lt + 1) % num_steps) * num_steps + (lng + 1) % num_steps],
                  temp->m[2][((lt + 1) % num_steps) * num_steps + (lng + 1) % num_steps],
                  temp->m[0][lt * num_steps + ((lng + 1) % num_steps)],
                  temp->m[1][lt * num_steps + ((lng + 1) % num_steps)],
                  temp->m[2][lt * num_steps + ((lng + 1) % num_steps)]);
      add_polygon(points, temp->m[0][lt * num_steps + lng],
                  temp->m[1][lt * num_steps + lng],
                  temp->m[2][lt * num_steps + lng],
                  temp->m[0][((lt + 1) % num_steps) * num_steps + lng],
                  temp->m[1][((lt + 1) % num_steps) * num_steps + lng],
                  temp->m[2][((lt + 1) % num_steps) * num_steps + lng],
         temp->m[0][((lt + 1) % num_steps) * num_steps + (lng + 1) % num_steps],
         temp->m[1][((lt + 1) % num_steps) * num_steps + (lng + 1) % num_steps],
         temp->m[2][((lt + 1) % num_steps) * num_steps+(lng + 1) % num_steps]);
    }
  }

  free_matrix(temp);

}
Exemple #3
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		double step ) {
  generate_torus(points, cx, cy, r1, r2, step);
  int i = 0;
  for(i = 0; i < points->lastcol; i++){
    add_edge(points,points->m[0][i], points->m[1][i], points->m[2][i], points->m[0][i], points->m[1][i], points->m[2][i]);
  }
}
Exemple #4
0
Fichier : draw.c Projet : stuydw/3d
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		double step ) {

    int i;
    struct matrix *tmp = new_matrix(4, 2);
    generate_torus(tmp, cx, cy, r1, r2, step);
    for (i = 0; i < tmp->lastcol; i++)
        add_edge(points, tmp->m[0][i], tmp->m[1][i], tmp->m[2][i], tmp->m[0][i], tmp->m[1][i], tmp->m[2][i]);
}
Exemple #5
0
/*======== void add_torus() ==========
 Inputs:   struct matrix * points
 double cx
 double cy
 double r1
 double r2
 double step
 Returns:
 
 adds all the points required to make a torus
 with center (cx, cy) and radii r1 and r2.
 
 should call generate_torus to create the
 necessary points
 
 03/22/12 13:34:03
 jdyrlandweaver
 ====================*/
void add_torus( struct matrix * points,
               double cx, double cy, double r1, double r2,
               double step ) {
    
    struct matrix * temp;
    int lat, longt;
    int i;
    double ns;
    int num_steps;
    
    ns = 1.0 / step;
    num_steps = (int)ns;
    
    temp = new_matrix( 4, num_steps * num_steps );
    //generate the points on the torus
    generate_torus( temp, cx, cy, r1, r2, step );
    
    //int num_points = temp->lastcol;
    
    int latStop, longStop, latStart, longStart;
    latStart = 0;
    longStart = 0;
    latStop = num_steps-1;
    longStop = num_steps-1;
    i = num_steps;
    
    for ( lat = latStart; lat <= latStop; lat++ ) {
        for ( longt = longStart; longt <= longStop; longt++ ) {
            add_polygon(points,
                        temp->m[0][lat*i + longt%i],
                        temp->m[1][lat*i + longt%i],
                        temp->m[2][lat*i + longt%i],
                        temp->m[0][((lat+1)%i)*i + (longt+1)%i],
                        temp->m[1][((lat+1)%i)*i + (longt+1)%i],
                        temp->m[2][((lat+1)%i)*i + (longt+1)%i],
                        temp->m[0][lat*i + ((longt+1)%i)],
                        temp->m[1][lat*i + ((longt+1)%i)],
                        temp->m[2][lat*i + ((longt+1)%i)]);
            add_polygon(points,
                        temp->m[0][lat*i + longt],
                        temp->m[1][lat*i + longt],
                        temp->m[2][lat*i + longt],
                        temp->m[0][((lat+1)%i)*i + longt],
                        temp->m[1][((lat+1)%i)*i + longt],
                        temp->m[2][((lat+1)%i)*i + longt],
                        temp->m[0][((lat+1)%i)*i + (longt+1)%i],
                        temp->m[1][((lat+1)%i)*i + (longt+1)%i],
                        temp->m[2][((lat+1)%i)*i + (longt+1)%i]);
        }
    }
}
Exemple #6
0
Fichier : draw.c Projet : stuydw/3d
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		double step ) {
  struct matrix * tmp = new_matrix( 4, 20 );
  int i;
  generate_torus( tmp, cx, cy, r1, r2, step );
  for( i = 0; i < tmp->lastcol; i++ ) {
    double x, y, z;
    x = tmp->m[ 0 ][ i ];
    y = tmp->m[ 1 ][ i ];
    z = tmp->m[ 2 ][ i ];
    add_edge( points, x, y, z, x, y, z );
  }
  free_matrix( tmp );
}
Exemple #7
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		double step ){
  double /*n*/x, y, z;
  int n;
  struct matrix *dummy  = new_matrix(4, 1);
  generate_torus(dummy, cx, cy, r1, r2, step);
  for (n = 0; n < dummy->lastcol; n++) {
    x = dummy->m[0][n];
    y = dummy->m[1][n];
    z = dummy->m[2][n];
    //edges get drawn
    add_edge(points, x, y, z, x, y, z);
  }
}
Exemple #8
0
Fichier : draw.c Projet : stuydw/3d
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		double step ) {
  int length = 1 / pow(step, 2);
  if((length % 2) == 1)
    length++;
  struct matrix * temp = new_matrix(4,length);
  generate_torus(temp, cx, cy, r1, r2, step);
  double x, y, z;
  int t;
  for(t=0;t<temp->lastcol; t++){
    x = temp->m[0][t];
    y = temp->m[1][t];
    z = temp->m[2][t];
    add_edge(points, x, y, z, x, y, z);
  }
  free_matrix(temp);
}
Exemple #9
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
	double cx
	double cy
	double r1
	double r2
	double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
								double cx, double cy, double r1, double r2, 
								double step ) {
  struct matrix *temp;
  temp = new_matrix(4,1);

  generate_torus(temp, cx, cy, r1, r2, step);

  int col;
  for(col = 0; col < temp->cols; col++) {
    add_edge(points,
						 temp->m[0][col],
						 temp->m[1][col],
						 temp->m[2][col],
						 temp->m[0][col],
						 temp->m[1][col],
						 temp->m[2][col]);
  }
}
Exemple #10
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		double step ) {
  
  struct matrix * temp;
  int lat, longt;
  double ns;
  int steps;
  
  ns = 1.0 / step;
  steps = (int)ns;

  temp = new_matrix( 4, steps * steps );
  //generate the points on the torus
  generate_torus( temp, cx, cy, r1, r2, step );

    
  for ( lat = 0; lat < steps; lat++ ) {
    for ( longt = 0; longt < steps; longt++ ) {
      add_polygon(points, temp->m[0][(lat * steps) + (longt % steps)],
		  temp->m[1][(lat * steps) + (longt % steps)],
		  temp->m[2][(lat * steps) + (longt % steps)],
		  temp->m[0][(((lat + 1) % steps) * steps) + ((longt + 1) % steps)], 
		  temp->m[1][(((lat + 1) % steps) * steps) + ((longt + 1) % steps)], 
		  temp->m[2][(((lat + 1) % steps) * steps) + ((longt + 1) % steps)], 
		  temp->m[0][(lat * steps) + ((longt + 1) % steps)], 
		  temp->m[1][(lat * steps) + ((longt + 1) % steps)], 
		  temp->m[2][(lat * steps) + ((longt + 1) % steps)]);
      add_polygon(points,
		  temp->m[0][(lat * steps) + longt],
		  temp->m[1][(lat * steps) + longt],
		  temp->m[2][(lat * steps) + longt],
		  temp->m[0][(((lat + 1) % steps) * steps) + longt], 
		  temp->m[1][(((lat + 1) % steps) * steps) + longt], 
		  temp->m[2][(((lat + 1) % steps) * steps) + longt],  
		  temp->m[0][(((lat + 1) % steps) * steps) + ((longt + 1) % steps)],
		  temp->m[1][(((lat + 1) % steps) * steps) + ((longt + 1) % steps)],
		  temp->m[2][(((lat + 1) % steps) * steps) + ((longt + 1) % steps)]);
    }
  }
}
Exemple #11
0
void init()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glEnable(GL_BLEND);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
 
    glPointSize(1.7f);
    
    srand((unsigned)time(NULL));

    int size = 1600;

    scene_object::color_type color(0.1, 0.5, 1.0, 1.0);

    generate_sphere(g_object_sphere, color, 0.5f, size);
    generate_torus(g_object_torus, color, 0.5f, 0.1f, size);
    generate_cube(g_object_cube, color, 1.0f, size);
    generate_lines(g_object_lines, color, 0.5f, size);
    generate_spiral(g_object_spiral, color, 0.5f, size);
    generate_paraboloid(g_object_paraboloid, color, 0.5f, size);
    generate_chaos(g_object_chaos, color, 0.5f, size);
    
    g_objects.push_back(g_object_sphere);
    g_objects.push_back(g_object_torus);
    g_objects.push_back(g_object_lines);
    g_objects.push_back(g_object_cube);
    g_objects.push_back(g_object_spiral);
    g_objects.push_back(g_object_paraboloid);
    g_objects.push_back(g_object_chaos);

    g_object = g_objects[g_object_index];

    std::cout << "Number of points in the object : " << g_object.points.size() << std::endl;

    g_move_delta = 1.0f / MORPHING_STEPS;
}
Exemple #12
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double cz,
		double r1, double r2, 
		double step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double ns;
  int num_steps;
  
  ns = 1.0 / step;
  num_steps = (int)ns;

  temp = new_matrix( 4, num_steps * num_steps );
  //generate the points on the torus
  generate_torus( temp, cx, cy, cz, r1, r2, step );

  int num_points = temp->lastcol;

  int latStop, longStop, latStart, longStart;
  latStart = 0;
  longStart = 0;
  latStop = num_steps;
  longStop = num_steps;

  for ( lat = 0; lat < latStop; lat++ )
    for ( longt = 0; longt < longStop; longt++ ) {
      
      index = lat * num_steps + longt;
      
      if ( longt != num_steps-1) {
	add_polygon( points, temp->m[0][index],
		     temp->m[1][index],
		     temp->m[2][index],
		     temp->m[0][(index+num_steps+1) % num_points],
		     temp->m[1][(index+num_steps+1) % num_points],
		     temp->m[2][(index+num_steps+1) % num_points],
		     temp->m[0][index+1],
		     temp->m[1][index+1],
		     temp->m[2][index+1] );
	add_polygon( points, temp->m[0][index],
		     temp->m[1][index],
		     temp->m[2][index],
		     temp->m[0][(index+num_steps) % num_points],
		     temp->m[1][(index+num_steps) % num_points],
		     temp->m[2][(index+num_steps) % num_points],
		     temp->m[0][(index+num_steps) % num_points + 1],
		     temp->m[1][(index+num_steps) % num_points + 1],
		     temp->m[2][(index+num_steps) % num_points + 1]);
      }
      else {
	add_polygon( points, temp->m[0][index],
		     temp->m[1][index],
		     temp->m[2][index],
		     temp->m[0][(index+1) % num_points],
		     temp->m[1][(index+1) % num_points],
		     temp->m[2][(index+1) % num_points],
		     temp->m[0][index+1-num_steps],
		     temp->m[1][index+1-num_steps],
		     temp->m[2][index+1-num_steps] );
	add_polygon( points, temp->m[0][index],
		     temp->m[1][index],
		     temp->m[2][index],
		     temp->m[0][(index+num_steps) % num_points],
		     temp->m[1][(index+num_steps) % num_points],
		     temp->m[2][(index+num_steps) % num_points],
		     temp->m[0][(index+1) % num_points],
		     temp->m[1][(index+1) % num_points],
		     temp->m[2][(index+1) % num_points]);
      }

    }//end points only
}
Exemple #13
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void
add_torus (struct matrix *points,
	   double cx, double cy, double r1, double r2, double step)
{
  struct matrix *temp;
  int lat, longt;
  double ns;
  int num_steps;

  ns = 1.0 / step;
  num_steps = (int) ns;

  temp = new_matrix (4, (num_steps) * (num_steps + 1));

  //generate the points on the sphere
  generate_torus (temp, cx, cy, r1, r2, step);
  int latStop, longStop, latStart, longStart;
  latStart = 0;
  latStop = num_steps - 1;
  longStart = 0;
  longStop = num_steps - 1;

  for (lat = latStart; lat <= latStop; lat++)
    {
      for (longt = longStart; longt <= longStop; longt++)
	{
	  add_polygon (points,
		       temp->m[0][lat * num_steps + (longt % num_steps)],
		       temp->m[1][lat * num_steps + (longt % num_steps)],
		       temp->m[2][lat * num_steps + (longt % num_steps)],
		       temp->
		       m[0][(((lat + 1) % num_steps) * num_steps +
			     ((longt + 1) % num_steps))],
		       temp->
		       m[1][(((lat + 1) % num_steps) * num_steps +
			     ((longt + 1) % num_steps))],
		       temp->
		       m[2][(((lat + 1) % num_steps) * num_steps +
			     ((longt + 1) % num_steps))],
		       temp->
		       m[0][(lat * num_steps + ((longt + 1) % num_steps))],
		       temp->
		       m[1][(lat * num_steps + ((longt + 1) % num_steps))],
		       temp->
		       m[2][(lat * num_steps + ((longt + 1) % num_steps))]);

	  add_polygon (points,
		       temp->m[0][lat * num_steps + longt],
		       temp->m[1][lat * num_steps + longt],
		       temp->m[2][lat * num_steps + longt],
		       temp->
		       m[0][(((lat + 1) % num_steps) * num_steps + longt)],
		       temp->
		       m[1][(((lat + 1) % num_steps) * num_steps + longt)],
		       temp->
		       m[2][(((lat + 1) % num_steps) * num_steps + longt)],
		       temp->
		       m[0][(((lat + 1) % num_steps) * num_steps +
			     ((longt + 1) % num_steps))],
		       temp->
		       m[1][(((lat + 1) % num_steps) * num_steps +
			     ((longt + 1) % num_steps))],
		       temp->
		       m[2][(((lat + 1) % num_steps) * num_steps +
			     ((longt + 1) % num_steps))]);


	}
    }
//DONE
}
Exemple #14
0
/*======== void add_torus() ==========
	Inputs:   struct matrix * points
						double cx
			double cy
			double r1
			double r2
			double step  
	Returns: 

	adds all the points required to make a torus
	with center (cx, cy) and radii r1 and r2.

	should call generate_torus to create the
	necessary points

	03/22/12 13:34:03
	jdyrlandweaver
	====================*/
	void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		int step ) {

		struct matrix * temp;
		int lat, longt;
		int index;
		int num_steps;
		
		num_steps = MAX_STEPS / step;

		temp = new_matrix( 4, num_steps * num_steps );
	//generate the points on the torus
		generate_torus( temp, cx, cy, r1, r2, step );

		int latStop, longtStop, latStart, longStart;
		latStart = 0;
		longStart = 0;
		latStop = num_steps;
		longtStop = num_steps;
		for ( lat = latStart; lat < latStop; lat++ )
			for ( longt = longStart; longt < longtStop; longt++ ) {
				
				index = lat * num_steps + longt;
				
				if (lat == latStop - 1) {
					if (longt == longtStop - 1) {
						add_polygon(points, temp->m[0][index],
							temp->m[1][index],
							temp->m[2][index],
							temp->m[0][index - num_steps + 1],
							temp->m[1][index - num_steps + 1],
							temp->m[2][index - num_steps + 1],
							temp->m[0][latStart * num_steps + longStart],
							temp->m[1][latStart * num_steps + longStart],
							temp->m[2][latStart * num_steps + longStart]);			
						add_polygon(points, temp->m[0][index],
							temp->m[1][index],
							temp->m[2][index],
							temp->m[0][latStart * num_steps + longStart],
							temp->m[1][latStart * num_steps + longStart],
							temp->m[2][latStart * num_steps + longStart],
							temp->m[0][latStart * num_steps + num_steps - 1],
							temp->m[1][latStart * num_steps + num_steps - 1],
							temp->m[2][latStart * num_steps + num_steps - 1]);
					}
					else {
					add_polygon(points, temp->m[0][index],
						temp->m[1][index],
						temp->m[2][index],
						temp->m[0][latStart * num_steps + longt + 1],
						temp->m[1][latStart * num_steps + longt + 1],
						temp->m[2][latStart * num_steps + longt + 1],
						temp->m[0][latStart * num_steps + longt],
						temp->m[1][latStart * num_steps + longt],
						temp->m[2][latStart * num_steps + longt]);			
					add_polygon(points, temp->m[0][index],
						temp->m[1][index],
						temp->m[2][index],
						temp->m[0][index + 1],
						temp->m[1][index + 1],
						temp->m[2][index + 1],
						temp->m[0][latStart * num_steps + longt + 1],
						temp->m[1][latStart * num_steps + longt + 1],
						temp->m[2][latStart * num_steps + longt + 1]);
					}
				}
				else {
					if (longt == longtStop - 1) {
						add_polygon(points, temp->m[0][index],
							temp->m[1][index],
							temp->m[2][index],
							temp->m[0][index - num_steps + 1],
							temp->m[1][index - num_steps + 1],
							temp->m[2][index - num_steps + 1],
							temp->m[0][index + 1],
							temp->m[1][index + 1],
							temp->m[2][index + 1]);			
						add_polygon(points, temp->m[0][index],
							temp->m[1][index],
							temp->m[2][index],
							temp->m[0][index + 1],
							temp->m[1][index + 1],
							temp->m[2][index + 1],
							temp->m[0][index + num_steps],
							temp->m[1][index + num_steps],
							temp->m[2][index + num_steps]);
					}
					else {
					add_polygon(points, temp->m[0][index],
						temp->m[1][index],
						temp->m[2][index],
						temp->m[0][index + 1 + num_steps],
						temp->m[1][index + 1 + num_steps],
						temp->m[2][index + 1 + num_steps],
						temp->m[0][index + num_steps],
						temp->m[1][index + num_steps],
						temp->m[2][index + num_steps]);			
					add_polygon(points, temp->m[0][index],
						temp->m[1][index],
						temp->m[2][index],
						temp->m[0][index + 1],
						temp->m[1][index + 1],
						temp->m[2][index + 1],
						temp->m[0][index + 1 + num_steps],
						temp->m[1][index + 1 + num_steps],
						temp->m[2][index + 1 + num_steps]);
					}
				}
		}//end points only
	}
Exemple #15
0
/*======== void add_torus() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r1
	    double r2
	    double step  
  Returns: 

  adds all the points required to make a torus
  with center (cx, cy) and radii r1 and r2.

  should call generate_torus to create the
  necessary points

  03/22/12 13:34:03
  jdyrlandweaver
  ====================*/
void add_torus( struct matrix * points, 
		double cx, double cy, double r1, double r2, 
		int step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  int num_steps;
  
  num_steps = MAX_STEPS / step;

  temp = new_matrix( 4, num_steps * num_steps );
  //generate the points on the torus
  generate_torus( temp, cx, cy, r1, r2, step );

  int latStop, longStop, latStart, longStart;
  latStart = 0;
  longStart = 0;
  latStop = num_steps;
  longStop = num_steps;
  index = 0;

  int tmp = 0;

 for ( lat = latStart; lat < latStop; lat++ ) {
    if (tmp == (num_steps - 1)) {
      for ( longt = longStart; longt < longStop; longt++ ) { // 1 is longStop
	//      index = lat * (num_steps+1) + longt;
	if (index % num_steps == (num_steps - 1)) {
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][(index % num_steps)],
		       temp->m[1][(index % num_steps)],
		       temp->m[2][(index % num_steps)],
		       temp->m[0][0],
		       temp->m[1][0],
		       temp->m[2][0]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][0],
		       temp->m[1][0],
		       temp->m[2][0],
		       temp->m[0][index - (num_steps - 1)],
		       temp->m[1][index - (num_steps - 1)],
		       temp->m[2][index - (num_steps - 1)]
		       );
	}
	else {
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][(index % num_steps)],
		       temp->m[1][(index % num_steps)],
		       temp->m[2][(index % num_steps)],
		       temp->m[0][(index % num_steps) + 1],
		       temp->m[1][(index % num_steps) + 1],
		       temp->m[2][(index % num_steps) + 1]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][(index % num_steps) + 1],
		       temp->m[1][(index % num_steps) + 1],
		       temp->m[2][(index % num_steps) + 1],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1]
		       );
	}
	index += 1;
      }
    }
    else {
      for ( longt = longStart; longt < longStop; longt++ ) { // 1 is longStop
	//      index = lat * (num_steps+1) + longt;
	if (index % num_steps == (num_steps - 1)) {
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + num_steps],
		       temp->m[1][index + num_steps],
		       temp->m[2][index + num_steps],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1],
		       temp->m[0][index - (num_steps - 1)],
		       temp->m[1][index - (num_steps - 1)],
		       temp->m[2][index - (num_steps - 1)]
		       );
	}
	else {
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + num_steps],
		       temp->m[1][index + num_steps],
		       temp->m[2][index + num_steps],
		       temp->m[0][index + num_steps + 1],
		       temp->m[1][index + num_steps + 1],
		       temp->m[2][index + num_steps + 1]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + num_steps + 1],
		       temp->m[1][index + num_steps + 1],
		       temp->m[2][index + num_steps + 1],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1]
		       );
	}
	index += 1;
      }
    }
    tmp += 1;
 }

  
  /*      index = lat * num_steps + longt;
	  
	  add_edge( points, temp->m[0][index],
	  temp->m[1][index],
	  temp->m[2][index],
	  temp->m[0][index] + 1,
	  temp->m[1][index] + 1,
		temp->m[2][index] );
  */
  //end points only
}