CHAPTER 3: Building a 3D World (^61)
Listing 3-3. Defining the 3D Cube
static const GLfloat cubeVertices[] = //1
{
-0.5, 0.5, 0.5, //vertex 0
0.5, 0.5, 0.5, // v1
0.5,-0.5, 0.5, // v2
-0.5,-0.5, 0.5, // v3
-0.5, 0.5,-0.5, // v4
0.5, 0.5,-0.5, // v5
0.5,-0.5,-0.5, // v6
-0.5,-0.5,-0.5, // v7
};
static const GLubyte cubeColors[] = { //2
255, 255, 0, 255,
0, 255, 255, 255,
0, 0, 0, 0,
255, 0, 255, 255,
255, 255, 0, 255,
0, 255, 255, 255,
0, 0, 0, 0,
255, 0, 255, 255,
};
static const GLubyte tfan1[6 3] = //3
{
1,0,3,
1,3,2,
1,2,6,
1,6,5,
1,5,4,
1,4,0
};
static const GLubyte tfan2[6 3] = //4
{
7,4,5,
7,5,6,
7,6,2,
7,2,3,
7,3,0,
7,0,4
};
Figure 3-5 shows the way the vertices are ordered. Under normal situations, you will
never have to define geometry in this fashion. You’ll likely load your objects from a file
stored in one of the standard 3D data formats, such as those used by 3D Studio or
Modeler 3D. And considering how complicated such files can be, it is not recommended
that you write your own because importers for most of the major formats are available.
singke
(singke)
#1