Exemplo n.º 1
0
  /*======== void add_sphere() ==========
Inputs: struct matrix * points
double cx
double cy
double r
double step
Returns:

adds all the points for a sphere with center
(cx, cy) and radius r.

should call generate_sphere to create the
necessary points

jdyrlandweaver
====================*/
  void add_sphere( struct matrix * points,
double cx, double cy, double r,
double step ) {
    struct matrix * temp;
    int lt, lng;
    // int num_steps = (int) (1.0 / step); why does this break?
    double f = 1.0 / step;
    int num_steps = (int) f;
    int fg = num_steps + 1;
    temp = new_matrix(4, num_steps * (num_steps + 1));
    generate_sphere(temp, cx, cy, r, step);
    for (lt = 0 ; lt <= num_steps - 1 ; lt++) {
      for (lng = 0 ; lng <= num_steps - 1; lng++) {
        add_polygon(points, temp->m[0][lt * fg +lng % fg],
                    temp->m[1][lt * fg + lng % fg],
                    temp->m[2][lt* fg + lng % fg],
                    temp->m[0][((lt + 1) % num_steps) * fg + (lng + 1) % fg],
                    temp->m[1][((lt + 1) % num_steps)* fg + (lng + 1) % fg],
                    temp->m[2][((lt + 1) % num_steps)* fg + (lng + 1) % fg],
                    temp->m[0][lt * fg + (lng + 1) % fg],
                    temp->m[1][lt * fg + (lng + 1) % fg],
                    temp->m[2][lt * fg + (lng + 1) % fg]);
        add_polygon(points, temp->m[0][lt * fg + lng],
                    temp->m[1][lt * fg +lng], temp->m[2][lt * fg + lng],
                    temp->m[0][((lt + 1) % num_steps) * fg + lng],
                    temp->m[1][((lt + 1) % num_steps) * fg + lng],
                    temp->m[2][((lt + 1) % num_steps) * fg + lng],
                    temp->m[0][((lt + 1) % num_steps) * fg + (lng + 1) % fg],
                    temp->m[1][((lt + 1) % num_steps) * fg + (lng + 1) % fg],
                    temp->m[2][((lt + 1) % num_steps) * fg + (lng + 1) % fg]);
      }
    }
  }
