Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sides = 20;
- int slices = 100;
- float radius = 10.0;
- float height = 1240.0;
- float x = 0.0, y = 0.0, z = -40.0;
- const float theta = 2. * M_PI / (float)sides;
- float c = cosf(theta);
- float s = sinf(theta);
- // coordinates on top of the circle, on xz plane
- float x2 = radius, z2 = 0;
- float dslice = (height / (float)slices);
- numVertices = 2 * slices * (sides+1);
- Vertices = malloc(sizeof(Vertex) * numVertices);
- int index = 0;
- for(int j=0; j<slices; j++) {
- for(int i=0; i<=sides; i++) {
- // texture coord
- const float tx = (float)i/sides;
- // normal
- const float nf = 1./sqrtf(x2*x2+z2*z2),
- xn = x2*nf, zn = z2*nf;
- Vertices[index].Position[0] = x+x2;
- Vertices[index].Position[1] = y;
- Vertices[index].Position[2] = z+z2;
- Vertices[index].TexCoord[0] = tx;
- Vertices[index].TexCoord[1] = 0;
- Vertices[index].Normal[0] = xn;
- Vertices[index].Normal[1] = 0;
- Vertices[index].Normal[2] = zn;
- Vertices[index].Color[0] = 1;
- Vertices[index].Color[1] = 1;
- Vertices[index].Color[2] = 1;
- Vertices[index].Color[3] = 1;
- index++;
- Vertices[index].Position[0] = x+x2;
- Vertices[index].Position[1] = y+dslice;
- Vertices[index].Position[2] = z+z2;
- Vertices[index].TexCoord[0] = tx;
- Vertices[index].TexCoord[1] = 1;
- Vertices[index].Color[0] = 1;
- Vertices[index].Color[1] = 1;
- Vertices[index].Color[2] = 1;
- Vertices[index].Color[3] = 1;
- Vertices[index].Normal[0] = xn;
- Vertices[index].Normal[1] = 0;
- Vertices[index].Normal[2] = zn;
- index++;
- // next position
- const float x3 = x2;
- x2 = c * x2 - s * z2;
- z2 = s * x3 + c * z2;
- }
- y += dslice;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement