2
問題是如果我旋轉三角形,並且旋轉超過1.6f,它開始閃爍。DirectX 11對象閃爍旋轉
這裏是一段代碼:
,尤其是圓形是其在渲染器initalized
mCamPosition = D3DXVECTOR3{ 0.0f, 0.0f, -0.5f };
mCamTarget = D3DXVECTOR3{ 0.0f, 0.0f, 0.0f };
mCamUp = D3DXVECTOR3{ 0.0f, 1.0f,0.0f };
D3DXMatrixLookAtLH(&mCamView, &mCamPosition, &mCamTarget, &mCamUp);
D3DXMatrixPerspectiveFovLH(&mCamProjection, 0.4f * static_cast<float32>(M_PI),
static_cast<float32>(pWindow->GetSize().Width)/static_cast<float32>(pWindow->GetSize().Height),
1.0f,
1000.0f);
-part主循環的一個小的設定
...
rotation += 0.0005f;
MeshTransform.SetRotation(rotation);
Renderer->Clear();
Renderer->Draw(Mesh, Shader, &MeshTransform);
Renderer->Display();
...
- 繪圖函數的一部分
D3DXMATRIX MeshTranslation;
D3DXMATRIX MeshRotaiton;
D3DXMATRIX MeshWorld;
D3DXMatrixIdentity(&MeshWorld);
D3DXMatrixIdentity(&MeshRotaiton);
D3DXMatrixIdentity(&MeshTranslation);
//Translation
D3DXMatrixTranslation(&MeshTranslation, pTransform->mPosition.X, pTransform->mPosition.Y, 0.0f);
//Rotation
D3DXVECTOR3 RotAxis{ 0.0f, 0.0f, 1.0f };
D3DXMatrixRotationAxis(&MeshRotaiton, &RotAxis, pTransform->mRotation);
MeshWorld = MeshRotaiton * MeshTranslation;
mWVP = MeshWorld * mCamView * mCamProjection;
D3DXMatrixTranspose(&mCBPerObject.WVP, &mWVP);
pContext->DeviceContext->UpdateSubresource(pPerObjectBuffer, NULL, nullptr, &mCBPerObject, NULL, NULL);
pContext->DeviceContext->VSSetConstantBuffers(0, 1, &pPerObjectBuffer);
pContext->DeviceContext->VSSetShader(pShader->cpVertexShader.Get(), 0, 0);
pContext->DeviceContext->PSSetShader(pShader->cpPixelShader.Get(), 0, 0);
...Drawing
-Shader文件
cbuffer cbPerObject
{
float4x4 WVP;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float4 Color : COLOR;
};
VS_OUTPUT VS(float4 InPosition : POSITION, float4 InColor : COLOR)
{
VS_OUTPUT Output;
Output.Position = mul(InPosition, WVP);
Output.Color = InColor;
return Output;
}
float4 PS(VS_OUTPUT Input) : SV_TARGET
{
return Input.Color;
}
我試了一個更高的值,它沒有工作,我試過一個較低的值它工作謝謝你! –
好吧,我編輯了我的答案..謝謝你的糾正 – Nain