Ejemplo n.º 1
0
void DiffuseCubeDemo::buildVertexBuffer()
{
	// Obtain a pointer to a new vertex buffer.
	HR(gd3dDevice->CreateVertexBuffer(24 * sizeof(VertexPN), D3DUSAGE_WRITEONLY,
		0, D3DPOOL_MANAGED, &mVB, 0));

	// Now lock it to obtain a pointer to its internal data, and write the
	// cube's vertex data.

	// NOTE: One key point to note is that with normals, we no longer have eight
	// unique vertices for the cube.  This is because, even though the vertices 
	// share spatial data, they do not share normal data.  
	VertexPN* v = 0;
	HR(mVB->Lock(0, 0, (void**)&v, 0));

	// fill in the front face vertex data
	v[0] = VertexPN(-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f);
	v[1] = VertexPN(-1.0f,  1.0f, -1.0f, 0.0f, 0.0f, -1.0f);
	v[2] = VertexPN( 1.0f,  1.0f, -1.0f, 0.0f, 0.0f, -1.0f);
	v[3] = VertexPN( 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f);

	// fill in the back face vertex data
	v[4] = VertexPN(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	v[5] = VertexPN( 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	v[6] = VertexPN( 1.0f,  1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	v[7] = VertexPN(-1.0f,  1.0f, 1.0f, 0.0f, 0.0f, 1.0f);

	// fill in the top face vertex data
	v[8]  = VertexPN(-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f);
	v[9]  = VertexPN(-1.0f, 1.0f,  1.0f, 0.0f, 1.0f, 0.0f);
	v[10] = VertexPN( 1.0f, 1.0f,  1.0f, 0.0f, 1.0f, 0.0f);
	v[11] = VertexPN( 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f);

	// fill in the bottom face vertex data
	v[12] = VertexPN(-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f);
	v[13] = VertexPN( 1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f);
	v[14] = VertexPN( 1.0f, -1.0f,  1.0f, 0.0f, -1.0f, 0.0f);
	v[15] = VertexPN(-1.0f, -1.0f,  1.0f, 0.0f, -1.0f, 0.0f);

	// fill in the left face vertex data
	v[16] = VertexPN(-1.0f, -1.0f,  1.0f, -1.0f, 0.0f, 0.0f);
	v[17] = VertexPN(-1.0f,  1.0f,  1.0f, -1.0f, 0.0f, 0.0f);
	v[18] = VertexPN(-1.0f,  1.0f, -1.0f, -1.0f, 0.0f, 0.0f);
	v[19] = VertexPN(-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f);

	// fill in the right face vertex data
	v[20] = VertexPN( 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f);
	v[21] = VertexPN( 1.0f,  1.0f, -1.0f, 1.0f, 0.0f, 0.0f);
	v[22] = VertexPN( 1.0f,  1.0f,  1.0f, 1.0f, 0.0f, 0.0f);
	v[23] = VertexPN( 1.0f, -1.0f,  1.0f, 1.0f, 0.0f, 0.0f);

	HR(mVB->Unlock());
}
Ejemplo n.º 2
0
void DiffusePyramidDemo::buildVertexBuffer()
{
	// Obtain a pointer to a new vertex buffer.
	HR(gd3dDevice->CreateVertexBuffer(12 * sizeof(VertexPN), D3DUSAGE_WRITEONLY,
		0, D3DPOOL_MANAGED, &mVB, 0));

	// Now lock it to obtain a pointer to its internal data, and write the
	// cube's vertex data.  Note also that in this demo we don't use an index
	// buffer.

	VertexPN* v = 0;
	HR(mVB->Lock(0, 0, (void**)&v, 0));

	// front face
	v[0] = VertexPN(-1.0f, 0.0f, -1.0f, 0.0f, 0.707f, -0.707f);
	v[1] = VertexPN( 0.0f, 1.0f,  0.0f, 0.0f, 0.707f, -0.707f);
	v[2] = VertexPN( 1.0f, 0.0f, -1.0f, 0.0f, 0.707f, -0.707f);

	// left face
	v[3] = VertexPN(-1.0f, 0.0f,  1.0f, -0.707f, 0.707f, 0.0f);
	v[4] = VertexPN( 0.0f, 1.0f,  0.0f, -0.707f, 0.707f, 0.0f);
	v[5] = VertexPN(-1.0f, 0.0f, -1.0f, -0.707f, 0.707f, 0.0f);

	// right face
	v[6] = VertexPN( 1.0f, 0.0f, -1.0f, 0.707f, 0.707f, 0.0f);
	v[7] = VertexPN( 0.0f, 1.0f,  0.0f, 0.707f, 0.707f, 0.0f);
	v[8] = VertexPN( 1.0f, 0.0f,  1.0f, 0.707f, 0.707f, 0.0f);

	// back face
	v[9]  = VertexPN( 1.0f, 0.0f,  1.0f, 0.0f, 0.707f, 0.707f);
	v[10] = VertexPN( 0.0f, 1.0f,  0.0f, 0.0f, 0.707f, 0.707f);
	v[11] = VertexPN(-1.0f, 0.0f,  1.0f, 0.0f, 0.707f, 0.707f);

	HR(mVB->Unlock());
}