Game Development Reference
In-Depth Information
Thesidesandthecapsharethesamevertices,theonlythingthatchangesisthefirstvertex,
we can calculate the indices all within the same loop.
const int offset = (numVertices - 2) * 3;
for (unsigned short i = 0, j = 0; i < (numVertices - 2) * 3; i += 3, ++j )
{
indices[i + 0] = 0;
indices[i + 1] = j + 1;
indices[i + 2] = j + 2;
indices[i + offset + 0] = (numVertices - 1);
indices[i + offset + 1] = indices[i + 1];
indices[i + offset + 2] = indices[i + 2];
}
All the sides have one vertex in common, they all reference the top vertex, and this is why
thefirstindexforallthesidesis0.Wealsoneedtomakecertain thatifwereachtheendof
the cone we need to wrap around the index to make sure it is properly closed. The cap uses
the same indices with the exception of the first index, which references the origin vertex
we stored at vertices[numVertices-1].
A note on texture mapping, the texture mapping applied is a per-face mapping, the top of
the cone maps to U:0.5, V:0 and each face's bottom vertices will range from 0 to 1. There
are different ways to apply texture mapping to a cone, which one to use will depend on the
feature being developed. A cylindrical texture mapping algorithm may give better results.
3.12.4 Ellipsoid / Sphere
A sphere is a very useful primitive to be render during the game's development, it can be
used to display information that is not normally visible, like an object's bounding volume,
a point in world space, a point light, we can even project spheres from world space onto
screen space, one useful application may be to represent nodes in an object hierarchy as
spheres.
The algorithm to generate a sphere's mesh works by separating a sphere into vertical seg-
ments, we can think of these as the rings that make up the sphere from top to bottom, then
each ring is divided into horizontal segments, these for the connections between rings to
form the triangles around the sphere, the vertical segments, represent the latitude while the
horizontal segments the longitude.
Search WWH ::




Custom Search