Game Development Reference
In-Depth Information
enabling lighting, which isn't necessary because it's enabled by default
(but it doesn't hurt either).
bool Setup()
{
Device->SetRenderState(D3DRS_LIGHTING, true);
Next, we create the vertex buffer, lock it, and specify the vertices that
form triangles of the pyramid. The vertex normals were precomputed
using the algorithm covered in section 5.3. Notice that while the trian-
gles share vertices, they do not share normals; thus it is not very
advantageous to use an index list for this object. For example, all the
triangles share the peak point (0, 1, 0); however, for each triangle, the
peak vertex normal points in a different direction.
Device->CreateVertexBuffer(
12 * sizeof(Vertex),
D3DUSAGE_WRITEONLY,
Vertex::FVF,
D3DPOOL_MANAGED,
&Pyramid,
0);
// fill the vertex buffer with pyramid data
Vertex* v;
Pyramid->Lock(0, 0, (void**)&v, 0);
// front face
v[0] = Vertex(-1.0f, 0.0f, -1.0f, 0.0f, 0.707f, -0.707f);
v[1] = Vertex( 0.0f, 1.0f, 0.0f, 0.0f, 0.707f, -0.707f);
v[2] = Vertex( 1.0f, 0.0f, -1.0f, 0.0f, 0.707f, -0.707f);
// left face
v[3] = Vertex(-1.0f, 0.0f, 1.0f, -0.707f, 0.707f, 0.0f);
v[4] = Vertex( 0.0f, 1.0f, 0.0f, -0.707f, 0.707f, 0.0f);
v[5] = Vertex(-1.0f, 0.0f, -1.0f, -0.707f, 0.707f, 0.0f);
// right face
v[6] = Vertex( 1.0f, 0.0f, -1.0f, 0.707f, 0.707f, 0.0f);
v[7] = Vertex( 0.0f, 1.0f, 0.0f, 0.707f, 0.707f, 0.0f);
v[8] = Vertex( 1.0f, 0.0f, 1.0f, 0.707f, 0.707f, 0.0f);
// back face
v[9] = Vertex( 1.0f, 0.0f, 1.0f, 0.0f, 0.707f, 0.707f);
v[10] = Vertex( 0.0f, 1.0f, 0.0f, 0.0f, 0.707f, 0.707f);
v[11] = Vertex(-1.0f, 0.0f, 1.0f, 0.0f, 0.707f, 0.707f);
Pyramid->Unlock();
After we have generated the vertex data of our object, we describe how
the object interacts with light by describing its materials. In this sam-
ple, the pyramid reflects white lights, emits no light, and produces
some highlights.
Search WWH ::




Custom Search