Nanashi-soft○プログラマ専用○DirectX11開発○
//メインループこれがまた,ちゃんと動くんだ(*'-')
MSG hMsg;
while(true){
while(PeekMessageW(&hMsg, NULL, 0, 0, PM_REMOVE)){
if(hMsg.message == WM_QUIT){
goto End;
}
TranslateMessage(&hMsg);
DispatchMessage(&hMsg);
}
//背景クリア
float ClearColor[] = {0.0f, 0.0f, 1.0f, 1.0f};
hpDeviceContext->ClearRenderTargetView(hpRenderTargetView, ClearColor);
//ワールド変換用行列を生成
XMMATRIX hWorld; //ワールド変換行列
//初期化
hWorld = XMMatrixIdentity();
XMMATRIX hView; //ビュー変換行列
XMVECTOR hEye = XMVectorSet(0.0f, 0.0f, -2.0f, 0.0f); //カメラの位置
XMVECTOR hAt = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); //焦点の位置
XMVECTOR hUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
hView = XMMatrixLookAtLH(hEye, hAt, hUp);
XMMATRIX hProjection; //透視射影変換行列
hProjection = XMMatrixPerspectiveFovLH(D3DXToRadian(45.0f), 16.0f/9.0f, 0.0f, 1000.0f);
//それらをシェーダーに送る
struct ConstantBuffer
{
XMMATRIX mWorld;
XMMATRIX mView;
XMMATRIX mProjection;
};
//constantバッファ生成
ID3D11Buffer* hpConstantBuffer = NULL;
hBufferDesc.ByteWidth = sizeof(ConstantBuffer);
hBufferDesc.Usage = D3D11_USAGE_DEFAULT;
hBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
hBufferDesc.CPUAccessFlags = 0;
hBufferDesc.MiscFlags = 0;
hBufferDesc.StructureByteStride = sizeof(float);
if(FAILED(hpDevice->CreateBuffer(&hBufferDesc, NULL, &hpConstantBuffer))){
MessageBoxW(hWnd, L"Create ConstantBuffer", L"Err", MB_ICONSTOP);
goto End;
}
//ID3D11DeviceContext* g_pImmediateContext = NULL;
ConstantBuffer hConstantBuffer;
hConstantBuffer.mWorld = XMMatrixTranspose(hWorld);
hConstantBuffer.mView = XMMatrixTranspose(hView);
hConstantBuffer.mProjection = XMMatrixTranspose(hProjection);
hpDeviceContext->UpdateSubresource(hpConstantBuffer, 0, NULL, &hConstantBuffer, 0, 0);
hpDeviceContext->VSSetConstantBuffers(0, 1, &hpConstantBuffer);
//描画
hpDeviceContext->Draw(TYOUTEN, 0);
hpDXGISwpChain->Present(0, 0);
}
XMMATRIX hRotate;2枚出てるww(冗談のつもりでした)
hRotate = XMMatrixRotationZ(D3DXToRadian(-45.0f));
hWorld = XMMatrixMultiply(hWorld, hRotate);
hConstantBuffer.mWorld = XMMatrixTranspose(hWorld);
hpDeviceContext->UpdateSubresource(hpConstantBuffer, 0, NULL, &hConstantBuffer, 0, 0);
hpDeviceContext->VSSetConstantBuffers(0, 1, &hpConstantBuffer);
//描画
hpDeviceContext->Draw(TYOUTEN, 0);
hpDXGISwpChain->Present(0, 0);