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


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

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


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

示例1: Init

bool cGridMesh::Init()
{
	// 1. Á¤Á¡ Á¤º¸¸¦ ÃßÃâÇÑ´Ù.
	GeometryGenerator::MeshData grid;
	GeometryGenerator geoGen;

	geoGen.CreateGrid(160.0f, 160.0f, 50, 50, grid);

	m_GridIndexCount = static_cast<UINT>(grid.Indices.size());

	// 2. °¢ Á¤Á¡¿¡ ³ôÀÌ ÇÔ¼ö¸¦ Àû¿ëÇÏ°í ±× ³ôÀÌ¿¡ µû¸¥ »ö»óµµ ÀûÀýÈ÷ ¼³Á¤ÇÑ´Ù.
	// ±×µÚ ¹öÆÛ¸¦ »ý¼ºÇÑ´Ù.

	std::vector<Vertex::Simple> vertices(grid.Vertices.size());
	for (int i = 0; i < grid.Vertices.size(); ++i)
	{
		XMFLOAT3 p = grid.Vertices[i].Position;

		// Á¤Á¡ÀÇ ³ôÀ̸¦ ±¸ÇÑ´Ù.
		p.y = GetHeight(p.x, p.z);

		vertices[i].Pos = p;

		// ³ôÀÌ¿¡ ±âÃÊÇؼ­ Á¤Á¡ÀÇ »ö»óÀ» ¼³Á¤ÇÑ´Ù.
		if (p.y < -10.0f)
		{
			// Çغ¯ÀÇ ¸ð·¡»ö.
			vertices[i].Color = XMFLOAT4(1.0f, 0.96f, 0.62f, 1.0f);
		}
		else if(p.y < 5.0f)
		{
			// ¹àÀº ³ìȲ»ö.
			vertices[i].Color = XMFLOAT4(0.48f, 0.77f, 0.46f, 1.0f);
		}
		else if (p.y < 12.0f)
		{
			// £Àº ³ìȲ»ö.
			vertices[i].Color = XMFLOAT4(0.1f, 0.48f, 0.19f, 1.0f);
		}
		else if (p.y < 20.0f)
		{
			// £Àº °¥»ö
			vertices[i].Color = XMFLOAT4(0.1f, 0.48f, 0.19f, 1.0f);
		}
		else
		{
			// ʼn»ö(´«)
			vertices[i].Color = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		}
	}

	// ¹öÆÛ¸¦ »ý¼ºÇÑ´Ù.
	m_VB = MyDirectUtil::CreateVertexBuffer(&vertices[0], sizeof(Vertex::Simple) * static_cast<UINT>(vertices.size()), g_pD3DDevice);
	m_IB = MyDirectUtil::CreateIndexBuffer(&grid.Indices[0], sizeof(UINT) * m_GridIndexCount, g_pD3DDevice);

	return true;
}
开发者ID:SeungMinChoi,项目名称:JaraffeEngine_Old,代码行数:57,代码来源:cGridMesh.cpp

示例2: BuildBuffers

void DXPlane::BuildBuffers(ID3D11Device* md3dDevice)
{
	GeometryGenerator::MeshData plane;

	GeometryGenerator geoGen;
	geoGen.CreateGrid(1.0f, 1.0f, 60, 40, plane);

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

	// Cache the index count of each object.
	mPlaneIndexCount      = plane.Indices.size();

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

	UINT totalIndexCount = mPlaneIndexCount;

	// 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 < plane.Vertices.size(); ++i, ++k)
	{
		vertices[k].Pos    = plane.Vertices[i].Position;
		vertices[k].Normal = plane.Vertices[i].Normal;
		vertices[k].Tex    = plane.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, &mPlaneVB));

	// Pack the indices of all the meshes into one index buffer.
	std::vector<UINT> indices;
	indices.insert(indices.end(), plane.Indices.begin(), plane.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, &mPlaneIB));
}
开发者ID:mindmastre,项目名称:DX11-Framework,代码行数:56,代码来源:DXPlane.cpp

示例3: BuildLandGeometry

void WavesCSApp::BuildLandGeometry()
{
    GeometryGenerator geoGen;
    GeometryGenerator::MeshData grid = geoGen.CreateGrid(160.0f, 160.0f, 50, 50);

    //
    // Extract the vertex elements we are interested and apply the height function to
    // each vertex.  In addition, color the vertices based on their height so we have
    // sandy looking beaches, grassy low hills, and snow mountain peaks.
    //

    std::vector<Vertex> vertices(grid.Vertices.size());
    for(size_t i = 0; i < grid.Vertices.size(); ++i)
    {
        auto& p = grid.Vertices[i].Position;
        vertices[i].Pos = p;
        vertices[i].Pos.y = GetHillsHeight(p.x, p.z);
        vertices[i].Normal = GetHillsNormal(p.x, p.z);
		vertices[i].TexC = grid.Vertices[i].TexC;
    }

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

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

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

	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["grid"] = submesh;

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

示例4:

Wave::Wave(float width, float depth, UINT m, UINT n)
: m_Time(0)
, m_Width(width)
, m_Depth(depth)
, m_M(m)
, m_N(n)
{
	GeometryGenerator gen;

	gen.CreateGrid(*m_Data, width, depth, m, n);
}
开发者ID:Shadow864,项目名称:DirectX11,代码行数:11,代码来源:ModelObject.cpp

示例5: BuildLandGeometryBuffers

void BlendApp::BuildLandGeometryBuffers()
{
	GeometryGenerator::MeshData grid;
 
	GeometryGenerator geoGen;

	geoGen.CreateGrid(160.0f, 160.0f, 50, 50, grid);

	mLandIndexCount = grid.Indices.size();

	//
	// Extract the vertex elements we are interested and apply the height function to
	// each vertex.  
	//

	std::vector<Vertex> vertices(grid.Vertices.size());
	for(UINT 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;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = &vertices[0];
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mLandVB));

	//
	// Pack the indices of all the meshes into one index 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;
    D3D11_SUBRESOURCE_DATA iinitData;
	iinitData.pSysMem = &grid.Indices[0];
    HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mLandIB));
}
开发者ID:fxyyoung,项目名称:HyperEngine,代码行数:51,代码来源:BlendDemo.cpp

示例6: BuildWavesGeometry

void WavesCSApp::BuildWavesGeometry()
{
	GeometryGenerator geoGen;
	GeometryGenerator::MeshData grid = geoGen.CreateGrid(160.0f, 160.0f, mWaves->RowCount(), mWaves->ColumnCount());

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

	std::vector<std::uint32_t> indices = grid.Indices32;

	UINT vbByteSize = mWaves->VertexCount()*sizeof(Vertex);
	UINT ibByteSize = (UINT)indices.size()*sizeof(std::uint32_t);

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

	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_R32_UINT;
	geo->IndexBufferByteSize = ibByteSize;

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

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

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

示例7: BuildLandBuffers

void LightDemo::BuildLandBuffers()
{
   	GeometryGenerator::MeshData land;
	GeometryGenerator geoGen;

	geoGen.CreateGrid(160.0f, 160.0f, 50, 50, land);

	m_landIndexCount = land.indices.size();

	// Extract the vertex elements we are interested and apply the height function to
	// each vertex.  In addition, color the vertices based on their height so we have
	// sandy looking beaches, grassy low hills, and snow mountain peaks.

	std::vector<Vertex> vertices(land.vertices.size());
	for(size_t i = 0; i < land.vertices.size(); ++i)
	{
		XMFLOAT3 p = land.vertices[i].position;

		p.y = GetHeight(p.x, p.z);

		vertices[i].pos   = p;
        vertices[i].normal = GetHillNormal(p.x, p.z);
	}

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
	vbd.ByteWidth = sizeof(Vertex) * land.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_landVB.GetAddressOf()));

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

