pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C++ pastebin - collaborative debugging tool View Help


Posted by Fourth on Mon 17 Nov 15:05
report abuse | download | new post

  1. Cylinder::Cylinder(int n, int m) : Shape() {
  2.   if (n < 3)
  3.     n = 3;
  4.  
  5.   //n is the tessellation factor of the cylinder itself
  6.   //m is the tessellation factor on the sides
  7.  
  8.   double x1,y1,z1,x2,y2,z2;
  9.   x1 = -0.5;
  10.   x2 = 0.5;
  11.   y1 = -0.5;
  12.   y2 = 0.5;
  13.   z1 = .5;
  14.   z2 = -.5;
  15.  
  16.   Point3 fixedPT( 0, y2, 0 );
  17.   Point3 fixedPB( 0, y1, 0 );
  18.   vector<Point3> circumPoints; //vector to hold circumference points
  19.  
  20.   //begin with the top and bottom
  21.   //while n > 0, add points to the circumference and try triangles
  22.   float angle = 360/n; //get the angle interval
  23.  
  24.   for( double i = 0; i < 360; i+=angle ) {
  25.  
  26.     double px = .5*cos( i * (PI/180) );
  27.     double pz = .5*sin( i * (PI/180) );
  28.  
  29.     Point3 circP( px, y2, pz );
  30.     circumPoints.push_back(circP);
  31.  
  32.   }
  33.  
  34.  
  35.   //iterate through to make the top and the bottom
  36.   for( int i = 0; i < n; i++ ) {
  37.  
  38.     int t = i;
  39.  
  40.     Point3 p1 = circumPoints.at(t);
  41.     if( t+1 == n )
  42.       t = -1;
  43.     Point3 p2 = circumPoints.at(t+1);
  44.  
  45.     addTriangle( p2, p1, fixedPT );
  46.  
  47.     p1.y = y1;
  48.     p2.y = y1;
  49.  
  50.     addTriangle( p1, p2, fixedPB );
  51.  
  52.   }
  53.  
  54.   //for each circumference point and the next circumference point
  55.   //draw squares all the way down
  56.   float fy = m-1;
  57.   for( int x = 0; x < n; x++ ) { //number of faces
  58.  
  59.     int t = x;
  60.     //grab the first 2 circumference points
  61.     Point3 p1 = circumPoints.at(t);
  62.     if(t+1 == n) {
  63.       t = -1; //go back to the beginning of the vector
  64.     }
  65.     Point3 p2 = circumPoints.at(t+1);
  66.     Point3 p3 = p2;
  67.     Point3 temp = p2;
  68.     p3.y = y1;
  69.  
  70.     for( int i = 0; i < m; i++ ) {
  71.       float facty = fy/m;
  72.       float npy = (1-facty)*p3.y + facty*p2.y;
  73.  
  74.       Point3 lowR( p1.x, npy, p1.z );
  75.       Point3 midP( temp.x, npy, temp.z );
  76.  
  77.       addSquare( p1, temp, midP, lowR );
  78.  
  79.       p1 = lowR;
  80.       temp = midP;
  81.       fy--;
  82.     }
  83.     fy = m-1;
  84.   }
  85.  
  86. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post