Game Development Reference
In-Depth Information
vertexb.y = radius*cos(((double)(j+1)/(double)
slices)*PI);
sliceradiusb = sqrt(radius*radius-vertexb.
y*vertexb.y);
for (i=0;i<=segments;i++){
theta = PI2*((double)i/(double)segments);
vertex.x = sliceradius*cos(theta);
vertex.z = sliceradius*sin(theta);
norm = vertex;
norm.Normalize();
glNormal3d(norm.x, norm.y, norm.z);
glVertex3d(vertex.x, vertex.y, vertex.z);
vertexb.x = sliceradiusb*cos(theta);
vertexb.z = sliceradiusb*sin(theta);
norm = vertexb;
norm.Normalize();
glNormal3d(norm.x, norm.y, norm.z);
glVertex3d(vertexb.x, vertexb.y, vertexb.z);
}
}
glEnd();
//Draw the bottom
glBegin(GL_TRIANGLE_FAN);
//First set vertex 0
vertex.Set(0.0, -radius, 0.0);
norm.Set( 0.0, -1.0, 0.0);
glNormal3d(norm.x, norm.y, norm.z);
glVertex3d(vertex.x, vertex.y, vertex.z);
//All subsequent vertices use the same y value
vertex.y = radius*cos(((double)(slices-1)/(double)
slices)*PI);
sliceradius = sqrt(radius*radius-vertex.y*vertex.y);;
for(i=segments;i>=0;i-){
theta = PI2*((double)i/(double)segments);
vertex.x = sliceradius*cos(theta);
vertex.z = sliceradius*sin(theta);
norm = vertex;
norm.Normalize();
glNormal3d(norm.x, norm.y, norm.z);
glVertex3d(vertex.x, vertex.y, vertex.z);
}
glEnd();
}
Search Nedrilad ::




Custom Search