示例8: BuildLandGeometry

void TexWaves::BuildLandGeometry()
{
    GeometryGenerator geoGen;
    GeometryGenerator::MeshData grid = geoGen.CreateGrid(160.0f, 160.0f, 50, 50);

    std::vector<FrameResource::Vertex> vertices(grid.Vertices.size());
    for (size_t i = 0; i < grid.Vertices.size(); i++)
    {
        auto& p = grid.Vertices[i].Position;
        vertices[i].Pos = p;
        vertices[i].Pos.y = GetHillsHeight(p.x, p.z);
        vertices[i].Normal = GetHillsNormal(p.z, p.z);
        vertices[i].TexC = grid.Vertices[i].TexCoord;
    }
    const UINT vbByteSize = (UINT)vertices.size() * sizeof(FrameResource::Vertex);
    std::vector<std::uint16_t> indices = grid.GetIndices16();
    const UINT ibByteSize = (UINT)indices.size() * sizeof(uint16_t);

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

    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;

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

    geo->DrawArgs["grid"] = submesh;
    _geometries["landGeo"] = std::move(geo);
}
开发者ID:jonny2027,项目名称:DX12Samples,代码行数:37,代码来源:TexWaves.cpp

示例9: 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

示例10: 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

示例11: 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

示例12: BuildLandGeometryBuffers

void WavesApp::BuildLandGeometryBuffers()
{
	GeometryGenerator::MeshData grid;

	GeometryGenerator geoGen;
	geoGen.CreateGrid(160.f, 160.f, 50, 50, grid);
	m_uLandGridIndexCount = grid.Indices.size();

	//
	// Extract the vertex elements we are interested and apply the height function
	// to each vertex. In addition,color the vertices based on their so we have
	// sandy looking beaches,grassy low hills,and snow moutain peaks
	//
	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 = GetHeight(p.x, p.z);
		vertices[i].Pos = p;

		if (p.y < -10.f)
		{
			//Sandy beach color
			vertices[i].Color = XMFLOAT4(1.0f,0.96f,0.62f,1.0f);
		}
		else if (p.y < 5.0f)
		{
			// Light yellow-green.
			vertices[i].Color = XMFLOAT4(0.48f, 0.77f, 0.46f, 1.0f);
		}
		else if (p.y < 12.0f)
		{
			// Dark yellow-green.
			vertices[i].Color = XMFLOAT4(0.1f, 0.48f, 0.19f, 1.0f);
		}
		else if (p.y < 20.0f)
		{
			// Dark brown.
			vertices[i].Color = XMFLOAT4(0.45f, 0.39f, 0.34f, 1.0f);
		}
		else
		{
			// White snow.
			vertices[i].Color = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
		}


	}

	{
		D3D11_BUFFER_DESC vbd;
		vbd.Usage = D3D11_USAGE_IMMUTABLE;//jingz todo 为什么CPU要访问和修改??
		vbd.ByteWidth = sizeof(Vertex) * vertices.size();
		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_pLandVB));
	}

	{
		D3D11_BUFFER_DESC ibd;
		ibd.Usage = D3D11_USAGE_IMMUTABLE;//jingz todo 为什么CPU要访问和修改??
		ibd.ByteWidth = sizeof(UINT) * m_uLandGridIndexCount;
		ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
		ibd.CPUAccessFlags = 0;
		ibd.MiscFlags = 0;
		ibd.StructureByteStride = 0;
		D3D11_SUBRESOURCE_DATA initDate;
		initDate.pSysMem = &grid.Indices[0];
		HR(m_pD3dDevice->CreateBuffer(&ibd, &initDate, &m_pLandIB));
	}

}
开发者ID:wjingzhe,项目名称:DX11,代码行数:78,代码来源:WavesDemo.cpp

示例13: 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

示例14: 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

示例15: 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


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