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


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

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


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

示例1: BuildBuffers

void DXBox::BuildBuffers(ID3D11Device* md3dDevice)
{
	GeometryGenerator::MeshData box;

	GeometryGenerator geoGen;
	geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);

	// Cache the vertex offsets to each object in the concatenated vertex buffer.
	mBoxVertexOffset      = 0;

	// Cache the index count of each object.
	mBoxIndexCount      = box.Indices.size();

	// Cache the starting index for each object in the concatenated index buffer.
	mBoxIndexOffset      = 0;
	
	UINT totalVertexCount = box.Vertices.size();

	UINT totalIndexCount = mBoxIndexCount;

	// Extract the vertex elements we are interested in and pack the
	// vertices of all the meshes into one vertex buffer.
	std::vector<Vertex::Basic32> vertices(totalVertexCount);

	UINT k = 0;
	for(size_t i = 0; i < box.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos    = box.Vertices[i].Position;
		vertices[k].Normal = box.Vertices[i].Normal;
		vertices[k].Tex    = box.Vertices[i].TexC;
	}

	D3D11_BUFFER_DESC vbd;
	vbd.Usage = D3D11_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof(Vertex::Basic32) * totalVertexCount;
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = 0;
	vbd.MiscFlags = 0;
	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = &vertices[0];
	HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));

	// Pack the indices of all the meshes into one index buffer.
	std::vector<UINT> indices;
	indices.insert(indices.end(), box.Indices.begin(), box.Indices.end());

	D3D11_BUFFER_DESC ibd;
	ibd.Usage = D3D11_USAGE_IMMUTABLE;
	ibd.ByteWidth = sizeof(UINT) * totalIndexCount;
	ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	ibd.CPUAccessFlags = 0;
	ibd.MiscFlags = 0;
	D3D11_SUBRESOURCE_DATA iinitData;
	iinitData.pSysMem = &indices[0];
	HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mBoxIB));
}
开发者ID:ZonyZerium,项目名称:Z-Force,代码行数:56,代码来源:DXBox.cpp

示例2: BuildBoxGeometry

void WavesCSApp::BuildBoxGeometry()
{
	GeometryGenerator geoGen;
	GeometryGenerator::MeshData box = geoGen.CreateBox(8.0f, 8.0f, 8.0f, 3);

	std::vector<Vertex> vertices(box.Vertices.size());
	for (size_t i = 0; i < box.Vertices.size(); ++i)
	{
		auto& p = box.Vertices[i].Position;
		vertices[i].Pos = p;
		vertices[i].Normal = box.Vertices[i].Normal;
		vertices[i].TexC = box.Vertices[i].TexC;
	}

	const UINT vbByteSize = (UINT)vertices.size() * sizeof(Vertex);

	std::vector<std::uint16_t> indices = box.GetIndices16();
	const UINT ibByteSize = (UINT)indices.size() * sizeof(std::uint16_t);

	auto geo = std::make_unique<MeshGeometry>();
	geo->Name = "boxGeo";

	ThrowIfFailed(D3DCreateBlob(vbByteSize, &geo->VertexBufferCPU));
	CopyMemory(geo->VertexBufferCPU->GetBufferPointer(), vertices.data(), vbByteSize);

	ThrowIfFailed(D3DCreateBlob(ibByteSize, &geo->IndexBufferCPU));
	CopyMemory(geo->IndexBufferCPU->GetBufferPointer(), indices.data(), ibByteSize);

	geo->VertexBufferGPU = d3dUtil::CreateDefaultBuffer(md3dDevice.Get(),
		mCommandList.Get(), vertices.data(), vbByteSize, geo->VertexBufferUploader);

	geo->IndexBufferGPU = d3dUtil::CreateDefaultBuffer(md3dDevice.Get(),
		mCommandList.Get(), indices.data(), ibByteSize, geo->IndexBufferUploader);

	geo->VertexByteStride = sizeof(Vertex);
	geo->VertexBufferByteSize = vbByteSize;
	geo->IndexFormat = DXGI_FORMAT_R16_UINT;
	geo->IndexBufferByteSize = ibByteSize;

	SubmeshGeometry submesh;
	submesh.IndexCount = (UINT)indices.size();
	submesh.StartIndexLocation = 0;
	submesh.BaseVertexLocation = 0;

	geo->DrawArgs["box"] = submesh;

	mGeometries["boxGeo"] = std::move(geo);
}
开发者ID:BlakeTriana,项目名称:d3d12book,代码行数:48,代码来源:WavesCSApp.cpp

示例3: BuildCrateGeometryBuffers

void BlendApp::BuildCrateGeometryBuffers()
{
	GeometryGenerator::MeshData box;

	GeometryGenerator geoGen;
	geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);

	//
	// Extract the vertex elements we are interested in and pack the
	// vertices of all the meshes into one vertex buffer.
	//

	std::vector<Vertex> vertices(box.Vertices.size());

	for(UINT i = 0; i < box.Vertices.size(); ++i)
	{
		vertices[i].Pos    = box.Vertices[i].Position;
		vertices[i].Normal = box.Vertices[i].Normal;
		vertices[i].Tex    = box.Vertices[i].TexC;
	}

    D3D11_BUFFER_DESC vbd;
	ZeroMemory(&vbd, sizeof(vbd));
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(Vertex) * box.Vertices.size();
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &vertices[0];
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));

	//
	// Pack the indices of all the meshes into one index buffer.
	//

	D3D11_BUFFER_DESC ibd;
	ZeroMemory(&ibd, sizeof(ibd));
    ibd.Usage = D3D11_USAGE_IMMUTABLE;
	ibd.ByteWidth = sizeof(UINT) * box.Indices.size();
    ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA iinitData;
    iinitData.pSysMem = &box.Indices[0];
    HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mBoxIB));
}
开发者ID:fxyyoung,项目名称:HyperEngine,代码行数:47,代码来源:BlendDemo.cpp

示例4: BuildCrateBuffers

