当前位置: 首页>>代码示例>>C++>>正文


C++ GeometryGenerator::createBox方法代码示例

本文整理汇总了C++中GeometryGenerator::createBox方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryGenerator::createBox方法的具体用法?C++ GeometryGenerator::createBox怎么用?C++ GeometryGenerator::createBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GeometryGenerator的用法示例。


在下文中一共展示了GeometryGenerator::createBox方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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 ) );
}
开发者ID:unixunited,项目名称:Direct3D11,代码行数:89,代码来源:main.cpp


注:本文中的GeometryGenerator::createBox方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。