Debug draw and Directx 11

Post Reply
andreahmed
Posts: 3
Joined: Tue Nov 18, 2014 9:50 pm

Debug draw and Directx 11

Post by andreahmed »

I'm trying to override Bullet physics Debug drawer and use DirectXTK line drawer functions. I'm getting random drawn lines when I try to use bullet debug drawer in combination with DXTK.

I tried to draw a simple aline in 3D but it never gets a perspective in the scene, even If I supplied the shader with the correct projection view matrix of the camera.

Here is my setup:

Code: Select all

BulletDebugDrawer::BulletDebugDrawer(cGraphics *graphics)
{
    if (graphics != nullptr)
    {
        m_pGraphics = graphics;
    }

    line = std::unique_ptr<PrimitiveBatch<VertexPositionColor>>(new PrimitiveBatch<VertexPositionColor>(m_pGraphics->getContext()));
    basicEffect = std::unique_ptr<BasicEffect>(new BasicEffect(m_pGraphics->getDevice()));

    basicEffect->SetProjection(m_pGraphics->getViewProjectionMatrix());
    basicEffect->SetVertexColorEnabled(true);

    void const* shaderByteCode;
    size_t byteCodeLength;

    basicEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength);

    m_pGraphics->getDevice()->CreateInputLayout(VertexPositionColor::InputElements,
        VertexPositionColor::InputElementCount,
        shaderByteCode, byteCodeLength,
        inputLayout.GetAddressOf());

}
void BulletDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& lineColor)
{
     CommonStates states( device );
     m_pGraphics->getContext()->OMSetBlendState( states.Opaque(), nullptr, 0xFFFFFFFF );
     m_pGraphics->getContext()->OMSetDepthStencilState( states.DepthNone(), 0 );
     m_pGraphics->getContext()->RSSetState( states.CullCounterClockwise() );

    basicEffect->Apply(m_pGraphics->getContext());
    m_pGraphics->getContext()->IASetInputLayout(inputLayout.Get());
    
    line->Begin();
    line->DrawLine(VertexPositionColor(XMFLOAT3(from.x(), from.y(), from.z()), XMFLOAT4(1, 0, 1, 1)),
        VertexPositionColor(XMFLOAT3(to.x(), to.y(), to.z()), XMFLOAT4(1, 0, 1, 1)));
     
    line->End();
 
}
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Debug draw and Directx 11

Post by xexuxjy »

That should be ok working like that.

Can you post your code where you draw with the cameras view,projection matrix ?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Debug draw and Directx 11

Post by Basroil »

Last I remember OGL and DX have different axis definitions, sure that's not causing an effect that looks "random"?
Post Reply