Exemplo n.º 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);

}
Exemplo n.º 3
0
/*======== void add_sphere() ==========
	Inputs:   struct matrix * points
						double cx
			double cy
			double r
			double step  
	Returns: 

	adds all the points for a sphere with center 
	(cx, cy) and radius r.

	should call generate_sphere to create the
	necessary points

	jdyrlandweaver
	====================*/
	void add_sphere( struct matrix * points, 
		double cx, double cy, double r, 
		int step ) {

		struct matrix * temp;
		int lat, longt;
		int index, index2;
		double x, y, z;
		int num_steps;
		
		num_steps = MAX_STEPS / step;

		temp = new_matrix( 4, num_steps * num_steps );
	//generate the points on the sphere
		generate_sphere( temp, cx, cy, r, step );

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

		for ( lat = latStart; lat < latStop; lat++ ) {
			for ( longt = longStart; longt * 2 < longStop; longt++ ) {
				
				index = lat * num_steps + longt;
				index2 = index + num_steps;
				if (lat == latStop - 1) {				
					index2 = latStart * num_steps + longt;
				}
				add_polygon(points, temp->m[0][index],
					temp->m[1][index],
					temp->m[2][index],
					temp->m[0][index2 + 1],
					temp->m[1][index2 + 1],
					temp->m[2][index2 + 1],
					temp->m[0][index2],
					temp->m[1][index2],
					temp->m[2][index2]);			
				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][index2 + 1],
					temp->m[1][index2 + 1],
					temp->m[2][index2 + 1]);
			}
		}
		free_matrix(temp);
}
Exemplo n.º 4
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]);
        }
    }
}
Exemplo n.º 5
0
  /*======== void add_sphere() ==========
    Inputs:   struct matrix * points
    double cx
    double cy
    double r
    double step  
    Returns: 

    adds all the points for a sphere with center 
    (cx, cy) and radius r.

    should call generate_sphere to create the
    necessary points

    jdyrlandweaver
    ====================*/
  void add_sphere( struct matrix * points, 
		   double cx, double cy, double r, 
		   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+1) );
    //generate the points on the sphere
    generate_sphere( temp, cx, cy, r, step );
    int latStop, longStop, latStart, longStart;
    latStart = 0;
    latStop = num_steps-1;
    longStart = 0;
    longStop = num_steps-1;
    index = num_steps+1;
  
    for ( lat = latStart; lat <= latStop; lat++ ) {
      for ( longt = longStart; longt <= longStop; longt++ ) {
	add_polygon(points,
		    temp->m[0][lat*index+longt%index], 
		    temp->m[1][lat*index+longt%index], 
		    temp->m[2][lat*index+longt%index],
		    temp->m[0][((lat+1) % num_steps)*index+(longt+1) % index],
		    temp->m[1][((lat+1) % num_steps)*index+(longt+1) % index],
		    temp->m[2][((lat+1) % num_steps)*index+(longt+1) % index],
		    temp->m[0][lat*index+(longt+1) % index],
		    temp->m[1][lat*index+(longt+1) % index],
		    temp->m[2][lat*index+(longt+1) % index]);
	add_polygon(points,
		    temp->m[0][lat*index+longt],
		    temp->m[1][lat*index+longt],
		    temp->m[2][lat*index+longt],
		    temp->m[0][((lat+1) % num_steps)*index + longt],
		    temp->m[1][((lat+1) % num_steps)*index + longt],
		    temp->m[2][((lat+1) % num_steps)*index + longt],
		    temp->m[0][((lat+1) % num_steps)*index + (longt+1) % index],
		    temp->m[1][((lat+1) % num_steps)*index + (longt+1) % index],
		    temp->m[2][((lat+1) % num_steps)*index + (longt+1) % index]);  
      }
    }
  }
