本文整理汇总了C++中GeometryGenerator::CreateCylinder方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryGenerator::CreateCylinder方法的具体用法?C++ GeometryGenerator::CreateCylinder怎么用?C++ GeometryGenerator::CreateCylinder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeometryGenerator
的用法示例。
在下文中一共展示了GeometryGenerator::CreateCylinder方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Init
bool cCylinder::Init()
{
GeometryGenerator::MeshData grid;
GeometryGenerator geoGen;
geoGen.CreateCylinder(10.0f, 5.0f, 10.0f, 6, 6, grid);
m_GridIndexCount = static_cast<UINT>(grid.Indices.size());
std::vector<Vertex::Simple> vertices(grid.Vertices.size());
for (UINT i = 0; i < grid.Vertices.size(); ++i)
{
vertices[i].Pos = grid.Vertices[i].Position;
vertices[i].Color = (const float*)&Colors::Black;
}
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 false;
}
示例2: InitBase
void ObjectsRenderer::InitBase()
{
// Init base objects
BasicObjectData* objectData = new BasicObjectData();
objectData->UseIndex = true;
objectData->UseEx = true;
// Init shapes
GeometryGenerator::MeshData box;
GeometryGenerator::MeshData grid;
GeometryGenerator::MeshData cylinder;
GeometryGenerator geoGen;
geoGen.CreateBox(1.0f, 1.0f, 1.0f, box);
geoGen.CreateGrid(20.0f, 30.0f, 60, 40, grid);
geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20, cylinder);
// Cache the vertex offsets to each object in the concatenated vertex buffer.
int boxVertexOffset = 0;
int gridVertexOffset = box.Vertices.size();
int cylinderVertexOffset = gridVertexOffset + grid.Vertices.size();
// Cache the index count of each object.
int boxIndexCount = box.Indices.size();
int gridIndexCount = grid.Indices.size();
int cylinderIndexCount = cylinder.Indices.size();
// Cache the starting index for each object in the concatenated index buffer.
int boxIndexOffset = 0;
int gridIndexOffset = boxIndexCount;
int cylinderIndexOffset = gridIndexOffset + gridIndexCount;
UINT totalVertexCount =
box.Vertices.size() +
grid.Vertices.size() +
cylinder.Vertices.size();
UINT totalIndexCount =
boxIndexCount +
gridIndexCount +
cylinderIndexCount;
// Extract the vertex elements we are interested in and pack the
// vertices of all the meshes into one vertex buffer.
auto& vertices = objectData->VertexDataEx;
vertices.resize(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;
vertices[k].TangentU = box.Vertices[i].TangentU;
}
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;
vertices[k].TangentU = grid.Vertices[i].TangentU;
}
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;
vertices[k].TangentU = cylinder.Vertices[i].TangentU;
}
// Pack the indices of all the meshes into one index buffer.
auto& indices = objectData->IndexData;
indices.insert(indices.end(), box.Indices.begin(), box.Indices.end());
indices.insert(indices.end(), grid.Indices.begin(), grid.Indices.end());
indices.insert(indices.end(), cylinder.Indices.begin(), cylinder.Indices.end());
// Set unit data
XMFLOAT4X4 gridWorld, boxWorld, cylWorld[10];
XMMATRIX I = XMMatrixIdentity();
XMFLOAT4X4 One;
XMStoreFloat4x4(&One, I);
XMStoreFloat4x4(&gridWorld, I);
XMMATRIX boxScale = XMMatrixScaling(3.0f, 1.0f, 3.0f);
XMMATRIX boxOffset = XMMatrixTranslation(0.0f, 0.5f, 0.0f);
XMStoreFloat4x4(&boxWorld, XMMatrixMultiply(boxScale, boxOffset));
for (int i = 0; i < 5; ++i)
{
XMStoreFloat4x4(&cylWorld[i * 2 + 0], XMMatrixTranslation(-5.0f, 1.5f, -10.0f + i*5.0f));
XMStoreFloat4x4(&cylWorld[i * 2 + 1], XMMatrixTranslation(+5.0f, 1.5f, -10.0f + i*5.0f));
}
Material gridMat, cylinderMat, boxMat;
gridMat.Ambient = XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f);
//.........这里部分代码省略.........
示例3: 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;
//.........这里部分代码省略.........
示例4: 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));
//.........这里部分代码省略.........
示例5: 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);
//.........这里部分代码省略.........
示例6: 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))
{
//.........这里部分代码省略.........
示例7: 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));
//.........这里部分代码省略.........
示例8:
Cylinder::Cylinder(float bottomRadius, float topRadius, float height, UINT sliceCount, UINT stackCount)
{
GeometryGenerator gen;
gen.CreateCylinder(*m_Data, bottomRadius, topRadius, height, sliceCount, stackCount);
}
示例9: 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
//.........这里部分代码省略.........
示例10: 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());
}
示例11: BuildGeometryBuffers
void BoxApp::BuildGeometryBuffers()
{
GeometryGenerator::MeshData cylinder;
GeometryGenerator geoGen;
geoGen.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 10, cylinder);
mCylinderIndexCount = cylinder.Indices.size();
UINT totalVertexCount = cylinder.Vertices.size();
UINT totalIndexCount = mCylinderIndexCount;
// Create vertex buffer
Vertex verticesPrim[] =
{
{ XMFLOAT3(-1.0f, -1.0f, -1.0f), (const float*)&Colors::White }, // 0
{ XMFLOAT3(-1.0f, +1.0f, -1.0f), (const float*)&Colors::Black }, // 1
{ XMFLOAT3(+1.0f, +1.0f, -1.0f), (const float*)&Colors::Red }, // 2
{ XMFLOAT3(+1.0f, -1.0f, -1.0f), (const float*)&Colors::Green }, // 3
{ XMFLOAT3(-1.0f, -1.0f, +1.0f), (const float*)&Colors::Blue }, // 4
{ XMFLOAT3(-1.0f, +1.0f, +1.0f), (const float*)&Colors::Yellow }, // 5
{ XMFLOAT3(+1.0f, +1.0f, +1.0f), (const float*)&Colors::Cyan }, // 6
{ XMFLOAT3(+1.0f, -1.0f, +1.0f), (const float*)&Colors::Magenta }, // 7
{ XMFLOAT3(+0.0f, +1.0f, +0.0f), (const float*)&Colors::White }, // 8
//Octagonal Prism
//Top
{ XMFLOAT3(+3.0f, +1.0f, +0.0f), (const float*)&Colors::White }, // 9 0
{ XMFLOAT3(+2.5f, +1.0f, +1.0f), (const float*)&Colors::White }, // 10 1
{ XMFLOAT3(+3.5f, +1.0f, +1.0f), (const float*)&Colors::Black }, // 11 2
{ XMFLOAT3(+4.0f, +1.0f, +0.5f), (const float*)&Colors::Red }, // 12 3
{ XMFLOAT3(+4.0f, +1.0f, -0.5f), (const float*)&Colors::Green }, // 13 4
{ XMFLOAT3(+3.5f, +1.0f, -1.0f), (const float*)&Colors::Blue }, // 14 5
{ XMFLOAT3(+2.5f, +1.0f, -1.0f), (const float*)&Colors::Yellow }, // 15 6
{ XMFLOAT3(+2.0f, +1.0f, -0.5f), (const float*)&Colors::Cyan }, // 16 7
{ XMFLOAT3(+2.0f, +1.0f, +0.5f), (const float*)&Colors::Magenta }, // 17 8
//Bottom
{ XMFLOAT3(+3.0f, -1.0f, +0.0f), (const float*)&Colors::White }, // 18 0
{ XMFLOAT3(+2.5f, -1.0f, +1.0f), (const float*)&Colors::White }, // 19 1
{ XMFLOAT3(+3.5f, -1.0f, +1.0f), (const float*)&Colors::Black }, // 20 2
{ XMFLOAT3(+4.0f, -1.0f, +0.5f), (const float*)&Colors::Red }, // 21 3
{ XMFLOAT3(+4.0f, -1.0f, -0.5f), (const float*)&Colors::Green }, // 22 4
{ XMFLOAT3(+3.5f, -1.0f, -1.0f), (const float*)&Colors::Blue }, // 23 5
{ XMFLOAT3(+2.5f, -1.0f, -1.0f), (const float*)&Colors::Yellow }, // 24 6
{ XMFLOAT3(+2.0f, -1.0f, -0.5f), (const float*)&Colors::Cyan }, // 25 7
{ XMFLOAT3(+2.0f, -1.0f, +0.5f), (const float*)&Colors::Magenta }, // 26 8
};
std::vector<Vertex> vertices(totalVertexCount);
XMFLOAT4 white(1.0f, 1.0f, 1.0f, 0.5f);
UINT k = 0;
for (size_t i = 0; i < cylinder.Vertices.size(); ++i, ++k)
{
vertices[k].Pos = cylinder.Vertices[i].Position;
vertices[k].Color = white;
}
D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = (sizeof(Vertex)* 250);
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, &mBoxVB));
// Create the index buffer
UINT indicesPrim[] = {
//Pyramid
// front face
// 0, 1, 2,
0, 8, 3,
// back face
// 4, 6, 5,
4, 7, 8,
// left face
// 4, 5, 1,
4, 8, 0,
// right face
// 3, 2, 6,
3, 8, 7,
// top face
// 1, 5, 6,
// 1, 6, 2,
// bottom face
4, 0, 3,
//.........这里部分代码省略.........