void TreeBillboardApp::BuildCrateBuffers()
{
    GeometryGenerator::MeshData box;

	GeometryGenerator geoGen;
	geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);

	// Extract the vertex elements we are interested in and pack the
	// vertices of all the meshes into one vertex buffer.
	std::vector<Vertex::Basic32> vertices(box.vertices.size());

	for(UINT i = 0; i < box.vertices.size(); ++i)
	{
		vertices[i].Pos    = box.vertices[i].position;
		vertices[i].Normal = box.vertices[i].normal;
		vertices[i].Tex    = box.vertices[i].texC;
	}

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(Vertex::Basic32) * box.vertices.size();
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &vertices[0];
    HR(m_dxDevice->CreateBuffer(&vbd, &vinitData, m_boxVB.GetAddressOf()));

	// Pack the indices of all the meshes into one index buffer.
	D3D11_BUFFER_DESC ibd;
    ibd.Usage = D3D11_USAGE_IMMUTABLE;
	ibd.ByteWidth = sizeof(UINT) * box.indices.size();
    ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA iinitData;
    iinitData.pSysMem = &box.indices[0];
    HR(m_dxDevice->CreateBuffer(&ibd, &iinitData, m_boxIB.GetAddressOf()));
}
开发者ID:madmaurice,项目名称:sandbox,代码行数:39,代码来源:TreeBillboard.cpp

示例5: BuildBoxGeometry

void TexWaves::BuildBoxGeometry()
{
    GeometryGenerator geoGen;
    GeometryGenerator::MeshData box = geoGen.CreateBox(8.0f, 8.0f, 8.0f, 3);

    SubmeshGeometry boxSubmesh;
    boxSubmesh.IndexCount = (UINT)box.Indices32.size();
    boxSubmesh.StartIndexLocation = 0;
    boxSubmesh.BaseVertexLocation = 0;

    std::vector<FrameResource::Vertex> vertices(box.Vertices.size());

    for (size_t i = 0; i < box.Vertices.size(); i++)
    {
        vertices[i].Pos = box.Vertices[i].Position;
        vertices[i].Normal = box.Vertices[i].Normal;
        vertices[i].TexC = box.Vertices[i].TexCoord;
    }
    std::vector<uint16_t> indices = box.GetIndices16();
    const UINT vbByteSize = sizeof(FrameResource::Vertex) * (UINT)vertices.size();
    const UINT ibByteSize = sizeof(uint16_t) * (UINT)indices.size();

    auto geo = std::make_unique<MeshGeometry>();
    geo->Name = "boxGeo";

    geo->VertexBufferGPU = D3DUtil::CreateDefaultBuffer(_device.Get(), _commandList.Get(), vertices.data(), vbByteSize, geo->VertexBufferUploader);
    geo->IndexBufferGPU = D3DUtil::CreateDefaultBuffer(_device.Get(), _commandList.Get(), indices.data(), ibByteSize, geo->IndexBufferUploader);

    geo->VertexByteStride = sizeof(FrameResource::Vertex);
    geo->VertexBufferByteSize = vbByteSize;
    geo->IndexFormat = DXGI_FORMAT_R16_UINT;
    geo->IndexBufferByteSize = ibByteSize;

    geo->DrawArgs["box"] = boxSubmesh;
    _geometries[geo->Name] = move(geo);
}
开发者ID:jonny2027,项目名称:DX12Samples,代码行数:36,代码来源:TexWaves.cpp

示例6: BuildShapeGeometryBuffers

void TexColumnApp::BuildShapeGeometryBuffers()
{
	GeometryGenerator::MeshData box;
	GeometryGenerator::MeshData grid;
	GeometryGenerator::MeshData sphere;
	GeometryGenerator::MeshData cylinder;

	GeometryGenerator geoGen;
	geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);
	geoGen.CreateGrid(20.0f, 30.0f, 60, 40, grid);
	geoGen.CreateSphere(0.5f, 20, 20, sphere);
	geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20, cylinder);

	// Cache the vertex offsets to each object in the concatenated vertex buffer.
	mBoxVertexOffset      = 0;
	mGridVertexOffset     = box.Vertices.size();
	mSphereVertexOffset   = mGridVertexOffset + grid.Vertices.size();
	mCylinderVertexOffset = mSphereVertexOffset + sphere.Vertices.size();

	// Cache the index count of each object.
	mBoxIndexCount      = box.Indices.size();
	mGridIndexCount     = grid.Indices.size();
	mSphereIndexCount   = sphere.Indices.size();
	mCylinderIndexCount = cylinder.Indices.size();

	// Cache the starting index for each object in the concatenated index buffer.
	mBoxIndexOffset      = 0;
	mGridIndexOffset     = mBoxIndexCount;
	mSphereIndexOffset   = mGridIndexOffset + mGridIndexCount;
	mCylinderIndexOffset = mSphereIndexOffset + mSphereIndexCount;
	
	UINT totalVertexCount = 
		box.Vertices.size() + 
		grid.Vertices.size() + 
		sphere.Vertices.size() +
		cylinder.Vertices.size();

	UINT totalIndexCount = 
		mBoxIndexCount + 
		mGridIndexCount + 
		mSphereIndexCount +
		mCylinderIndexCount;

	//
	// Extract the vertex elements we are interested in and pack the
	// vertices of all the meshes into one vertex buffer.
	//

	std::vector<Vertex::Basic32> vertices(totalVertexCount);

	UINT k = 0;
	for(size_t i = 0; i < box.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos    = box.Vertices[i].Position;
		vertices[k].Normal = box.Vertices[i].Normal;
		vertices[k].Tex    = box.Vertices[i].TexC;
	}

	for(size_t i = 0; i < grid.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos    = grid.Vertices[i].Position;
		vertices[k].Normal = grid.Vertices[i].Normal;
		vertices[k].Tex    = grid.Vertices[i].TexC;
	}

	for(size_t i = 0; i < sphere.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos    = sphere.Vertices[i].Position;
		vertices[k].Normal = sphere.Vertices[i].Normal;
		vertices[k].Tex    = sphere.Vertices[i].TexC;
	}

	for(size_t i = 0; i < cylinder.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos    = cylinder.Vertices[i].Position;
		vertices[k].Normal = cylinder.Vertices[i].Normal;
		vertices[k].Tex    = cylinder.Vertices[i].TexC;
	}

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(Vertex::Basic32) * totalVertexCount;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &vertices[0];
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mShapesVB));

	//
	// Pack the indices of all the meshes into one index buffer.
	//

	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;