Exemplo n.º 6
0
void NavigationMesh::create_from_mesh(const Ref<Mesh>& p_mesh) {


	vertices=PoolVector<Vector3>();
	clear_polygons();

	for(int i=0;i<p_mesh->get_surface_count();i++) {

		if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
			continue;
		Array arr = p_mesh->surface_get_arrays(i);
		PoolVector<Vector3> varr = arr[Mesh::ARRAY_VERTEX];
		PoolVector<int> iarr = arr[Mesh::ARRAY_INDEX];
		if (varr.size()==0 || iarr.size()==0)
			continue;

		int from = vertices.size();
		vertices.append_array(varr);
		int rlen = iarr.size();
		PoolVector<int>::Read r = iarr.read();

		for(int j=0;j<rlen;j+=3) {
			Vector<int> vi;
			vi.resize(3);
			vi[0]=r[j+0]+from;
			vi[1]=r[j+1]+from;
			vi[2]=r[j+2]+from;

			add_polygon(vi);
		}
	}
}
Exemplo n.º 7
0
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 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+1) );

  //generate the points on the sphere
  generate_sphere( temp, cx, cy, r, step );
  for(lat = 0; lat < steps; lat++){
    for(longt = 0; longt < steps; longt++){
      add_polygon(points,
		  temp->m[0][(lat * (steps + 1)) + (longt % (steps + 1))],
		  temp->m[1][(lat * (steps + 1)) + (longt % (steps + 1))],
		  temp->m[2][(lat * (steps + 1)) + (longt % (steps + 1))],
		  temp->m[0][(((lat + 1) % steps) * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[1][(((lat + 1) % steps) * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[2][(((lat + 1) % steps) * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[0][(lat * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[1][(lat * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[2][(lat * (steps + 1)) + ((longt + 1) % (steps + 1))]);
      add_polygon(points,
		  temp->m[0][(lat * (steps + 1)) + longt],
		  temp->m[1][(lat * (steps + 1)) + longt],
		  temp->m[2][(lat * (steps + 1)) + longt],
		  temp->m[0][(((lat + 1) % steps) * (steps + 1)) + longt],
		  temp->m[1][(((lat + 1) % steps) * (steps + 1)) + longt],
		  temp->m[2][(((lat + 1) % steps) * (steps + 1)) + longt],

		  temp->m[0][(((lat + 1) % steps) * (steps + 1)) + ((longt+1) % (steps + 1))],
		  temp->m[1][(((lat + 1) % steps) * (steps + 1)) + ((longt+1) % (steps + 1))],
		  temp->m[2][(((lat + 1) % steps) * (steps + 1)) + ((longt+1) % (steps + 1))]);
    }
  }

}
Exemplo n.º 8
0
Arquivo: draw.c Projeto: Wayez/polygon
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 int step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double x, y, z;
  int num_steps;
  
  num_steps = MAX_STEPS / step;

  temp = new_matrix( 4, num_steps * num_steps );
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, r, step );

  int latStop, longStop, latStart, longStart;
  latStart = 0;
  latStop = num_steps;
  longStart = 0;
  longStop = num_steps;
  
  for ( lat = latStart; lat < latStop; lat++ ) {
    for ( longt = longStart; longt < longStop; longt++ ) {
      
      index = lat * 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][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 + num_steps], temp->m[1][index + num_steps], temp->m[2][index + num_steps]);
      /*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
  }
  free_matrix(temp);
}
Exemplo n.º 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;
  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)]);
    }
  }
}
Exemplo n.º 10
0
 void partition() {
   TPPLPoly poly;
   std::vector<Point> nodes = polygons_[0].nodes_;
   poly.Init(nodes.size());
   unsigned int i = 0;
   for (std::vector<Point>::const_iterator p = nodes.begin(); p != nodes.end(); ++p, ++i) {
     poly[i].x = p->lat;
     poly[i].y = p->lon;
   }
   std::list<TPPLPoly> convex_polys;
   TPPLPartition partitioner;
   partitioner.Triangulate_OPT(&poly, &convex_polys);
   //partitioner.ConvexPartition_HM(&poly, &convex_polys);
   polygons_.clear();
   for (std::list<TPPLPoly>::iterator p = convex_polys.begin(); p != convex_polys.end(); ++p) {
     add_polygon();
     for (long i = 0; i < p->GetNumPoints(); ++i) {
       TPPLPoint point = p->GetPoint(i);
       add_node(Point(point.x, point.y));
     }
   }
 }
Exemplo n.º 11
0
static int
drawpolygon(struct render_buffer *rb, struct pack_polygon *poly, const struct sprite_trans *arg) {
	struct matrix tmp;
	int i,j;
	if (arg->mat == NULL) {
		matrix_identity(&tmp);
	} else {
		tmp = *arg->mat;
	}
	int *m = tmp.m;
	int object = rb->object;
	for (i=0;i<poly->n;i++) {
		struct pack_poly *p = &poly->poly[i];
		if (update_tex(rb, p->texid)) {
			rb->object = object;
			return -1;
		}

		int pn = p->n;

		ARRAY(struct vertex_pack, vb, pn);

		for (j=0;j<pn;j++) {
			int xx = p->screen_coord[j*2+0];
			int yy = p->screen_coord[j*2+1];
		
			vb[j].vx = (xx * m[0] + yy * m[2]) / 1024 + m[4];
			vb[j].vy = (xx * m[1] + yy * m[3]) / 1024 + m[5];
			vb[j].tx = p->texture_coord[j*2+0];
			vb[j].ty = p->texture_coord[j*2+1];
		}
		if (add_polygon(rb, pn, vb, arg->color, arg->additive)) {
			rb->object = object;
			return 1;
		}
	}
	return 0;
}
Exemplo n.º 12
0
  /*======== void add_box() ==========
Inputs: struct matrix * points
double x
double y
double z
double width
double height
double depth
Returns:

add the points for a rectagular prism whose
upper-left corner is (x, y, z) with width,
height and depth dimensions.

jdyrlandweaver
====================*/
void add_box( struct matrix *points,
double x, double y, double z,
double width, double height, double depth ) {
  add_polygon(points, x, y, z, x, y - height, z, x + width, y, z);
  add_polygon(points, x + width, y, z, x, y - height, z, x + width, y - height, z);
  add_polygon(points, x + width, y, z, x + width, y - height, z, x + width, y - height, z - depth);
  add_polygon(points, x + width, y, z, x + width, y - height, z - depth, x + height, y, z - depth);
  add_polygon(points, x + width, y, z, x + width, y, z - depth, x, y, z - depth);
  add_polygon(points, x + width, y, z, x, y, z - depth, x, y, z);
  add_polygon(points, x, y - height, z - depth, x + width, y, z - depth, x + width, y - height, z - depth);
  add_polygon(points, x, y - height, z - depth, x + width, y - height, z - depth, x + width, y - height, z);
  add_polygon(points, x, y - height, z - depth, x + width, y - height, z, x, y - height, z);
  add_polygon(points, x, y, z, x, y - height, z - depth, x, y - height, z);
  add_polygon(points, x, y, z, x, y, z - depth, x, y - height, z - depth);
  add_polygon(points, x, y - height, z - depth, x, y, z - depth, x + width, y, z - depth);
}
Exemplo n.º 13
0
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double cz, double r, 
		 int step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  int num_steps, num_points;
  double px0, px1, px2, px3;
  double py0, py1, py2, py3;
  double pz0, pz1, pz2, pz3;

  num_steps = MAX_STEPS / step;
  num_points = num_steps * (num_steps + 1);
  
  temp = new_matrix( 4, num_points);
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, cz, r, step );

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

  num_steps++;

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

      px0 = temp->m[0][ index ];
      py0 = temp->m[1][ index ];
      pz0 = temp->m[2][ index ];
      
      px1 = temp->m[0][ (index + num_steps) % num_points ];
      py1 = temp->m[1][ (index + num_steps) % num_points ];
      pz1 = temp->m[2][ (index + num_steps) % num_points ];

      px3 = temp->m[0][ index + 1 ];
      py3 = temp->m[1][ index + 1 ];
      pz3 = temp->m[2][ index + 1 ];

      if (longt != longStop - 1) {
	px2 = temp->m[0][ (index + num_steps + 1) % num_points ];
	py2 = temp->m[1][ (index + num_steps + 1) % num_points ];
	pz2 = temp->m[2][ (index + num_steps + 1) % num_points ];
      }
      else {
	px2 = temp->m[0][ (index + 1) % num_points ];
	py2 = temp->m[1][ (index + 1) % num_points ];
	pz2 = temp->m[2][ (index + 1) % num_points ];
      }

      if (longt != 0)
	add_polygon( points, px0, py0, pz0, px1, py1, pz1, px2, py2, pz2 );
      if (longt != longStop - 1)
	add_polygon( points, px2, py2, pz2, px3, py3, pz3, px0, py0, pz0 );
    }
  }
}
Exemplo n.º 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, 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
}
Exemplo n.º 15
0
Arquivo: draw.c Projeto: stuydw/mdl
/*======== 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
}
Exemplo n.º 16
0
/*======== void add_box() ==========
  Inputs:   struct matrix * points
            double x
	    double y
	    double z
	    double width
	    double height
	    double depth
  Returns: 

  add the points for a rectagular prism whose 
  upper-left corner is (x, y, z) with width, 
  height and depth dimensions.

  jdyrlandweaver
  ====================*/
void
add_box (struct matrix *points,
	 double x, double y, double z,
	 double width, double height, double depth)
{
  double x2, y2, z2;
  x2 = x + width;
  y2 = y - height;
  z2 = z - depth;

  add_polygon (points, x, y, z, x, y2, z, x2, y, z);
  add_polygon (points, x2, y, z, x, y2, z, x2, y2, z);
  add_polygon (points, x2, y, z, x2, y2, z, x2, y2, z2);
  add_polygon (points, x2, y, z, x2, y2, z2, x2, y, z2);
  add_polygon (points, x2, y, z, x2, y, z2, x, y, z2);
  add_polygon (points, x2, y, z, x, y, z2, x, y, z);
  add_polygon (points, x, y2, z2, x2, y, z2, x2, y2, z2);
  add_polygon (points, x, y2, z2, x2, y2, z2, x2, y2, z);
  add_polygon (points, x, y2, z2, x2, y2, z, x, y2, z);
  add_polygon (points, x, y, z, x, y2, z2, x, y2, z);
  add_polygon (points, x, y, z, x, y, z2, x, y2, z2);
  add_polygon (points, x, y2, z2, x, y, z2, x2, y, z2);
//DONE
}
Exemplo n.º 17
0
Arquivo: draw.c Projeto: stuydw/final
/*======== void add_box() ==========
Inputs: struct matrix * points
double x
double y
double z
double width
double height
double depth
Returns:

add the points for a rectagular prism whose
upper-left corner is (x, y, z) with width,
height and depth dimensions.

jdyrlandweaver
====================*/
void add_box( struct matrix * polygons,
              double x, double y, double z,
              double width, double height, double depth ) {

    double x2, y2, z2;
    x2 = x + width;
    y2 = y - height;
    z2 = z - depth;

    //front
    add_polygon( polygons,
                 x, y, z,
                 x, y2, z,
                 x2, y2, z);
    add_polygon( polygons,
                 x2, y2, z,
                 x2, y, z,
                 x, y, z);
    //back
    add_polygon( polygons,
                 x2, y, z2,
                 x2, y2, z2,
                 x, y2, z2);
    add_polygon( polygons,
                 x, y2, z2,
                 x, y, z2,
                 x2, y, z2);
    //top
    add_polygon( polygons,
                 x, y, z2,
                 x, y, z,
                 x2, y, z);
    add_polygon( polygons,
                 x2, y, z,
                 x2, y, z2,
                 x, y, z2);
    //bottom
    add_polygon( polygons,
                 x2, y2, z2,
                 x2, y2, z,
                 x, y2, z);
    add_polygon( polygons,
                 x, y2, z,
                 x, y2, z2,
                 x2, y2, z2);
    //right side
    add_polygon( polygons,
                 x2, y, z,
                 x2, y2, z,
                 x2, y2, z2);
    add_polygon( polygons,
                 x2, y2, z2,
                 x2, y, z2,
                 x2, y, z);
    //left side
    add_polygon( polygons,
                 x, y, z2,
                 x, y2, z2,
                 x, y2, z);
    add_polygon( polygons,
                 x, y2, z,
                 x, y, z,
                 x, y, z2);
}
Exemplo n.º 18
0
/*======== void add_box() ==========
 Inputs:   struct matrix * points
 double x
 double y
 double z
 double width
 double height
 double depth
 Returns:
 
 add the points for a rectagular prism whose
 upper-left corner is (x, y, z) with width,
 height and depth dimensions.
 
 jdyrlandweaver
 ====================*/
void add_box( struct matrix *points,
             double x, double y, double z,
             double width, double height, double depth ) {
    double x2, y2, z2;
    x2 = x + width;
    y2 = y + height;
    z2 = z - depth;

    //Front
    add_polygon( points, x, y, z, x2, y, z, x2, y2, z );
    add_polygon( points, x, y, z, x2, y2, z, x, y2, z );
    
    //Back
    add_polygon( points, x2, y, z2, x2, y2, z2, x, y2, z2 );
    add_polygon( points, x2, y, z2, x, y2, z2, x, y, z2 );
    
    //Left
    add_polygon( points, x, y, z2, x, y2, z2, x, y2, z );
    add_polygon( points, x, y, z2, x, y2, z, x, y, z );
    
    //Right
    add_polygon( points, x2, y, z, x2, y2, z, x2, y2, z2 );
    add_polygon( points, x2, y, z, x2, y2, z2, x2, y, z2 );
    
    //Top
    add_polygon( points, x, y, z2, x, y, z, x2, y, z );
    add_polygon( points, x, y, z2, x2, y, z, x2, y, z2 );
    
    //Bottom
    add_polygon( points, x, y2, z, x, y2, z2, x2, y2, z2 );
    add_polygon( points, x, y2, z, x2, y2, z2, x2, y2, z );
    
    /*
     add_edge( points,
     x, y, z,
     x, y, z );
     add_edge( points,
     x, y2, z,
     x, y2, z );
     add_edge( points,
     x2, y, z,
     x2, y, z );
     add_edge( points,
     x2, y2, z,
     x2, y2, z );
     add_edge( points,
     x, y, z2,
     x, y, z2 );
     add_edge( points,
     x, y2, z2,
     x, y2, z2 );
     add_edge( points,
     x2, y, z2,
     x2, y, z2 );
     add_edge( points,
     x2, y2, z2,
     x2, y2, z2 );
     */
}
Exemplo n.º 19
0
  /*======== void add_box() ==========
    Inputs:   struct matrix * points
    double x
    double y
    double z
    double width
    double height
    double depth
    Returns: 

    add the points for a rectagular prism whose 
    upper-left corner is (x, y, z) with width, 
    height and depth dimensions.

    jdyrlandweaver
    ====================*/
void add_box( struct matrix *points,
	      double x, double y, double z,
	      double width, double height, double depth ) {

  //F = front; B = back; L = left side; R = right side; T = top; U = underside

  double x1 = x+width;
  double y1 = y-height;
  double z1 = z+depth;

  add_polygon( points, x,y,z, x,y1,z, x1,y1,z); //F1
  add_polygon( points, x,y,z, x1,y1,z, x1,y,z); //F2
  add_polygon( points, x,y,z1, x1,y,z1, x,y1,z1 ); //B1
  add_polygon( points, x1,y,z1, x1,y1,z1, x,y1,z1 ); //B2
  add_polygon( points, x,y,z1, x,y1,z1, x,y1,z ); //L1
  add_polygon( points, x,y1,z, x,y,z, x,y,z1 );//L2
  add_polygon( points, x1,y,z, x1,y1,z, x1,y1,z1 ); //R1
  add_polygon( points, x1,y,z, x1,y1,z1, x1,y1,z1 ); //R2
  add_polygon( points, x,y,z1, x,y,z, x1,y,z ); //U1
  add_polygon( points, x1,y,z, x1,y,z1, x,y,z1 ); //U2
  add_polygon( points, x1,y1,z1, x1,y1,z, x,y1,z ); //B1
  add_polygon( points, x,y1,z, x,y1,z1, x1,y1,z1 ); //B2

  /*double x2, y2, z2;
    x2 = x + width;
    y2 = y - height;
    z2 = z - depth;

    add_edge( points, 
    x, y, z, 
    x, y, z );
    add_edge( points, 
    x, y2, z, 
    x, y2, z );
    add_edge( points, 
    x2, y, z, 
    x2, y, z );
    add_edge( points, 
    x2, y2, z, 
    x2, y2, z );
    add_edge( points, 
    x, y, z2, 
    x, y, z2 );
    add_edge( points, 
    x, y2, z2, 
    x, y2, z2 );
    add_edge( points, 
    x2, y, z2, 
    x2, y, z2 );
    add_edge( points, 
    x2, y2, z2, 
    x2, y2, z2 );*/
}
Exemplo n.º 20
0
 void add_node(const Point& node) {
   if (polygons_.size() == 0) add_polygon();
   polygons_[polygons_.size()-1].add_node(node);
 }
Exemplo n.º 21
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]);   
      */
      
      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))]
		  );     

  
    }
  }
}
Exemplo n.º 22
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
}
Exemplo n.º 23
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
	}
