Game Development Reference
In-Depth Information
Figure 4.3 Vertex numbering for triangle fans and quad strips.
The call to DrawSphere is a little routine that is included with the code for
this example as a further example of using OpenGL drawing primitives.
The first parameter in the function call defines the number of segments
that will be used in drawing the sphere, the second the number of slices
and the last the radius of the sphere. Take a look at the code to see how
to use two other types of painting, GL_TRIANGLE_FAN and GL_QUAD_
A triangle fan uses the first vertex as a vertex in all subsequent
triangles. The next two vertices define the first triangle; after that, each
subsequent vertex defines a triangle which takes the first vertex and the
previously defined vertex as its three vertices. It is a little more efficient
because it uses fewer vertices in the definition. With quad strips, the first
four vertices define the first quad then each subsequent quad is defined
from the previously defined two vertices and two new vertices. In the
function, triangle fan is used to cap the top and bottom of a sphere and
quad strips form rings of latitude around the sphere. This is only one way
to draw a sphere, a simpler way is to use the GLUT library function:
glutSolidSphere (Gldouble radius , Glint slices , Glint stacks ).
But this doesn't help you create your own drawing functions. Yet another
way is to use all triangles. Hopefully, this short function will show you how
a little bit of trigonometry can go a long way. Any point on a circle centred
at the origin and of radius r is defined as ( r cos
, r sin
), where
is an
Search Nedrilad ::

Custom Search