//.........这里部分代码省略.........
开发者ID:akbyrd,项目名称:Direct3D11-Playground,代码行数:101,代码来源:TexColumnsDemo.cpp

示例7: BuildShapeGeometry

void CameraAndDynamicIndexingApp::BuildShapeGeometry()
{
    GeometryGenerator geoGen;
	GeometryGenerator::MeshData box = geoGen.CreateBox(1.0f, 1.0f, 1.0f, 3);
	GeometryGenerator::MeshData grid = geoGen.CreateGrid(20.0f, 30.0f, 60, 40);
	GeometryGenerator::MeshData sphere = geoGen.CreateSphere(0.5f, 20, 20);
	GeometryGenerator::MeshData cylinder = geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20);

	//
	// We are concatenating all the geometry into one big vertex/index buffer.  So
	// define the regions in the buffer each submesh covers.
	//

	// Cache the vertex offsets to each object in the concatenated vertex buffer.
	UINT boxVertexOffset = 0;
	UINT gridVertexOffset = (UINT)box.Vertices.size();
	UINT sphereVertexOffset = gridVertexOffset + (UINT)grid.Vertices.size();
	UINT cylinderVertexOffset = sphereVertexOffset + (UINT)sphere.Vertices.size();

	// Cache the starting index for each object in the concatenated index buffer.
	UINT boxIndexOffset = 0;
	UINT gridIndexOffset = (UINT)box.Indices32.size();
	UINT sphereIndexOffset = gridIndexOffset + (UINT)grid.Indices32.size();
	UINT cylinderIndexOffset = sphereIndexOffset + (UINT)sphere.Indices32.size();

	SubmeshGeometry boxSubmesh;
	boxSubmesh.IndexCount = (UINT)box.Indices32.size();
	boxSubmesh.StartIndexLocation = boxIndexOffset;
	boxSubmesh.BaseVertexLocation = boxVertexOffset;

	SubmeshGeometry gridSubmesh;
	gridSubmesh.IndexCount = (UINT)grid.Indices32.size();
	gridSubmesh.StartIndexLocation = gridIndexOffset;
	gridSubmesh.BaseVertexLocation = gridVertexOffset;

	SubmeshGeometry sphereSubmesh;
	sphereSubmesh.IndexCount = (UINT)sphere.Indices32.size();
	sphereSubmesh.StartIndexLocation = sphereIndexOffset;
	sphereSubmesh.BaseVertexLocation = sphereVertexOffset;

	SubmeshGeometry cylinderSubmesh;
	cylinderSubmesh.IndexCount = (UINT)cylinder.Indices32.size();
	cylinderSubmesh.StartIndexLocation = cylinderIndexOffset;
	cylinderSubmesh.BaseVertexLocation = cylinderVertexOffset;

	//
	// Extract the vertex elements we are interested in and pack the
	// vertices of all the meshes into one vertex buffer.
	//

	auto totalVertexCount =
		box.Vertices.size() +
		grid.Vertices.size() +
		sphere.Vertices.size() +
		cylinder.Vertices.size();

	std::vector<Vertex> vertices(totalVertexCount);

	UINT k = 0;
	for(size_t i = 0; i < box.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos = box.Vertices[i].Position;
		vertices[k].Normal = box.Vertices[i].Normal;
		vertices[k].TexC = box.Vertices[i].TexC;
	}

	for(size_t i = 0; i < grid.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos = grid.Vertices[i].Position;
		vertices[k].Normal = grid.Vertices[i].Normal;
		vertices[k].TexC = grid.Vertices[i].TexC;
	}

	for(size_t i = 0; i < sphere.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos = sphere.Vertices[i].Position;
		vertices[k].Normal = sphere.Vertices[i].Normal;
		vertices[k].TexC = sphere.Vertices[i].TexC;
	}

	for(size_t i = 0; i < cylinder.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos = cylinder.Vertices[i].Position;
		vertices[k].Normal = cylinder.Vertices[i].Normal;
		vertices[k].TexC = cylinder.Vertices[i].TexC;
	}

	std::vector<std::uint16_t> indices;
	indices.insert(indices.end(), std::begin(box.GetIndices16()), std::end(box.GetIndices16()));
	indices.insert(indices.end(), std::begin(grid.GetIndices16()), std::end(grid.GetIndices16()));
	indices.insert(indices.end(), std::begin(sphere.GetIndices16()), std::end(sphere.GetIndices16()));
	indices.insert(indices.end(), std::begin(cylinder.GetIndices16()), std::end(cylinder.GetIndices16()));

    const UINT vbByteSize = (UINT)vertices.size() * sizeof(Vertex);
    const UINT ibByteSize = (UINT)indices.size()  * sizeof(std::uint16_t);

	auto geo = std::make_unique<MeshGeometry>();
	geo->Name = "shapeGeo";

	ThrowIfFailed(D3DCreateBlob(vbByteSize, &geo->VertexBufferCPU));
//.........这里部分代码省略.........
开发者ID:BlakeTriana,项目名称:d3d12book,代码行数:101,代码来源:CameraAndDynamicIndexingApp.cpp

示例8: BuildGeometries

