本文整理汇总了C++中GeometryGenerator::createGrid方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryGenerator::createGrid方法的具体用法?C++ GeometryGenerator::createGrid怎么用?C++ GeometryGenerator::createGrid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeometryGenerator
的用法示例。
在下文中一共展示了GeometryGenerator::createGrid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vertices
void D3DTextureDemo::BuildLandGemetryBuffers()
{
GeometryGenerator::MeshData grid;
GeometryGenerator landGenerator;
landGenerator.createGrid(160.0f, 160.0f, 50, 50, grid);
mLandIndexCount = grid.Indices.size();
std::vector<Vertex> vertices(grid.Vertices.size());
for(size_t i = 0; i < grid.Vertices.size(); ++i)
{
XMFLOAT3 p = grid.Vertices[i].Position;
p.y = GetHillHeight(p.x, p.z);
vertices[i].Pos = p;
vertices[i].Normal = GetHillNormal(p.x, p.z);
vertices[i].Tex = grid.Vertices[i].TexC;
}
D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex) * grid.Vertices.size();
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
vbd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = &vertices[0];
HR(m_d3dDevice->CreateBuffer(
&vbd,
&vinitData,
&mLandVB),
L"Create Vertex Buffer");
D3D11_BUFFER_DESC ibd;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(UINT) * mLandIndexCount;
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
ibd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &grid.Indices[0];
HR(m_d3dDevice->CreateBuffer(
&ibd,
&iinitData,
&mLandIB),
L"Create Index Buffer");
}
示例2: buildGeometryBuffers
void App::buildGeometryBuffers( void )
{
GeometryGenerator::MeshData grid;
GeometryGenerator geoGen;
geoGen.createGrid( 160.f, 160.f, 50, 50, grid );
mGridIndexCount = static_cast<UINT>( grid.indices.size() );
std::vector<Vertex> vertices( grid.vertices.size() );
for ( size_t i = 0; i < grid.vertices.size(); ++i ) {
DirectX::XMFLOAT3 p = grid.vertices[i].position;
p.y = getHeight( p.x, p.z );
vertices[i].Pos = p;
vertices[i].Color = DirectX::XMFLOAT4( 0.f, 0.5f, 0.f, 1.f );
}
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof( bd ) );
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof( Vertex ) * grid.vertices.size();
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
bd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory( &initData, sizeof( initData ) );
initData.pSysMem = &vertices[0];
HR( mD3DDevice->CreateBuffer( &bd, &initData, &mVB ) );
D3D11_BUFFER_DESC ibd;
ZeroMemory( &ibd, sizeof( ibd ) );
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof( UINT ) * mGridIndexCount; //!
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
ibd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &grid.indices[0];
HR( mD3DDevice->CreateBuffer( &ibd, &iinitData, &mIB ) );
}
示例3: buildGeometryBuffers
void App::buildGeometryBuffers( void )
{
GeometryGenerator::MeshData box, grid, sphere, cylinder;
GeometryGenerator geoGen;
geoGen.createBox( 1.f, 1.f, 1.f, box );
geoGen.createGrid( 20.f, 30.f, 60, 40, grid );
geoGen.createSphere( 0.5f, 20, 20, sphere );
geoGen.createCylinder( 0.5f, 0.3f, 3.f, 20, 20, cylinder );
mBoxVertexOffset = 0;
mGridVertexOffset = box.vertices.size();
mSphereVertexOffset = mGridVertexOffset + grid.vertices.size();
mCylinderVertexOffset = mSphereVertexOffset + sphere.vertices.size();
mBoxIndexCount = static_cast<UINT>( box.indices.size() );
mGridIndexCount = static_cast<UINT>( grid.indices.size() );
mSphereIndexCount = static_cast<UINT>( sphere.indices.size() );
mCylinderIndexCount = static_cast<UINT>( cylinder.indices.size() );
mBoxIndexOffset = 0;
mGridIndexOffset = mBoxIndexCount;
mSphereIndexOffset = mGridIndexOffset + mGridIndexCount;
mCylinderIndexOffset = mSphereIndexOffset + mSphereIndexCount;
const UINT totalVertexCount = box.vertices.size() +
grid.vertices.size() +
sphere.vertices.size() +
cylinder.vertices.size();
const UINT totalIndexCount = mBoxIndexCount +
mGridIndexCount +
mSphereIndexCount +
mCylinderIndexCount;
// Pack all vertices into one vertex buffer.
std::vector<Vertex> vertices( totalVertexCount );
const DirectX::XMFLOAT4 black( 0.f, 1.f, 0.f, 1.f );
UINT k = 0;
for ( size_t i = 0; i < box.vertices.size(); ++i, ++k ) {
vertices[k].pos = box.vertices[i].position;
vertices[k].color = black;
}
for ( size_t i = 0; i < grid.vertices.size(); ++i, ++k ) {
vertices[k].pos = grid.vertices[i].position;
vertices[k].color = black;
}
for ( size_t i = 0; i < sphere.vertices.size(); ++i, ++k ) {
vertices[k].pos = sphere.vertices[i].position;
vertices[k].color = black;
}
for ( size_t i = 0; i < cylinder.vertices.size(); ++i, ++k ) {
vertices[k].pos = cylinder.vertices[i].position;
vertices[k].color = black;
}
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof( bd ) );
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof( Vertex ) * totalVertexCount;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
bd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory( &initData, sizeof( initData ) );
initData.pSysMem = &vertices[0];
HR( mD3DDevice->CreateBuffer( &bd, &initData, &mVB ) );
std::vector<UINT> indices;
indices.insert( indices.end(), box.indices.begin(), box.indices.end() );
indices.insert( indices.end(), grid.indices.begin(), grid.indices.end() );
indices.insert( indices.end(), sphere.indices.begin(), sphere.indices.end() );
indices.insert( indices.end(), cylinder.indices.begin(), cylinder.indices.end() );
D3D11_BUFFER_DESC ibd;
ZeroMemory( &ibd, sizeof( ibd ) );
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof( UINT ) * totalIndexCount;
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
ibd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &indices[0];
HR( mD3DDevice->CreateBuffer( &ibd, &iinitData, &mIB ) );
}