前田稔(Maeda Minoru)の超初心者のプログラム入門
#include "CreateModel.h" #include "MyCamera.h" Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer[3]; Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer[3]; uint32 m_indexCount[3]; CreateModel *m_CreateModel; MyCamera *my_camera[3]; |
Sample3DSceneRenderer::Sample3DSceneRenderer(const std::shared_ptr<DX::DeviceResources>& deviceResources) : m_loadingComplete(false), m_degreesPerSecond(45), m_tracking(false), m_deviceResources(deviceResources) { CreateDeviceDependentResources(); CreateWindowSizeDependentResources(); for(int i=0; i<3; i++) my_camera[i] = new MyCamera(m_deviceResources); } |
// 両方のシェーダーの読み込みが完了したら、メッシュを作成します。 auto createCubeTask = (createPSTask && createVSTask).then([this] () { m_CreateModel = new CreateModel(m_deviceResources); m_CreateModel->CreateCube(&m_vertexBuffer[0], &m_indexBuffer[0], &m_indexCount[0]); m_CreateModel->CreateCone(4, &m_vertexBuffer[1], &m_indexBuffer[1], &m_indexCount[1]); m_CreateModel->CreateCone(19, &m_vertexBuffer[2], &m_indexBuffer[2], &m_indexCount[2]); }); |
void Sample3DSceneRenderer::Rotate(float radians) { my_camera[0]->Model(0.0f, radians, 0.0f); float3 m_rot[] = {{ 0.0f, 0.4f, 0-radians },{ 0.0f, 0.3f, 0-radians }}; my_camera[1]->Model(m_rot, 1); my_camera[2]->Model(m_rot, 2); } |
void Sample3DSceneRenderer::Render() { if (!m_loadingComplete) { return; } auto context = m_deviceResources->GetD3DDeviceContext(); context->VSSetShader(m_vertexShader.Get(), nullptr, 0); context->PSSetShader(m_pixelShader.Get(), nullptr, 0); context->VSSetConstantBuffers( 0, 1, m_constantBuffer.GetAddressOf()); context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->IASetInputLayout(m_inputLayout.Get()); UINT stride = sizeof(VertexPositionColor); UINT offset = 0; //☆モデルを描画 for(int i=0; i<3; i++) { m_constantBufferData.projection = my_camera[i]->m_projection; m_constantBufferData.view = my_camera[i]->m_view; m_constantBufferData.model = my_camera[i]->m_model; context->UpdateSubresource( m_constantBuffer.Get(), 0, NULL, &m_constantBufferData, 0, 0); context->IASetVertexBuffers( 0, 1, m_vertexBuffer[i].GetAddressOf(), &stride, &offset); context->IASetIndexBuffer( m_indexBuffer[i].Get(), DXGI_FORMAT_R16_UINT, 0); context->DrawIndexed(m_indexCount[i], 0, 0); } } |