DirectX 11通过旋转闪烁对象

时间:2017-04-16 22:11:14

标签: c++ directx-11

问题是如果我旋转三角形并且旋转超过1.6f它会开始闪烁。

example

这是一段代码:

- 这是一个在渲染器中初始化的小设置

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);

- 主循环的一部分

...
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 file

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;
}

1 个答案:

答案 0 :(得分:0)

调整投影矩阵的近平面...尝试降低 近平面值。