本文整理汇总了C++中GeometryGenerator::CreateGeosphere方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryGenerator::CreateGeosphere方法的具体用法?C++ GeometryGenerator::CreateGeosphere怎么用?C++ GeometryGenerator::CreateGeosphere使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeometryGenerator
的用法示例。
在下文中一共展示了GeometryGenerator::CreateGeosphere方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Geosphere::Geosphere(float radius, UINT numSubdivisions)
{
GeometryGenerator gen;
gen.CreateGeosphere(*m_Data, radius, numSubdivisions);
}
示例2: 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));
//.........这里部分代码省略.........
示例3: 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
//.........这里部分代码省略.........