本文整理汇总了C++中GeometryGenerator::CreateSphere方法的典型用法代码示例。如果您正苦于以下问题:C++ GeometryGenerator::CreateSphere方法的具体用法?C++ GeometryGenerator::CreateSphere怎么用?C++ GeometryGenerator::CreateSphere使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeometryGenerator
的用法示例。
在下文中一共展示了GeometryGenerator::CreateSphere方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vertices
void D3DPBRApp::BuildGeometry()
{
GeometryGenerator::MeshData sphere;
GeometryGenerator geoGen;
geoGen.CreateSphere(5.f, 40, 40, sphere);
m_indexnum = sphere.Indices.size();
std::vector<Vertex::Basic32> vertices(sphere.Vertices.size());
for (int i = 0; i < vertices.size(); i++)
{
vertices[i].Normal = sphere.Vertices[i].Normal;
vertices[i].Pos = sphere.Vertices[i].Position;
vertices[i].Tangent = sphere.Vertices[i].TangentU;
vertices[i].Tex = sphere.Vertices[i].TexC;
}
D3D11_BUFFER_DESC dbd;
dbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
dbd.ByteWidth = sizeof(Vertex::Basic32) * vertices.size();
dbd.CPUAccessFlags = 0;
dbd.StructureByteStride = 0;
dbd.MiscFlags = 0;
dbd.Usage = D3D11_USAGE_DEFAULT;
D3D11_SUBRESOURCE_DATA vinitdata;
vinitdata.pSysMem = &vertices[0];
HR(md3dDevice->CreateBuffer(&dbd, &vinitdata, &m_pVB));
std::vector<UINT> indeces(sphere.Indices.begin(), sphere.Indices.end());
dbd.BindFlags = D3D11_BIND_INDEX_BUFFER;
dbd.ByteWidth = sizeof(UINT) * m_indexnum;
vinitdata.pSysMem = &indeces[0];
HR(md3dDevice->CreateBuffer(&dbd, &vinitdata, &m_pIB));
}
示例2: vertices
Sky::Sky(ID3D11Device* device, const std::wstring& cubemapFilename, float skySphereRadius)
{
HR(D3DX11CreateShaderResourceViewFromFileW(device, cubemapFilename.c_str(), 0, 0, &mCubeMapSRV, 0));
GeometryGenerator::MeshData sphere;
GeometryGenerator geoGen;
geoGen.CreateSphere(skySphereRadius, 30, 30, sphere);
std::vector<XMFLOAT3> vertices(sphere.Vertices.size());
for(size_t i = 0; i < sphere.Vertices.size(); ++i)
{
vertices[i] = sphere.Vertices[i].Position;
}
D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(XMFLOAT3) * vertices.size();
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
vbd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = &vertices[0];
HR(device->CreateBuffer(&vbd, &vinitData, &mVB));
mIndexCount = sphere.Indices.size();
D3D11_BUFFER_DESC ibd;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(USHORT) * mIndexCount;
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.StructureByteStride = 0;
ibd.MiscFlags = 0;
std::vector<USHORT> indices16;
indices16.assign(sphere.Indices.begin(), sphere.Indices.end());
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &indices16[0];
HR(device->CreateBuffer(&ibd, &iinitData, &mIB));
}
示例3: CreateShadow
void Shadow::CreateShadow(XMFLOAT3 playerPos, ID3D11DeviceContext* dc,ID3D11Device* dv)
{
XMMATRIX view = mCam.View();
XMMATRIX proj = mCam.Proj();
XMMATRIX viewProj = mCam.ViewProj();
GeometryGenerator::MeshData sphere;
GeometryGenerator geoMake;
world = XMLoadFloat4x4(&mSphereWorld);
worldInvTranspose = MathHelper::InverseTranspose(world);
worldViewProj = world*view*proj;
geoMake.CreateSphere(0.5f, 20, 20, sphere);
Effects::BasicFX->SetWorld(world);
Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
Effects::BasicFX->SetWorldViewProj(worldViewProj);
Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
mSphereIndexCount = sphere.Indices.size();
mSphereIndexOffset = 0;
// mSphereVertexCount = sphere.Vertices.size();
UINT totalVertexCount = sphere.Vertices.size();
UINT totalIndexCount = sphere.Indices.size();
std::vector<Vertex::PosNormalTexTan> vertices(totalVertexCount);
UINT k = 0;
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;
//vertices[k].TangentU = sphere.Vertices[i].TangentU;
}
D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex::PosNormalTexTan) * totalVertexCount;
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = &vertices[0];
HR(dv->CreateBuffer(&vbd, &vinitData, &mShapesVB));
dc->DrawIndexed(mSphereIndexCount, 0, 0);
}
示例4: GObject
GSphere::GSphere() : GObject()
{
GeometryGenerator geoGen;
GeometryGenerator::MeshData sphere;
geoGen.CreateSphere(0.5f, 20, 20, sphere);
mVertexCount = sphere.Vertices.size();
mIndexCount = sphere.Indices.size();
mVertices.resize(mVertexCount);
for (size_t i = 0; i < mVertexCount; ++i)
{
mVertices[i].Pos = sphere.Vertices[i].Position;
mVertices[i].Normal = sphere.Vertices[i].Normal;
mVertices[i].Tex = sphere.Vertices[i].TexC;
}
mIndices.resize(mIndexCount);
mIndices.insert(mIndices.begin(), sphere.Indices.begin(), sphere.Indices.end());
}
示例5: InitSphere
void ObjectsRenderer::InitSphere()
{
// Init spheres
BasicObjectData* objectData = new BasicObjectData();
objectData->UseIndex = true;
objectData->UseEx = false;
GeometryGenerator::MeshData sphere;
GeometryGenerator geoGen;
geoGen.CreateSphere(0.5f, 20, 20, sphere);
int sphereIndexCount = sphere.Indices.size();
// Extract the vertex elements we are interested in and pack the
// vertices of all the meshes into one vertex buffer.
auto& vertices = objectData->VertexData;
vertices.resize(sphere.Vertices.size());
for (size_t i = 0; i < sphere.Vertices.size(); ++i)
{
vertices[i].Pos = sphere.Vertices[i].Position;
vertices[i].Normal = sphere.Vertices[i].Normal;
vertices[i].Tex = sphere.Vertices[i].TexC;
}
// Pack the indices of all the meshes into one index buffer.
auto& indices = objectData->IndexData;
indices.assign(sphere.Indices.begin(), sphere.Indices.end());
// Set unit data
XMFLOAT4X4 sphereWorld[10];
for (int i = 0; i < 5; ++i)
{
XMStoreFloat4x4(&sphereWorld[i * 2 + 0], XMMatrixTranslation(-5.0f, 3.5f, -10.0f + i*5.0f));
XMStoreFloat4x4(&sphereWorld[i * 2 + 1], XMMatrixTranslation(+5.0f, 3.5f, -10.0f + i*5.0f));
}
Material sphereMat;
sphereMat.Ambient = XMFLOAT4(0.2f, 0.3f, 0.4f, 1.0f);
sphereMat.Diffuse = XMFLOAT4(0.2f, 0.3f, 0.4f, 1.0f);
sphereMat.Specular = XMFLOAT4(0.9f, 0.9f, 0.9f, 16.0f);
sphereMat.Reflect = XMFLOAT4(0.4f, 0.4f, 0.4f, 1.0f);
objectData->Units.resize(1);
// sphere
XMFLOAT4X4 One;
XMStoreFloat4x4(&One, XMMatrixIdentity());
auto& unit = objectData->Units[0];
unit.VCount = vertices.size();
unit.Base = 0;
unit.Count = sphereIndexCount;
unit.Start = 0;
unit.Worlds.assign(sphereWorld, sphereWorld + 10);
unit.Material.push_back(sphereMat);
unit.MaterialStepRate = 10;
unit.TextureFileNames.push_back(L"Media\\Textures\\stone.dds");
unit.TextureStepRate = 10;
unit.TextureTransform.push_back(One);
unit.TextureTransformStepRate = 10;
BasicFeatureConfigure objectFeature = { 0 };
objectFeature.LightCount = 3;
objectFeature.TextureEnable = true;
objectFeature.ReflectEnable = true;
objectFeature.ReflectFileName = L"Media\\Textures\\grasscube1024.dds";
m_sphere->Initialize(objectData, objectFeature);
}
示例6: 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 ) );
}
示例7: 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;
//.........这里部分代码省略.........
示例8: 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));
//.........这里部分代码省略.........
示例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);
//.........这里部分代码省略.........
示例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))
{
//.........这里部分代码省略.........
示例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());
}