void TextureWave::BuildGeometries()
{
    GeometryGenerator::MeshData meshData;
    GeometryGenerator generator;
    generator.CreateGrid(160.0f, 160.0f, 50, 50, meshData);

    m_wave.Init(160, 160, 1.0f, 0.03f, 5.0f, 0.3f);

    m_landIndexCount = static_cast<UINT>(meshData.Indices.size());

    std::vector<D3DHelper::CustomVertexWithTexture> tempVerties(meshData.Vertices.size());

    UINT vertexCount = static_cast<UINT>(meshData.Vertices.size());

    for (UINT i = 0; i < vertexCount; ++i)
    {
        XMFLOAT3 pos = meshData.Vertices[i].Position;
        pos.y = GetHillHeight(pos.x, pos.z);

        tempVerties[i].Position = pos;
        tempVerties[i].Normal = GetHillNormal(pos.x, pos.z);;
        tempVerties[i].TexCoord = meshData.Vertices[i].TexC;
    }

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = static_cast<UINT>(sizeof(D3DHelper::CustomVertexWithTexture) * tempVerties.size());
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &tempVerties[0];
    auto hr = m_d3dDevice->CreateBuffer(&vbd, &vinitData, &m_landVB);
    D3DHelper::ThrowIfFailed(hr);

    D3D11_BUFFER_DESC ibd;
    ibd.Usage = D3D11_USAGE_IMMUTABLE;
    ibd.ByteWidth = sizeof(UINT) * m_landIndexCount;
    ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
    D3D11_SUBRESOURCE_DATA iinitData;
    iinitData.pSysMem = &meshData.Indices[0];
    hr = m_d3dDevice->CreateBuffer(&ibd, &iinitData, &m_landIB);
    D3DHelper::ThrowIfFailed(hr);

    meshData.Clear();

    // *** start create wave
    m_waveIndexCount = m_wave.IndexCount();

    vbd.Usage = D3D11_USAGE_DYNAMIC;
    vbd.ByteWidth = static_cast<UINT>(sizeof(D3DHelper::CustomVertexWithTexture) * m_wave.VertexCount());
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    vbd.MiscFlags = 0;
    hr = m_d3dDevice->CreateBuffer(&vbd, nullptr, &m_waveVB);
    D3DHelper::ThrowIfFailed(hr);

    std::vector<UINT> indices(3 * m_wave.TriangleCount()); // 3 indices per face
    UINT m = m_wave.RowCount();
    UINT n = m_wave.ColumnCount();
    int k = 0;
    for (UINT i = 0; i < m - 1; ++i)
    {
        for (DWORD j = 0; j < n - 1; ++j)
        {
            indices[k] = i*n + j;
            indices[k + 1] = i*n + j + 1;
            indices[k + 2] = (i + 1)*n + j;

            indices[k + 3] = (i + 1)*n + j;
            indices[k + 4] = i*n + j + 1;
            indices[k + 5] = (i + 1)*n + j + 1;

            k += 6; // next quad
        }
    }

    ibd.Usage = D3D11_USAGE_IMMUTABLE;
    ibd.ByteWidth = sizeof(UINT) * m_waveIndexCount;
    ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
    iinitData;
    iinitData.pSysMem = &indices[0];
    hr = m_d3dDevice->CreateBuffer(&ibd, &iinitData, &m_waveIB);
    D3DHelper::ThrowIfFailed(hr);

    // *** end of create wave

    meshData.Clear();
    generator.CreateBox(4, 4, 4, meshData);
    tempVerties.clear();
    tempVerties.resize(meshData.Vertices.size());
    vertexCount = static_cast<UINT>(meshData.Vertices.size());
    for (UINT i = 0; i < vertexCount; ++i)
    {
        tempVerties[i].Position = meshData.Vertices[i].Position;
        tempVerties[i].Normal = meshData.Vertices[i].Normal;
//.........这里部分代码省略.........
开发者ID:tczzyzymj,项目名称:Prectice,代码行数:101,代码来源:TextureWave.cpp

示例9: BuildShapeGeometry

void DynamicIndexing::BuildShapeGeometry()
{
    GeometryGenerator geoGen;
    GeometryGenerator::MeshData box = geoGen.CreateBox(1.0f, 1.0f, 1.0f, 3);
    GeometryGenerator::MeshData grid = geoGen.CreateGrid(20.0f, 30.0f, 60, 40);
    GeometryGenerator::MeshData sphere = geoGen.CreateSphere(0.5f, 20, 20);
    GeometryGenerator::MeshData cylinder = geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20);

    UINT boxVertexOffset = 0;
    UINT gridVertexOffset = (UINT)box.Vertices.size();
    UINT sphereVertexOffset = gridVertexOffset + (UINT)grid.Vertices.size();
    UINT cylinderVertexOffset = sphereVertexOffset + (UINT)sphere.Vertices.size();

    UINT boxIndexOffset = 0;
    UINT gridIndexOffset = (UINT)box.Indices32.size();
    UINT sphereIndexOffset = gridIndexOffset + (UINT)grid.Indices32.size();
    UINT cylinderIndexOffset = sphereIndexOffset + (UINT)sphere.Indices32.size();

    SubmeshGeometry boxSubmesh;
    boxSubmesh.IndexCount = (UINT)box.Indices32.size();
    boxSubmesh.StartIndexLocation = boxIndexOffset;
    boxSubmesh.BaseVertexLocation = boxVertexOffset;

    SubmeshGeometry gridSubmesh;
    gridSubmesh.IndexCount = (UINT)grid.Indices32.size();
    gridSubmesh.StartIndexLocation = gridIndexOffset;
    gridSubmesh.BaseVertexLocation = gridVertexOffset;

    SubmeshGeometry sphereSubmesh;
    sphereSubmesh.IndexCount = (UINT)sphere.Indices32.size();
    sphereSubmesh.StartIndexLocation = sphereIndexOffset;
    sphereSubmesh.BaseVertexLocation = sphereVertexOffset;

    SubmeshGeometry cylinderSubmesh;
    cylinderSubmesh.IndexCount = (UINT)cylinder.Indices32.size();
    cylinderSubmesh.StartIndexLocation = cylinderIndexOffset;
    cylinderSubmesh.BaseVertexLocation = cylinderVertexOffset;

    auto totalVertexCount =
        box.Vertices.size() +
        grid.Vertices.size() +
        sphere.Vertices.size() +
        cylinder.Vertices.size();

    std::vector<Vertex> vertices(totalVertexCount);

    UINT k = 0;
    for (size_t i = 0; i < box.Vertices.size(); ++i, ++k)
    {
        vertices[k].Pos = box.Vertices[i].Position;
        vertices[k].Normal = box.Vertices[i].Normal;
        vertices[k].Uv = box.Vertices[i].TexCoord;
    }

    for (size_t i = 0; i < grid.Vertices.size(); ++i, ++k)
    {
        vertices[k].Pos = grid.Vertices[i].Position;
        vertices[k].Normal = grid.Vertices[i].Normal;
        vertices[k].Uv = grid.Vertices[i].TexCoord;
    }

    for (size_t i = 0; i < sphere.Vertices.size(); ++i, ++k)
    {
        vertices[k].Pos = sphere.Vertices[i].Position;
        vertices[k].Normal = sphere.Vertices[i].Normal;
        vertices[k].Uv = sphere.Vertices[i].TexCoord;
    }

    for (size_t i = 0; i < cylinder.Vertices.size(); ++i, ++k)
    {
        vertices[k].Pos = cylinder.Vertices[i].Position;
        vertices[k].Normal = cylinder.Vertices[i].Normal;
        vertices[k].Uv = cylinder.Vertices[i].TexCoord;
    }

    std::vector<uint16_t> indices;
    indices.insert(indices.end(), begin(box.GetIndices16()), end(box.GetIndices16()));
    indices.insert(indices.end(), begin(grid.GetIndices16()), end(grid.GetIndices16()));
    indices.insert(indices.end(), begin(sphere.GetIndices16()), end(sphere.GetIndices16()));
    indices.insert(indices.end(), begin(cylinder.GetIndices16()), end(cylinder.GetIndices16()));

    const UINT vbByteSize = (UINT)vertices.size() * sizeof(Vertex);
    const UINT ibByteSize = (UINT)indices.size()  * sizeof(uint16_t);

    auto geo = std::make_unique<MeshGeometry>();
    geo->Name = "shapeGeo";

    ThrowIfFailed(D3DCreateBlob(vbByteSize, &geo->VertexBufferCPU));
    CopyMemory(geo->VertexBufferCPU->GetBufferPointer(), vertices.data(), vbByteSize);

    ThrowIfFailed(D3DCreateBlob(ibByteSize, &geo->IndexBufferCPU));
    CopyMemory(geo->IndexBufferCPU->GetBufferPointer(), indices.data(), ibByteSize);

    geo->VertexBufferGPU = D3DUtil::CreateDefaultBuffer(_device.Get(),
        _commandList.Get(), vertices.data(), vbByteSize, geo->VertexBufferUploader);

    geo->IndexBufferGPU = D3DUtil::CreateDefaultBuffer(_device.Get(),
        _commandList.Get(), indices.data(), ibByteSize, geo->IndexBufferUploader);

    geo->VertexByteStride = sizeof(Vertex);
//.........这里部分代码省略.........
开发者ID:nameless323,项目名称:DX12Samples,代码行数:101,代码来源:DynamicIndexing.cpp

示例10: BuildGeometries

HRESULT LightSkull::BuildGeometries()
{
    auto tempBoxWorld = XMMatrixTranslation(0.0f, 0.5f, 0.0f);
    auto tempBoxScale = XMMatrixScaling(3.0f, 1.0f, 3.0f);
    m_boxWorld = XMMatrixMultiply(tempBoxWorld, tempBoxScale);
    m_boxWorld = XMMatrixTranspose(m_boxWorld);

    auto tempCenterSphereOffset = XMMatrixTranslation(0.0f, 2.0f, 0.0f);
    auto tempCenterSphereScale = XMMatrixScaling(2.0f, 2.0f, 2.0f);
    m_centerSphere = XMMatrixMultiply(tempCenterSphereScale, tempCenterSphereOffset);
    m_centerSphere = XMMatrixTranspose(m_centerSphere);

    for (int i = 0; i < 5; ++i)
    {
        m_cylinderWorld[i * 2] = XMMatrixTranslation(-5.0f, 1.5f, -10.0f + i*5.0f);
        m_cylinderWorld[i * 2] = XMMatrixTranspose(m_cylinderWorld[i * 2]);
        m_cylinderWorld[i * 2 + 1] = XMMatrixTranslation(+5.0f, 1.5f, -10.0f + i*5.0f);
        m_cylinderWorld[i * 2 + 1] = XMMatrixTranspose(m_cylinderWorld[i * 2 + 1]);

        m_sphereWorld[i * 2] = XMMatrixTranslation(-5.0f, 3.5f, -10.0f + i*5.0f);
        m_sphereWorld[i * 2] = XMMatrixTranspose(m_sphereWorld[i * 2]);
        m_sphereWorld[i * 2 + 1] = XMMatrixTranslation(+5.0f, 3.5f, -10.0f + i*5.0f);
        m_sphereWorld[i * 2 + 1] = XMMatrixTranspose(m_sphereWorld[i * 2 + 1]);
    }

    HRESULT result = S_FALSE;

    GeometryGenerator::MeshData box;
    GeometryGenerator::MeshData grid;
    GeometryGenerator::MeshData sphere;
    GeometryGenerator::MeshData cylinder;

    GeometryGenerator g;
    g.CreateBox(1.0f, 1.0f, 1.0f, box);
    g.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20, cylinder);
    g.CreateGrid(20.0f, 30.0f, 60, 40, grid);
    g.CreateSphere(0.5f, 20, 20, sphere);

    m_boxVertexOffset = 0;
    m_gridVertexOffset = static_cast<int>(box.Vertices.size());
    m_sphereVertexOffset = static_cast<int>(m_gridVertexOffset + grid.Vertices.size());
    m_cylinderVertexOffset = static_cast<int>(m_sphereVertexOffset + sphere.Vertices.size());

    m_boxIndexCount = static_cast<UINT>(box.Indices.size());
    m_gridIndexCount = static_cast<UINT>(grid.Indices.size());
    m_sphereIndexCount = static_cast<UINT>(sphere.Indices.size());
    m_cylinderIndexCount = static_cast<UINT>(cylinder.Indices.size());

    m_boxIndexOffset = 0;
    m_gridIndexOffset = m_boxIndexCount;
    m_sphereIndexOffset = m_gridIndexOffset + m_gridIndexCount;
    m_cylinderIndexOffset = m_sphereIndexOffset + m_sphereIndexCount;

    std::vector<CustomVertex> vertices;
    int j = 0;
    for (UINT i = 0; i < box.Vertices.size(); ++i, ++j)
    {
        CustomVertex newData;
        newData.Pos = box.Vertices[i].Position;
        newData.Normal = box.Vertices[i].Normal;
        vertices.push_back(newData);
    }

    for (UINT i = 0; i < grid.Vertices.size(); ++i, ++j)
    {
        CustomVertex newData;
        newData.Pos = grid.Vertices[i].Position;
        newData.Normal = grid.Vertices[i].Normal;
        vertices.push_back(newData);
    }

    for (UINT i = 0; i < sphere.Vertices.size(); ++i, ++j)
    {
        CustomVertex newData;
        newData.Pos = sphere.Vertices[i].Position;
        newData.Normal = sphere.Vertices[i].Normal;
        vertices.push_back(newData);
    }

    for (UINT i = 0; i < cylinder.Vertices.size(); ++i, ++j)
    {
        CustomVertex newData;
        newData.Pos = cylinder.Vertices[i].Position;
        newData.Normal = cylinder.Vertices[i].Normal;
        vertices.push_back(newData);
    }

    D3D11_BUFFER_DESC vbd;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.ByteWidth = sizeof(CustomVertex) * static_cast<UINT>(vertices.size());
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    vbd.StructureByteStride = 0;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    D3D11_SUBRESOURCE_DATA vsd;
    vsd.pSysMem = &vertices[0];

    result = m_d3dDevice->CreateBuffer(&vbd, &vsd, &m_vertexBuffer);
    if (FAILED(result))
    {
//.........这里部分代码省略.........
开发者ID:tczzyzymj,项目名称:Prectice,代码行数:101,代码来源:LightSkull.cpp

示例11: BuildShapeGeometryBuffers

void LitSkullApp::BuildShapeGeometryBuffers()
{
	GeometryGenerator::MeshData box;
	GeometryGenerator::MeshData grid;
	GeometryGenerator::MeshData sphere;
	GeometryGenerator::MeshData cylinder;


	GeometryGenerator geoGen;
	geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);
	geoGen.CreateGrid(160.f, 160.f, 50, 50, grid);
	//geoGen.CreateSphere(0.5f, 20, 20, sphere);
	geoGen.CreateGeosphere(0.5f, 3, sphere);
	geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20, cylinder);

	UINT boxVertexCount = box.Vertices.size();
	UINT gridVertexCount = grid.Vertices.size();
	UINT sphereVertexCount = sphere.Vertices.size();
	UINT cylinderVertexCount = cylinder.Vertices.size();
	UINT totalVertexCount = boxVertexCount + gridVertexCount + sphereVertexCount + cylinderVertexCount;


	m_uBoxIndexCount = box.Indices.size();
	m_uGridIndexCount = grid.Indices.size();
	m_uSphereIndexCount = sphere.Indices.size();
	m_uCylinderIndexCount = cylinder.Indices.size();
	UINT totalIndexCount = m_uBoxIndexCount + m_uGridIndexCount + m_uSphereIndexCount + m_uCylinderIndexCount;

	m_uBoxVertexOffset = 0;
	m_uGridVertexOffset = m_uBoxVertexOffset + boxVertexCount;
	m_uSphereVertexOffset = m_uGridVertexOffset + gridVertexCount;
	m_uCylinderVertexOffset = m_uSphereVertexOffset + sphereVertexCount;

	m_uBoxIndexOffset = 0;
	m_uGridIndexOffset = m_uBoxIndexOffset + m_uBoxIndexCount;
	m_uSphereIndexOffset = m_uGridIndexOffset + m_uGridIndexCount;
	m_uCylinderIndexOffset = m_uSphereIndexOffset + m_uSphereIndexCount;


	std::vector<Vertex::PosNormal> vertices(totalVertexCount);
	XMFLOAT4 black(0.0f, 0.0f, 0.0f, 1.0f);



	for (UINT k = m_uBoxVertexOffset, i = 0; i < boxVertexCount; ++i)
	{
		vertices[k + i].Pos = box.Vertices[i].Position;
		vertices[k + i].Normal = box.Vertices[i].Normal;
	}

	for (UINT k = m_uGridVertexOffset, i = 0; i < gridVertexCount; ++i)
	{
		vertices[k + i].Pos = grid.Vertices[i].Position;
		vertices[k + i].Normal = grid.Vertices[i].Normal;
	}

	for (size_t k = m_uSphereVertexOffset, i = 0; i < sphereVertexCount; ++i)
	{
		vertices[k + i].Pos = sphere.Vertices[i].Position;
		vertices[k + i].Normal = sphere.Vertices[i].Normal;
	}

	for (size_t k = m_uCylinderVertexOffset, i = 0; i < cylinderVertexCount; ++i)
	{
		vertices[k + i].Pos = cylinder.Vertices[i].Position;
		vertices[k + i].Normal = cylinder.Vertices[i].Normal;
	}

	{
		D3D11_BUFFER_DESC vbd;
		vbd.Usage = D3D11_USAGE_IMMUTABLE;//jingz todo 为什么CPU要访问和修改??
		vbd.ByteWidth = sizeof(Vertex::PosNormal) * totalVertexCount;
		vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		vbd.CPUAccessFlags = 0;
		vbd.MiscFlags = 0;
		vbd.StructureByteStride = 0;
		D3D11_SUBRESOURCE_DATA initDate;
		initDate.pSysMem = &vertices[0];
		HR(m_pD3dDevice->CreateBuffer(&vbd, &initDate, &m_pShapesVB));
	}



	{
		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;
		ibd.Usage = D3D11_USAGE_IMMUTABLE;//jingz todo 为什么CPU要访问和修改??
		ibd.ByteWidth = sizeof(UINT) * totalIndexCount;
		ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
		ibd.CPUAccessFlags = 0;
		ibd.MiscFlags = 0;
		ibd.StructureByteStride = 0;
		D3D11_SUBRESOURCE_DATA initDate;
		initDate.pSysMem = &indices[0];
		HR(m_pD3dDevice->CreateBuffer(&ibd, &initDate, &m_pShapesIB));
//.........这里部分代码省略.........
开发者ID:wjingzhe,项目名称:DX11,代码行数:101,代码来源:LitSkullDemo.cpp

示例12:

Box::Box()
{
	GeometryGenerator gen;

	gen.CreateBox(*m_Data);
}
开发者ID:Shadow864,项目名称:DirectX11,代码行数:6,代码来源:ModelObject.cpp

示例13: BuildGeometryBuffers

void Shape::BuildGeometryBuffers()
{
	GeometryGenerator::MeshData grid;
	GeometryGenerator::MeshData box;
	GeometryGenerator::MeshData sphere;
	GeometryGenerator::MeshData cylinder;

	GeometryGenerator geoGen;
	geoGen.CreateGrid(20.0f, 30.0f, 60, 40, grid);
	geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);
	geoGen.CreateGeosphere(0.5f, 3, sphere);
	//geoGen.CreateSphere(1.0f, 30, 30, sphere);
	geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 30, 30, cylinder);

	mGridVertexOffset		= 0;
	mBoxVertexOffset		= grid.Vertices.size();
	mSphereVertexOffset		= mBoxVertexOffset + box.Vertices.size();
	mCylinderVertexOffset	= mSphereVertexOffset + sphere.Vertices.size();

	mGridIndexCount			= grid.Indices.size();
	mBoxIndexCount			= box.Indices.size();
	mSphereIndexCount		= sphere.Indices.size();
	mCylinderIndexCount		= cylinder.Indices.size();

	mGridIndexOffset		= 0;
	mBoxIndexOffset			= mGridIndexCount;
	mSphereIndexOffset		= mBoxIndexOffset + mBoxIndexCount;
	mCylinderIndexOffset	= mSphereIndexOffset + mSphereIndexCount;

	UINT totalVertexCount =
		box.Vertices.size() +
		grid.Vertices.size() +
		sphere.Vertices.size() +
		cylinder.Vertices.size();

	UINT totalIndexCount =
		mBoxIndexCount +
		mGridIndexCount +
		mSphereIndexCount +
		mCylinderIndexCount;
#pragma region Create Vertices Buffer
	std::vector<Vertex> vertices(totalVertexCount);
	XMFLOAT4 color = *(XMFLOAT4*)&Colors::Red;

	UINT k = 0;
	for ( size_t i = 0; i < grid.Vertices.size(); ++i, ++k )
	{
		vertices[k].Pos = grid.Vertices[i].Position;
		vertices[k].Color = *(XMFLOAT4*)&Colors::Blue;
	}

	for ( size_t i = 0; i < box.Vertices.size(); ++i, ++k )
	{
		vertices[k].Pos = box.Vertices[i].Position;
		vertices[k].Color = *(XMFLOAT4*)&Colors::Magenta;
	}

	for ( size_t i = 0; i < sphere.Vertices.size(); ++i, ++k )
	{
		vertices[k].Pos = sphere.Vertices[i].Position;
		vertices[k].Color = *(XMFLOAT4*)&Colors::Yellow;
	}

	for ( size_t i = 0; i < cylinder.Vertices.size(); ++i, ++k )
	{
		vertices[k].Pos = cylinder.Vertices[i].Position;
		vertices[k].Color = *(XMFLOAT4*)&Colors::Red;
	}

	D3D11_BUFFER_DESC vbd;
	vbd.Usage = D3D11_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof(Vertex)*totalVertexCount;
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = 0;
	vbd.MiscFlags = 0;
	vbd.StructureByteStride = 0;
	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = &vertices[0];
	HR(mD3DDevice->CreateBuffer(&vbd, &vinitData, &mShapeVB));
#pragma endregion

#pragma region Create Indices Buffer
	std::vector<UINT> indices;
	indices.clear();
	indices.insert(indices.end(), grid.Indices.begin(), grid.Indices.end());
	indices.insert(indices.end(), box.Indices.begin(), box.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;
	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, &mShapeIB));
#pragma endregion
//.........这里部分代码省略.........
开发者ID:Vampire-Z-V,项目名称:D3D11_Demo,代码行数:101,代码来源:Shape.cpp

示例14: XMMatrixIdentity

//Makes a Square by default 
Entity::Entity(int type, std::string label, float width, float height, float depth) :
mPosition(0.0f, 0.0f, 0.0f),
mShadowScale(0.0f, 0.0f, 0.0f),
mRight(1.0f, 0.0f, 0.0f),
mUp(0.0f, 1.0f, 0.0f),
mLook(0.0f, 0.0f, 1.0f),
prevPitch(0.0f),
rotationY(0.0f),
prevRoll(0.0f),
origTexScale(1.0f, 1.0f, 1.0f),
texTrans(0.0f, 0.0f, 0.0f),
texTransMult(0.0f, 0.0f, 0.0f),
mGoToPos(0.0f, 0.0f, 0.0f),
currProgress(0.0f),
rotationZ(0.0f),
mDistanceLeft(0.0f),
mTexWidth(0.0f),
mTexHeight(0.0f),
mUpDown(false),
mGrowing(false),
mSquishX(false),
mSquishY(false),
mSquishZ(false),
mOrigY(0.0f),
mOrigX(0.0f),
mOrigZ(0.0f),
mGrowOut(false),
mHeightToGo(0.0f),
mScale(1.0f),
mWidth(width),
mHeight(height),
mDepth(depth),
hovering(false),
useTexTrans(false),
progressBar(false),
goToPos(false),
billboard(false),
flipUpright(false),
reverseLook(false),
mDead(false),
mSpinning(false),
mExplode(false),
mBasicTexTrans(false),
mUseAnimation(false),
mUseAAB(false),
mUseAABOnce(false),
mGoUp(true),
mBackFaceCull(true),
mGoDown(false),
mSideToSide(false),
mPulse(false),
mOrbit(false),
turnAngle(0.0f),
explosionDist(0.0f),
mAnim(0),
movementMult(0.0f),
mFlipping(false),
mRolling(false),
mBackAndForth(false),
mGrow(true),
mShrink(false),
mGrowIn(false),
mFlipTexture(false),
mTexRotate(false),
mLabel(label)
{
	//SET MATERIAL
	mMat.Ambient	= XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	mMat.Diffuse	= XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	mMat.Specular	= XMFLOAT4(1.0f, 1.0f, 1.0f, 48.0f);

	GeometryGenerator geoGen;

	//FLOOR PLANE
	XMMATRIX I = XMMatrixIdentity();
	XMStoreFloat4x4(&mWorld, I); XMStoreFloat4x4(&mShadowTrans, I);

	switch (type)
	{
	case 0: geoGen.CreateGrid(width, height, 2, 2, mGrid);					break;
	case 1: geoGen.CreateSphere(width, height, height, mGrid);/*height is slice count .. width for radius*/ break;
	case 2: geoGen.CreateUprightSquare(width, height, mGrid);				break;
	case 3: geoGen.CreateBox(width, height, depth, mGrid);					break;
	case 4: geoGen.CreateFrontandBackFace(width, height, depth, mGrid);		break;
	case 5: geoGen.CreateCylinder(width, depth, height, 15, 2, mGrid);		break;
	case 6: geoGen.CreateBox2Tex(width, height, depth, mGrid);				break;
	}

	mIndexCount = mGrid.Indices.size();
	mMeshVertices.resize(mGrid.Vertices.size());
}
开发者ID:JustinMorritt,项目名称:DudeWheresMyIQ,代码行数:92,代码来源:Entity.cpp

示例15: BuildObjectBuffers

// @brief 生成天体对象的Buffers
void SuperSolarSystemApp::BuildObjectBuffers( )
{
	GeometryGenerator geoGen;
	GeometryGenerator::MeshData starMash;
	GeometryGenerator::MeshData iceCubeMash;

	geoGen.CreateSphere( 1.0f, 40, 40, starMash );
	geoGen.CreateBox( 1.0f, 1.0f, 1.0f, iceCubeMash );

	//
	// 缓存偏移信息和数量信息, 以及冰立方的各个面的法向量
	//

	mLTVertexOffset[LTVT_STAR]     = 0;
	mLTVertexOffset[LTVT_ICECUBE]  = starMash.Vertices.size( );

	mLTIndexCount[LTVT_STAR]       = starMash.Indices.size( );
	mLTIndexCount[LTVT_ICECUBE]    = iceCubeMash.Indices.size( );

	mLTIndexOffset[LTVT_STAR]	   = 0;
	mLTIndexOffset[LTVT_ICECUBE]   = starMash.Indices.size( );

	for ( int i = 0; i < 6; i++ )
	{
		mIceCubeNormals[i] = iceCubeMash.Vertices[i * 4].Normal;
	}

	//
	// 创建顶点缓冲
	//

	UINT totVertexCount =
		starMash.Vertices.size( ) +
		iceCubeMash.Vertices.size( );

	std::vector<Vertex::NormalObjVertex> vertices;
	vertices.resize( totVertexCount );

	UINT k = 0;
	for ( size_t i = 0; i < starMash.Vertices.size( ); i++, k++ )
	{
		vertices[k].Pos    = starMash.Vertices[i].Position;
		vertices[k].Normal = starMash.Vertices[i].Normal;
		vertices[k].Tex    = starMash.Vertices[i].TexC;
	}

	for ( size_t i = 0; i < iceCubeMash.Vertices.size( ); i++, k++ )
	{
		vertices[k].Pos    = iceCubeMash.Vertices[i].Position;
		vertices[k].Normal = iceCubeMash.Vertices[i].Normal;
		vertices[k].Tex    = iceCubeMash.Vertices[i].TexC;
	}

	// 顶点缓冲创建第1步, 填充描述缓冲的 D3D11_BUFFER_DESC
	D3D11_BUFFER_DESC vbd;
	// Usage指定如何使用这个缓冲, 这里指定 D3D11_USAGE_IMMUTABLE, 表明缓冲一旦创建后便不再更改
	vbd.Usage = D3D11_USAGE_IMMUTABLE;
	// 按字节衡量的顶点缓冲大小
	vbd.ByteWidth = sizeof( Vertex::NormalObjVertex ) * totVertexCount;
	// 对于顶点缓冲, 指定 D3D11_BIND_VERTEX_BUFFER
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	// 指定CPU如何访问缓冲, 如果之前Usage指定了D3D11_USAGE_IMMUTABLE, 那就设为0
	vbd.CPUAccessFlags = 0;
	// 在顶点缓冲中指定0
	vbd.MiscFlags = 0;
	// 这个参数只对结构缓冲有效, 其余缓冲设为0
	vbd.StructureByteStride = 0;

	// 顶点缓冲创建第2步, 填充 D3D11_SUBRESOURCE_DATA, 指定顶点数据
	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = &vertices[0];

	// 顶点缓冲创建第3步, 创建顶点缓冲
	HR( mD3dDevice->CreateBuffer( &vbd, &vinitData, &mLightTexVB ) );

	//
	// 创建索引缓冲
	//

	std::vector<UINT> indices;
	indices.insert( indices.end( ), starMash.Indices.begin( ), starMash.Indices.end( ) );
	indices.insert( indices.end( ), iceCubeMash.Indices.begin( ), iceCubeMash.Indices.end( ) );

	UINT totIndexCount =
		starMash.Indices.size( ) +
		iceCubeMash.Indices.size( );

	D3D11_BUFFER_DESC ibd;
	ibd.Usage = D3D11_USAGE_IMMUTABLE;
	ibd.ByteWidth = sizeof( UINT ) * totIndexCount;
	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, &mLightTexIB ) );
}
开发者ID:RanTaimu,项目名称:SuperSolarSystem,代码行数:99,代码来源:SolarSystemMain.cpp


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