Exemplo n.º 24
0
Arquivo: draw.c Projeto: stuydw/mdl
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double cz, double r, 
		 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+1) );
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, cz, r, step );
  num_steps++;
  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++ ) {
      
      index = lat * (num_steps) + longt;

      if ( lat == num_steps - 2) {
	add_polygon( points, temp->m[0][index],
		     temp->m[1][index],
		     temp->m[2][index],
		     temp->m[0][longt],
		     temp->m[1][longt],
		     temp->m[2][longt],
		     temp->m[0][longt+1],
		     temp->m[1][longt+1],
		     temp->m[2][longt+1]);
	if ( longt != num_steps - 2 ) {
	  add_polygon( points, 
		       temp->m[0][longt+1],
		       temp->m[1][longt+1],
		       temp->m[2][longt+1],
		       temp->m[0][index+1],
		       temp->m[1][index+1],
		       temp->m[2][index+1],
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index]);
	}
      }//end edge case
      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]);
	if ( longt != num_steps - 2 ) {
	  add_polygon( points, 
		       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],
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index]);
	}
      }//end not last full rotation
    }
  }
}
Exemplo n.º 25
0
/*======== void add_box() ==========
	Inputs:   struct matrix * points
						double x
			double y
			double z
			double width
			double height
			double depth
	Returns: 

	add the points for a rectagular prism whose 
	upper-left corner is (x, y, z) with width, 
	height and depth dimensions.

	jdyrlandweaver
	====================*/
	void add_box( struct matrix * points,
		double x, double y, double z,
		double width, double height, double depth ) {

		double x2, y2, z2;
		x2 = x + width;
		y2 = y - height;
		z2 = z - depth;

		add_polygon(points, x,y,z, x,y2,z, x2,y2,z);//front
		add_polygon(points, x,y,z, x2,y2,z, x2,y,z);
		add_polygon(points, x2,y,z2, x,y2,z2, x,y,z2);//back
		add_polygon(points, x2,y,z2, x2,y2,z2, x,y2,z2);
		add_polygon(points, x,y,z2, x,y,z, x2,y,z);//top
		add_polygon(points, x,y,z2, x2,y,z, x2,y,z2);
		add_polygon(points, x,y2,z, x,y2,z2, x2,y2,z2);//bot
		add_polygon(points, x,y2,z, x2,y2,z2, x2,y2,z);
		add_polygon(points, x,y,z2, x,y2,z2, x,y2,z);//left
		add_polygon(points, x,y,z2, x,y2,z, x,y,z);
		add_polygon(points, x2,y,z, x2,y2,z, x2,y2,z2);//right
		add_polygon(points, x2,y,z, x2,y2,z2, x2,y,z2);

		// add_edge( points, 
		// 	x, y, z, 
		// 	x, y, z );
		// add_edge( points, 
		// 	x, y2, z, 
		// 	x, y2, z );
		// add_edge( points, 
		// 	x2, y, z, 
		// 	x2, y, z );
		// add_edge( points, 
		// 	x2, y2, z, 
		// 	x2, y2, z );
		// add_edge( points, 
		// 	x, y, z2, 
		// 	x, y, z2 );
		// add_edge( points, 
		// 	x, y2, z2, 
		// 	x, y2, z2 );
		// add_edge( points, 
		// 	x2, y, z2, 
		// 	x2, y, z2 );
		// add_edge( points, 
		// 	x2, y2, z2, 
		// 	x2, y2, z2 );
	}
