Advertisement
Guest User

Untitled

a guest
Sep 13th, 2011
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1.     int sides = 20;
  2.     int slices = 100;
  3.     float radius = 10.0;
  4.     float height = 1240.0;
  5.     float x = 0.0, y = 0.0, z = -40.0;
  6.    
  7.     const float theta = 2. * M_PI / (float)sides;
  8.     float c = cosf(theta);
  9.     float s = sinf(theta);
  10.     // coordinates on top of the circle, on xz plane
  11.     float x2 = radius, z2 = 0;
  12.    
  13.     float dslice = (height / (float)slices);
  14.    
  15.    
  16.     numVertices = 2 * slices * (sides+1);
  17.     Vertices = malloc(sizeof(Vertex) * numVertices);
  18.    
  19.     int index = 0;
  20.    
  21.     for(int j=0; j<slices; j++) {
  22.         for(int i=0; i<=sides; i++) {
  23.             // texture coord
  24.             const float tx = (float)i/sides;
  25.             // normal
  26.             const float nf = 1./sqrtf(x2*x2+z2*z2),
  27.             xn = x2*nf, zn = z2*nf;
  28.            
  29.             Vertices[index].Position[0] = x+x2;
  30.             Vertices[index].Position[1] = y;
  31.             Vertices[index].Position[2] = z+z2;
  32.            
  33.             Vertices[index].TexCoord[0] = tx;
  34.             Vertices[index].TexCoord[1] = 0;
  35.            
  36.             Vertices[index].Normal[0] = xn;
  37.             Vertices[index].Normal[1] = 0;
  38.             Vertices[index].Normal[2] = zn;
  39.            
  40.             Vertices[index].Color[0] = 1;
  41.             Vertices[index].Color[1] = 1;
  42.             Vertices[index].Color[2] = 1;
  43.             Vertices[index].Color[3] = 1;
  44.            
  45.             index++;
  46.            
  47.             Vertices[index].Position[0] = x+x2;
  48.             Vertices[index].Position[1] = y+dslice;
  49.             Vertices[index].Position[2] = z+z2;
  50.            
  51.             Vertices[index].TexCoord[0] = tx;
  52.             Vertices[index].TexCoord[1] = 1;
  53.            
  54.             Vertices[index].Color[0] = 1;
  55.             Vertices[index].Color[1] = 1;
  56.             Vertices[index].Color[2] = 1;
  57.             Vertices[index].Color[3] = 1;
  58.            
  59.             Vertices[index].Normal[0] = xn;
  60.             Vertices[index].Normal[1] = 0;
  61.             Vertices[index].Normal[2] = zn;
  62.            
  63.             index++;
  64.            
  65.             // next position
  66.             const float x3 = x2;
  67.             x2 = c * x2 - s * z2;
  68.             z2 = s * x3 + c * z2;
  69.         }
  70.        
  71.         y += dslice;
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement