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 14:59
report abuse | View followups from Vectorxx | download | new post

  1. Cube::Cube(int n) : Shape() {
  2.  
  3.   double x1,x2,y1,y2,z1,z2;
  4.   x1 = -0.5;
  5.   x2 = 0.5;
  6.   y1 = -0.5;
  7.   y2 = 0.5;
  8.   z1 = .5;       // front
  9.   z2 = -.5;      // back
  10.  
  11.   Point3 op3(x2,y2,z1);
  12.   Point3 op2(x1,y2,z1);
  13.   Point3 op1(x1,y1,z1);
  14.   Point3 p3 = op3;
  15.   Point3 p2 = op2;
  16.   Point3 p1 = op1;
  17.   float fx = n-1;
  18.   float fy = n-1;
  19.   float fz = n-1;
  20.   Point3 temp = p3;
  21.  
  22.   //front and back
  23.   //iterate through the square creating smaller squares made up of 2 triangles
  24.   for( int x = 0; x < 2; x++ ) {
  25.  
  26.     for( int i = 0; i < n; i++ ) { //rows
  27.       float facty = fy/n;
  28.       float npy = (1-facty)*p1.y + facty*p2.y;
  29.  
  30.       for( int j = 0; j < n; j++ ) { //cols
  31.         float factx = fx/n;
  32.         float npx = (1-factx)*p2.x + factx*p3.x;
  33.  
  34.         Point3 topL( npx, temp.y, temp.z);
  35.         Point3 lowR( temp.x, npy, temp.z);
  36.         Point3 midP( npx, npy, temp.z);
  37.  
  38.         addSquare( temp, topL, midP, lowR );
  39.  
  40.         temp = topL;
  41.         fx--;
  42.       }
  43.  
  44.       fx = n-1;
  45.       temp.x = p3.x;
  46.       temp.z = p3.z;
  47.       temp.y = npy;
  48.       fy--;
  49.     }
  50.     fy = n-1;
  51.     //reset for the back
  52.     p2 = op3;
  53.     p3 = op2;
  54.     p1.x = p2.x;
  55.     p3.z = z2;
  56.     p2.z = z2;
  57.     p1.z = z2;
  58.     temp = p3;
  59.   }
  60.  
  61.   //set up for the top
  62.   p3 = op3;
  63.   p2 = op2;
  64.   p1 = op1;
  65.   p3.z = z2;
  66.   p2.z = z2;
  67.   p1.y = p2.y;
  68.   fx = n-1;
  69.   temp = p3;
  70.  
  71.   //top and bottom
  72.   for( int x = 0; x < 2; x++ ) {
  73.  
  74.     for( int i = 0; i < n; i++ ) { //rows
  75.       float factz = fz/n;
  76.       float npz = (1-factz)*p1.z + factz*p2.z;
  77.  
  78.       for( int j = 0; j < n; j++ ) { //cols
  79.         float factx = fx/n;
  80.         float npx = (1-factx)*p2.x + factx*p3.x;
  81.  
  82.         Point3 topL( npx, temp.y, temp.z);
  83.         Point3 lowR( temp.x, temp.y, npz);
  84.         Point3 midP( npx, temp.y, npz);
  85.  
  86.         addSquare( temp, topL, midP, lowR );
  87.  
  88.         temp = topL;
  89.         fx--;
  90.       }
  91.  
  92.       fx = n-1;
  93.       temp.x = p3.x;
  94.       temp.z = npz;
  95.       temp.y = p3.y;
  96.       fz--;
  97.     }
  98.     fz = n-1;
  99.     //reset for the bottom
  100.     p3 = op3;
  101.     p2 = op1;
  102.     p1 = op1;
  103.     p1.z = z2;
  104.     p3.y = p1.y;
  105.     temp = p3;
  106.   }
  107.  
  108.   //set up for the right
  109.   p3 = op3;
  110.   p2 = op3;
  111.   p1.x = p2.x;
  112.   p3.z = z2;
  113.   fz = n-1;
  114.   fy = n-1;
  115.   temp = p3;
  116.  
  117.   //right and left
  118.   for( int x = 0; x < 2; x++ ) {
  119.  
  120.     for( int i = 0; i < n; i++ ) { //rows
  121.       float facty = fy/n;
  122.       float npy = (1-facty)*p1.y + facty*p2.y;
  123.  
  124.       for( int j = 0; j < n; j++ ) { //cols
  125.         float factz = fz/n;
  126.         float npz = (1-factz)*p2.z + factz*p3.z;
  127.  
  128.         Point3 topL( temp.x, temp.y, npz);
  129.         Point3 lowR( temp.x, npy, temp.z);
  130.         Point3 midP( temp.x, npy, npz);
  131.  
  132.         addSquare( temp, topL, midP, lowR );
  133.  
  134.         temp = topL;
  135.         fz--;
  136.       }
  137.  
  138.       fz = n-1;
  139.       temp.x = p3.x;
  140.       temp.z = p3.z;
  141.       temp.y = npy;
  142.       fy--;
  143.     }
  144.     fy = n-1;
  145.     //reset for the left
  146.     p3 = op2;
  147.     p2 = op2;
  148.     p2.z = z2;
  149.     p1 = op1;
  150.     p1.z = z2;
  151.     temp = p3;
  152.   }
  153.  
  154. }

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