Game Development Reference
In-Depth Information
software that lets us sculpture 3D objects in a WYSIWYG fashion. There are various paradigms
used in those applications, ranging from manipulating separate triangles to just specifying a few
parameters that output a triangle mesh (a fancy name for a list of triangles).
Prominent software packages such as Blender, 3ds Max, ZBrush, and Wings 3D provide users
with tons of functionality for creating 3D objects. Some of them are free (such as Blender and
Wings 3D) and some are commercial (for example, 3ds Max and ZBrush). It's not within the scope
of this topic to teach you how to use one of these programs. However, all these programs can
save the 3D models to different file formats. The Web is also full of free-to-use 3D models. In the
next chapter, we'll write a loader for one of the simplest and most common file formats in use.
In this chapter, we'll do everything programmatically. Let's create one of the simplest 3D objects
possible: a cube.
A Cube: Hello World in 3D
In the previous three chapters, we've made heavy use of the concept of model space. It's the
space in which to define models; it's completely unrelated to the world space. We use the
convention of constructing all objects around the model space's origin so that an object's center
coincides with that origin. Such a model can then be reused for rendering multiple objects at
different locations and with different orientations in world space, just as in the massive BobTest
example in Chapter 7.
The first thing we need to figure out for our cube is its corner points. Figure 10-11 shows a cube
with a side length of 1 unit (for example, 1 meter). We also exploded the cube a little so that we
can see the separate sides made up of two triangles each. In reality, the sides would all meet at
the edges and corner points, of course.
Figure 10-11. A cube and its corner points
A cube has six sides, and each side is made up of two triangles. The two triangles of each side
share two vertices. For the front side of the cube, the vertices at (−0.5,0.5,0.5) and (0.5,-0.5,0.5)
are shared. We only need four vertices per side; for a complete cube, that's 6 × 4 = 24 vertices
in total. However, we do need to specify 36 indices, not just 24. That's because there are 6 × 2
 
Search WWH ::




Custom Search