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


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

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


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

示例1: GeoBuffer

void Map::GeoBuffer()
{
	for (int y = 0; y < Md_.height; y++)
	{
		for (int x = 0; x < Md_.width; x++)
		{
			float ID = (float)Md_.grid[x][y][0] - 1;
			float col = floor(ID / 52.0f);
			float row = ID - (col * 52.0f);
			float sx = 1.0f / 52.0f;
			float sy = 1.0f / 52.0f;
			XMMATRIX trans = XMMatrixTranslation(row, col, 0.0f);
			XMMATRIX scale = XMMatrixScaling(sx, sy, 1.0f);
			XMStoreFloat4x4(&mTexTransform[x + (y * Md_.width)], trans * scale);

			GeometryGenerator::MeshData box;

			GeometryGenerator geoGen;
			//geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);
			//geoGen.CreateFullscreenQuad(box); //Works
			//geoGen.CreateGrid(2.0f, 2.0f, 10, 10, box);
			//geoGen.CreateGeosphere(0.75f, 100, box);
			geoGen.CreateSquare(x, y, 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 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<GeometryGenerator::Vertex> vertices(totalVertexCount);

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

			D3D11_BUFFER_DESC vbd;
			vbd.Usage = D3D11_USAGE_IMMUTABLE;
			vbd.ByteWidth = sizeof(GeometryGenerator::Vertex) * totalVertexCount;
			vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
			vbd.CPUAccessFlags = 0;
			vbd.MiscFlags = 0;
			D3D11_SUBRESOURCE_DATA vinitData;
			vinitData.pSysMem = &vertices[0];
			pDev_->CreateBuffer(&vbd, &vinitData, &mBoxVB[x + (y * Md_.width)]);

			//
			// 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];
			pDev_->CreateBuffer(&ibd, &iinitData, &mBoxIB[x + (y * Md_.width)]);
		}
	}
}
开发者ID:Garrowni,项目名称:ARevenge,代码行数:81,代码来源:Map.cpp


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