练习3.
(a)
//LINELIST std::array<VPosData, > posData = {
VPosData({ XMFLOAT3(-2.0f, -1.0f, +1.0f) }),
VPosData({ XMFLOAT3(-1.5f, +1.0f, +1.0f) }),
VPosData({ XMFLOAT3(-1.0f, -0.3f, +1.0f) }),
VPosData({ XMFLOAT3(-0.3f, +0.7f, +1.0f) }),
VPosData({ XMFLOAT3(-0.0f, -0.3f, +1.0f) }),
VPosData({ XMFLOAT3(+1.0f, +0.7f, +1.0f) }),
VPosData({ XMFLOAT3(+2.0f, +0.0f, +1.0f) }),
VPosData({ XMFLOAT3(+2.7f, +1.5f, +1.0f) }),
}; std::array<std::uint16_t, > indices =
{
,,,
,,,
,,,
,,,
,,,
,,,
};
(b)
//LINELIST std::array<std::uint16_t, > indices =
{
,,,,,,,
};
(c)
//LINELIST
std::array<std::uint16_t, > indices =
{
,,
,,
,,
,,
,,
,,
,,
,,
,,
,,
,,
,,
,
};
练习4:
//TRIANGLESTRIP std::array<VPosData, > posData = {
VPosData({ XMFLOAT3(-1.0f, -1.0f, -1.0f) }),
VPosData({ XMFLOAT3(+1.0f, -1.0f, -1.0f) }),
VPosData({ XMFLOAT3(+1.0f, -1.0f, +1.0f) }),
VPosData({ XMFLOAT3(-1.0f, -1.0f, +1.0f) }),
VPosData({ XMFLOAT3(-0.0f, +0.78f, +0.0f) }), }; std::array<VColorData, > colorData{
VColorData({ XMFLOAT4(Colors::Green) }),
VColorData({ XMFLOAT4(Colors::Green) }),
VColorData({ XMFLOAT4(Colors::Green) }),
VColorData({ XMFLOAT4(Colors::Green) }),
VColorData({ XMFLOAT4(Colors::Red) })
}; std::array<std::uint16_t, > indices =
{
,,,
,,, ,,,
,,,
,,,
,,,
};
在update中添加代码获得旋转效果:
XMMATRIX Ry; static float Y = 0.0f;
Ry = XMMatrixRotationY(Y);
Y += 0.001;
XMStoreFloat4x4(&mWorld, Ry);
添加另一个图形(新建buffer):
BoxApp.cpp
①修改ommandList:
std::unique_ptr<MeshGeometry> mBoxGeo02 = nullptr;
mCommandList->IASetVertexBuffers(, , &mBoxGeo02->VertexBufferView());//设置顶点buffer视图,起始接口也为0,顶点buffer数量依旧为1个 mCommandList->IASetIndexBuffer(&mBoxGeo02->IndexBufferView());//设置索引buffer视图 mCommandList->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);//不变 mCommandList->SetGraphicsRootDescriptorTable(, mCbvHeap->GetGPUDescriptorHandleForHeapStart());
mCommandList->DrawIndexedInstanced( mBoxGeo02->DrawArgs["cww"].IndexCount, , , , );//改变drawargs里的字符串,因为是另一个物体,用不同名字以区分