Game Development Reference
In-Depth Information
3.12 R ENDERING P RIMITIVES
During the development of a game there is often need for tools and features that only serve
as a way to provide visual feedback about the game's world that is not visible to players.
One common example is the visual representation of the physical properties of game entit-
ies, gameplay, AI and physics programmers often need to see the game as it is simulated to
understand how different systems are behaving. But beyond development tools, understand-
ing how to generate primitives is a useful tool for user interface programmers as it may lead
to new ideas and new ways of presenting information to players, the concepts behind the
geometry generation of a sphere for example could be used to create a 3D dynamic menu in
which menu options are presented as quads oriented along a sphere.
Inthissectionwewillseehowtogeneratethegeometryfordifferentprimitives,thefocusof
this section is on the algorithms necessary to generate the geometry, however it is important
to go further and create a batching system that stores all primitives of the same type within
the same buffers or an instancing system that given one primitive it will create multiple in-
stancesofitselftransformeddifferently.Otherwise,large-scaleuseofthesesystemsislikely
to cause performance problems.
Theprimitiveswecreatewillbeunitprimitives,meaningtheywillhavearadiusorwidthof
exactly one unit and they will be centered about the origin, this allows us to reuse the geo-
metry data with different transforms to translate, position or scale the primitives as needed.
All primitives will share the same vertex type, this will make it easier and consistent when
it's time to batch all primitives.
struct vertex_default
{
vector3 position;
color diffuse;
float u, v;
};
3.12.1 Quads
Aquad isoneofthemoststraightforward primitives todraw,itconsists oftwotriangles and
four vertices, there are a few ways to draw a quad however, we could use four vertices in a
vertex buffer and six indices in an index buffer to map both triangles in the quad, then draw
it as a triangle list. We could use four vertices in a vertex buffer and draw it as a triangle
Search WWH ::




Custom Search