図0004a
void SquareSpriteGroup::OnCreate() {
float HelfSize = 0.5f;
//頂点配列
vector<VertexPositionColor> vertices = {
{ VertexPositionColor(Vec3(-HelfSize, HelfSize, 0), Col4(1.0f, 0.0f, 0.0f, 1.0f)) },
{ VertexPositionColor(Vec3(HelfSize, HelfSize, 0), Col4(0.0f, 1.0f, 0.0f, 1.0f)) },
{ VertexPositionColor(Vec3(-HelfSize, -HelfSize, 0), Col4(0.0f, 0.0f, 1.0f, 1.0f)) },
{ VertexPositionColor(Vec3(HelfSize, -HelfSize, 0), Col4(1.0f, 0.0f, 1.0f, 1.0f)) },
};
//インデックス配列
vector<uint16_t> indices = { 0, 1, 2, 1, 3, 2 };
//メッシュの作成
//頂点変更できない
m_SquareSpriteMesh = MeshResource::CreateMeshResource(vertices, indices, false);
//グループの配列の作成
m_SquareSpriteVec.assign(100, SquareSprite());
for (auto& v : m_SquareSpriteVec) {
v.m_LocalRot = Util::RandZeroToOne(true);
v.m_LocalRotVelocity = Util::RandZeroToOne(true) * 20.0f - 10.0f;
v.m_LocalPos = Vec2(0, 0);
v.m_LocalVelocity = Vec2(Util::RandZeroToOne(true) * 200.0f - 100.0f,
100 + Util::RandZeroToOne(true) * 100.0f);
v.m_LocalGravityVelocity = Vec2(0, 0);
}
///ルートシグネチャ作成
CreateRootSignature();
///デスクプリタヒープ作成
CreateDescriptorHeap();
///コンスタントバッファ作成
CreateConstantBuffer();
///パイプラインステート作成
CreatePipelineState();
///コマンドリスト作成
CreateCommandList();
}
for (auto& v : m_SquareSpriteVec) { v.m_LocalRot = Util::RandZeroToOne(true); v.m_LocalRotVelocity = Util::RandZeroToOne(true) * 20.0f - 10.0f; v.m_LocalPos = Vec2(0, 0); v.m_LocalVelocity = Vec2(Util::RandZeroToOne(true) * 200.0f - 100.0f, 100 + Util::RandZeroToOne(true) * 100.0f); v.m_LocalGravityVelocity = Vec2(0, 0); }
///デスクプリタヒープ作成 void SquareSpriteGroup::CreateDescriptorHeap() { for (auto& v : m_SquareSpriteVec) { v.CreateDescriptorHeap(); } }
void SquareSprite::CreateDescriptorHeap() { auto Dev = App::GetApp()->GetDeviceResources(); m_CbvSrvDescriptorHandleIncrementSize = Dev->GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); //CbvSrvデスクプリタヒープ(コンスタントバッファのみ) m_CbvSrvUavDescriptorHeap = DescriptorHeap::CreateCbvSrvUavHeap(1); //GPU側デスクプリタヒープのハンドルの配列の作成 m_GPUDescriptorHandleVec.clear(); CD3DX12_GPU_DESCRIPTOR_HANDLE CbvHandle( m_CbvSrvUavDescriptorHeap->GetGPUDescriptorHandleForHeapStart(), 0, 0 ); m_GPUDescriptorHandleVec.push_back(CbvHandle); }
///コンスタントバッファ作成 void SquareSpriteGroup::CreateConstantBuffer() { for (auto& v : m_SquareSpriteVec) { v.CreateConstantBuffer(); } }
void SquareSpriteGroup::OnUpdate() { float ElapsedTime = App::GetApp()->GetElapsedTime(); UpdateObjects(ElapsedTime); }
//各オブジェクトの位置等の変更 void SquareSpriteGroup::UpdateObjects(float ElapsedTime) { float h = static_cast<float>(App::GetApp()->GetGameHeight()); h /= 2.0f; for (auto& v : m_SquareSpriteVec) { if (v.m_LocalPos.y < -h) { v.m_LocalRot = Util::RandZeroToOne(true); v.m_LocalRotVelocity = Util::RandZeroToOne(true) * 20.0f - 10.0f; v.m_LocalPos = Vec2(0, 0); v.m_LocalVelocity = Vec2(Util::RandZeroToOne(true) * 200.0f - 100.0f, 100 + Util::RandZeroToOne(true) * 100.0f); v.m_LocalGravityVelocity = Vec2(0, 0); } else { v.m_LocalRot += v.m_LocalRotVelocity * ElapsedTime; v.m_LocalPos += v.m_LocalVelocity * ElapsedTime; v.m_LocalGravityVelocity += Vec2(0, -98.0f) * ElapsedTime; v.m_LocalPos += v.m_LocalGravityVelocity * ElapsedTime; } } }
void SquareSpriteGroup::DrawObject() {
//中略
//各スプライトごとの処理
for (auto& v : m_SquareSpriteVec) {
//デスクプリタヒープのセット
ID3D12DescriptorHeap* ppHeaps[] = { v.m_CbvSrvUavDescriptorHeap.Get() };
m_CommandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
//GPUデスクプリタヒープハンドルのセット
for (size_t i = 0; i < v.m_GPUDescriptorHandleVec.size(); i++) {
m_CommandList->SetGraphicsRootDescriptorTable(i, v.m_GPUDescriptorHandleVec[i]);
}
//インデックス描画
m_CommandList->DrawIndexedInstanced(m_SquareSpriteMesh->GetNumIndicis(), 1, 0, 0, 0);
}
//中略
}