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:08
report abuse | download | new post

  1. Cone::Cone(int n, int m) : Shape() {
  2.   if (n < 3)
  3.     n = 3;
  4.  
  5.   double x1,y1,z1,x2,y2,z2;
  6.   x1 = -0.5;
  7.   x2 = 0.5;
  8.   y1 = -0.5;
  9.   y2 = 0.5;
  10.   z1 = .5;
  11.   z2 = -.5;
  12.  
  13.   Point3 fixedPB( 0, y1, 0 ); //fixed point at the bottom
  14.   Point3 fixedPT( 0, y2, 0 ); //fixed point at the top
  15.   vector<Point3> circumPoints; //vector to hold circumference points
  16.  
  17.   //do the bottom first
  18.   //begin by solving the circumference points
  19.   float angle = 360/n; //get the angle interval
  20.   for( double i = 0; i < 360; i+=angle ) {
  21.  
  22.     double px = .5*cos( i * (PI/180) );
  23.     double pz = .5*sin( i * (PI/180) );
  24.  
  25.     Point3 circP( px, y2, pz );
  26.     circumPoints.push_back(circP);
  27.  
  28.   }
  29.  
  30.   //iterate through to create the bottom of the cone
  31.   for( int i = 0; i < n; i++ ) {
  32.  
  33.     int t = i;
  34.  
  35.     Point3 p1 = circumPoints.at(t);
  36.     if( t+1 == n )
  37.       t = -1;
  38.     Point3 p2 = circumPoints.at(t+1);
  39.  
  40.     p1.y = y1;
  41.     p2.y = y1;
  42.  
  43.     addTriangle( p1, p2, fixedPB );
  44.  
  45.   }
  46.  
  47.   /*
  48.    * to make the cone part, we start from the fixed point at the top
  49.    * and move down iterations of fy. the first iteration will not
  50.    * make a square, but all others will.
  51.    */
  52.   float f = m-1;
  53.   for( int i = 0; i < n; i++ ) {
  54.  
  55.     int t = i;
  56.     //grab the first 2 circumference points
  57.     Point3 p1 = circumPoints.at(t);
  58.     if(t+1 == n) {
  59.       t = -1; //go back to the beginning of the vector
  60.     }
  61.     Point3 p2 = circumPoints.at(t+1);
  62.     p1.y = y1;
  63.     p2.y = y1;
  64.     Point3 tempr = p1;
  65.     Point3 templ = p2;
  66.  
  67.     for( int i = 0; i < m; i++ ) {
  68.       float fact = f/m;
  69.       float npy = (1-fact)*p1.y + fact*fixedPT.y;
  70.       float npzr = (1-fact)*p1.z + fact*fixedPT.z;
  71.       float npzl = (1-fact)*p2.z + fact*fixedPT.z;
  72.       float npxr = (1-fact)*p1.x + fact*fixedPT.x;
  73.       float npxl = (1-fact)*p2.x + fact*fixedPT.x;
  74.  
  75.       Point3 uppR( npxr, npy, (-1)*npzr );
  76.       Point3 uppL( npxl, npy, (-1)*npzl );
  77.  
  78.       if( i == 0 ) { //first iteration, so build a triangle at the top
  79.         addTriangle( uppL, fixedPT, uppR );
  80.       } else {            //all other iterations make squares
  81.         addSquare( uppR, uppL, templ, tempr );
  82.       }
  83.  
  84.       tempr = uppR;
  85.       templ = uppL;
  86.       f--;
  87.     }
  88.     f = m-1;
  89.   }
  90.  
  91. }

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