Exemplo n.º 26
0
Arquivo: draw.c Projeto: stuydw/mdl
/*======== void add_box() ==========
  Inputs:   struct matrix * points
            double x
	    double y
	    double z
	    double width
	    double height
	    double depth
  Returns: 

  add the points for a rectagular prism whose 
  upper-left corner is (x, y, z) with width, 
  height and depth dimensions.

  jdyrlandweaver
  ====================*/
void add_box( struct matrix * polygons,
	      double x, double y, double z,
	      double width, double height, double depth ) {

  double x2, y2, z2;
  x2 = x + width;
  y2 = y - height;
  z2 = z - depth;


if (width < 0){//shows backends only otherwise
add_box(polygons,x2,y,z,-1 * width, height, depth);
return;
}
if (depth < 0){
add_box(polygons,x,y,z2,width, height, -1 * depth);
return;
}
if (height < 0){
add_box(polygons,x,y2,z,width, -1 * height, depth);
return;
}



  //front
  add_polygon( polygons, 
	       x, y, z, 
	       x, y2, z,
	       x2, y2, z);
  add_polygon( polygons, 
	       x2, y2, z, 
	       x2, y, z,
	       x, y, z);
  //back
  add_polygon( polygons, 
	       x2, y, z2, 
	       x2, y2, z2,
	       x, y2, z2);
  add_polygon( polygons, 
	       x, y2, z2, 
	       x, y, z2,
	       x2, y, z2);
  //top
  add_polygon( polygons, 
	       x, y, z2, 
	       x, y, z,
	       x2, y, z);
  add_polygon( polygons, 
	       x2, y, z, 
	       x2, y, z2,
	       x, y, z2);
  //bottom
  add_polygon( polygons, 
	       x2, y2, z2, 
	       x2, y2, z,
	       x, y2, z);
  add_polygon( polygons, 
	       x, y2, z, 
	       x, y2, z2,
	       x2, y2, z2);
  //right side
  add_polygon( polygons, 
	       x2, y, z, 
	       x2, y2, z,
	       x2, y2, z2);
  add_polygon( polygons, 
	       x2, y2, z2, 
	       x2, y, z2,
	       x2, y, z);
  //left side
  add_polygon( polygons, 
	       x, y, z2, 
	       x, y2, z2,
	       x, y2, z);
  add_polygon( polygons, 
	       x, y2, z, 
	       x, y, z,
	       x, y, z2); 
}
Exemplo n.º 27
0
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 int step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double x, y, z;
  int num_steps;
  
  num_steps = MAX_STEPS / step;

  temp = new_matrix( 4, num_steps * num_steps );
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, r, step );

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

  /*print_points(temp);

  printf("\n\n\n\n\n\n\n\n");
  */
  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
	//	printf("index: %d\n", index);
	//      index = lat * (num_steps+1) + longt;
	if (index % num_steps == (num_steps - 1)) {
	  /*	  printf("Special case\n");
	  printf("connection indices: %f, %f, %f\n", index, index + num_steps, index + 1);
	  printf("connection indices: %f, %f, %f\n", index, index + 1, index - (num_steps - 1));
	  printf("index point: %f, %f, %f\n", temp->m[0][index] , temp->m[1][index], temp->m[2][index]);
	  printf("index + num_steps point, %f, %f, %f\n", temp->m[0][index + num_steps], temp->m[1][index + num_steps], temp->m[2][index + num_steps]);
	  printf("NEXT\n");*/
	  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 {
	  /*	  printf("index point: %f, %f, %f\n", temp->m[0][index], temp->m[1][index], temp->m[2][index]);
	  printf("index + num_steps point, %f, %f, %f\n", temp->m[0][index + num_steps], temp->m[1][index + num_steps], temp->m[2][index + num_steps]);
	  printf("connection indices: %f, %f, %f\n", index, index + num_steps, index + num_steps + 1);
	  printf("connection indices: %f, %f, %f\n", index, index + num_steps + 1, index + 1);*/
	  //	  printf("NEXT\n");
	  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;
  }
      
      /*      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

  /*  printf("\n\n\n\n");
      print_matrix(points);*/

  free_matrix(temp);
}