void GateDemo::buildGateGeometry() { // Gate is just a rectangle aligned with the xy-plane. // Obtain a pointer to a new vertex buffer. HR(gd3dDevice->CreateVertexBuffer(4* sizeof(VertexPNT), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &mGateVB, 0)); // Now lock it to obtain a pointer to its internal data, and write the // grid's vertex data. VertexPNT* v = 0; HR(mGateVB->Lock(0, 0, (void**)&v, 0)); // Scale texture coordinates by 4 units in the v-direction for tiling. v[0] = VertexPNT(-20.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f); v[1] = VertexPNT(-20.0f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); v[2] = VertexPNT( 20.0f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 4.0f, 0.0f); v[3] = VertexPNT( 20.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 4.0f, 1.0f); HR(mGateVB->Unlock()); // Obtain a pointer to a new index buffer. HR(gd3dDevice->CreateIndexBuffer(6*sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &mGateIB, 0)); // Now lock it to obtain a pointer to its internal data, and write the // grid's index data. WORD* k = 0; HR(mGateIB->Lock(0, 0, (void**)&k, 0)); k[0] = 0; k[1] = 1; k[2] = 2; // Triangle 0 k[3] = 0; k[4] = 2; k[5] = 3; // Triangle 1 HR(mGateIB->Unlock()); }
IDirect3DVertexBuffer9* BufferFactory::textureCubeBuffer() { HR(gd3dDevice->CreateVertexBuffer(24 * sizeof(VertexPNT), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &mTexturedCubeVB, 0)); VertexPNT* v = 0; HR(mTexturedCubeVB->Lock(0, 0, (void**)&v, 0)); // Fill in the front face vertex data. v[0] = VertexPNT(-0.5, -0.5, -0.5, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f); v[1] = VertexPNT(-0.5, 0.5, -0.5, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); v[2] = VertexPNT( 0.5, 0.5, -0.5, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f); v[3] = VertexPNT( 0.5, -0.5, -0.5, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f); // Fill in the back face vertex data. v[4] = VertexPNT(-0.5, -0.5, 0.5, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); v[5] = VertexPNT( 0.5, -0.5, 0.5, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f); v[6] = VertexPNT( 0.5, 0.5, 0.5, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); v[7] = VertexPNT(-0.5, 0.5, 0.5, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); // Fill in the top face vertex data. v[8] = VertexPNT(-0.5, 0.5, -0.5, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f); v[9] = VertexPNT(-0.5, 0.5, 0.5, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); v[10] = VertexPNT( 0.5, 0.5, 0.5, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f); v[11] = VertexPNT( 0.5, 0.5, -0.5, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f); // Fill in the bottom face vertex data. v[12] = VertexPNT(-0.5, -0.5, -0.5, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f); v[13] = VertexPNT( 0.5, -0.5, -0.5, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f); v[14] = VertexPNT( 0.5, -0.5, 0.5, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f); v[15] = VertexPNT(-0.5, -0.5, 0.5, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); // Fill in the left face vertex data. v[16] = VertexPNT(-0.5, -0.5, 0.5, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f); v[17] = VertexPNT(-0.5, 0.5, 0.5, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f); v[18] = VertexPNT(-0.5, 0.5, -0.5, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f); v[19] = VertexPNT(-0.5, -0.5, -0.5, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f); // Fill in the right face vertex data. v[20] = VertexPNT( 0.5, -0.5, -0.5, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); v[21] = VertexPNT( 0.5, 0.5, -0.5, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f); v[22] = VertexPNT( 0.5, 0.5, 0.5, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f); v[23] = VertexPNT( 0.5, -0.5, 0.5, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f); HR(mTexturedCubeVB->Unlock()); return mTexturedCubeVB; }
void MirrorDemo::buildRoomGeometry() { // Create and specify geometry. For this sample we draw a floor // and a wall with a mirror on it. We put the floor, wall, and // mirror geometry in one vertex buffer. // // |----|----|----| // |Wall|Mirr|Wall| // | | or | | // /--------------/ // / Floor / // /--------------/ // Create the vertex buffer. HR(gd3dDevice->CreateVertexBuffer(24 * sizeof(VertexPNT), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &mRoomVB, 0)); // Write box vertices to the vertex buffer. VertexPNT* v = 0; HR(mRoomVB->Lock(0, 0, (void**)&v, 0)); // Floor: Observe we tile texture coordinates. v[0] = VertexPNT(-7.5f, 0.0f, -10.0f, 0.0f, 1.0f, 0.0f, 0.0f, 4.0f); v[1] = VertexPNT(-7.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); v[2] = VertexPNT( 7.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 4.0f, 0.0f); v[3] = VertexPNT(-7.5f, 0.0f, -10.0f, 0.0f, 1.0f, 0.0f, 0.0f, 4.0f); v[4] = VertexPNT( 7.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 4.0f, 0.0f); v[5] = VertexPNT( 7.5f, 0.0f, -10.0f, 0.0f, 1.0f, 0.0f, 4.0f, 4.0f); // Wall: Observe we tile texture coordinates, and that we // leave a gap in the middle for the mirror. v[6] = VertexPNT(-7.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 2.0f); v[7] = VertexPNT(-7.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); v[8] = VertexPNT(-2.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 2.0f, 0.0f); v[9] = VertexPNT(-7.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 2.0f); v[10] = VertexPNT(-2.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 2.0f, 0.0f); v[11] = VertexPNT(-2.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 2.0f, 2.0f); v[12] = VertexPNT(2.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 2.0f); v[13] = VertexPNT(2.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); v[14] = VertexPNT(7.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 2.0f, 0.0f); v[15] = VertexPNT(2.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 2.0f); v[16] = VertexPNT(7.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 2.0f, 0.0f); v[17] = VertexPNT(7.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 2.0f, 2.0f); // Mirror v[18] = VertexPNT(-2.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f); v[19] = VertexPNT(-2.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); v[20] = VertexPNT( 2.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f); v[21] = VertexPNT(-2.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f); v[22] = VertexPNT( 2.5f, 5.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f); v[23] = VertexPNT( 2.5f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f); HR(mRoomVB->Unlock()); }