Game Development Reference

In-Depth Information

angle defined in radians between 0 and 2

radians in a revolution just as there are 360°). In this function we start by

calculating the radius of the base of the first slice. To do this, imagine that

we are looking at the sphere down the
z
-axis. Next think of a line pointing

vertically up; we want to rotate this line around by half a revolution divided

by the number of slices. Using this angle we can calculate the distance

from the
y
-axis to the circle using the sine of the angle together with the

radius of the circle. The sine gives the length of the side opposite the

angle and the cosine gives the length of the side adjacent to the angle.

(recall that there are 2

Figure 4.4 Calculating the radius of a slice.

Having calculated the radius of the top slice, we can use a similar

technique to calculate the position of each vertex. We know the
y
position

of each vertex in the triangle fan, vertex 0 will have a
y
value of radius and

all subsequent vertices will have a
y
value of radius
*
cos(

/slices). When

considering the
x
and
z
values we can think in two dimensions. We simply

need the positions on a circle. This is just the same problem as calculating

the radius of the first slice; each position will be (radius
*
cos(angle),

radius
*
sin(angle)) for some value of angle. The angle parameter starts

at 0 and increments by 2

/segments for each subsequent vertex. When

drawing the remaining slices we need two radii and two
y
values, one for

Search Nedrilad ::

Custom Search