Jump to content
  • Advertisement
Sign in to follow this  
ITboy_Lemon

DirectX about the matrix

This topic is 2088 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello every . I am new here .

I have a problem with the understanding of view matrix .

 

I draw a polyline with DrawPrimitive(D3DPT_LEINSTRIP , ...) in the x-y plane . And I put the eye in (0.0f,0.0f,-10.0f) . But I can not see the image .

But when I do not set the view matrix and projection matrix , the image will display . I do not know why .

 

This is my vertex buffer :

void Exercise::buildVB()
{
    //get Direct3D Device
    IDirect3DDevice9* _pDevice = m_pD3d->getDevice();

    //craete the vertex buffer
    HR(_pDevice->CreateVertexBuffer(6 * sizeof(VertexPos),D3DUSAGE_WRITEONLY,0,
        D3DPOOL_MANAGED,&m_pVB,0));

    //lock the vertex buffer
    VertexPos * _pData = NULL ;
    HR(m_pVB->Lock(0,0,(void**)&_pData,0));

    //set the vertex
    /*_pData[0] = VertexPos(0.0f, 0.0f, 0.0f);
    _pData[1] = VertexPos(1.0f, 0.0f, -3.0f);
    _pData[2] = VertexPos(3.0f, 0.0f, -2.0f);
    _pData[3] = VertexPos(2.0f, 0.0f, -1.0f);
    _pData[4] = VertexPos(2.5f, 0.0f, 1.0f);
    _pData[5] = VertexPos(1.0f, 0.0f, 3.0f);*/
    _pData[0] = VertexPos(0.0f, 0.0f, 0.0f);
    _pData[1] = VertexPos(0.1f, -0.3f,0.0f );
    _pData[2] = VertexPos(0.3f, -0.2f, 0.0f);
    _pData[3] = VertexPos(0.2f, -0.1f,0.0f );
    _pData[4] = VertexPos(0.25f, 0.1f,0.0f );
    _pData[5] = VertexPos(0.1f, 0.3f,0.0f );

    
    //unlock the vertex buffer
    HR(m_pVB->Unlock());
}

 

This is the draw method which draw the image :

void Exercise::draw()
{
    //get Direct3D Device
    IDirect3DDevice9* _pDevice = m_pD3d->getDevice();

    //set stream source
    HR(_pDevice->SetStreamSource(0,m_pVB,0,sizeof(VertexPos)));

    //set the index
    //HR(_pDevice->SetIndices(m_pIB));

    //set the vertex declaration
    HR(_pDevice->SetVertexDeclaration(VertexPos::_vertexDecl));

    //set the world matrix
    D3DXMATRIX _worldM ;
    HR(_pDevice->SetTransform(D3DTS_WORLD,D3DXMatrixIdentity(&_worldM)));

    //set the view matrix
    HR(_pDevice->SetTransform(D3DTS_VIEW,&m_ViewM));

    //set the projection matrix
    HR(_pDevice->SetTransform(D3DTS_PROJECTION,&m_ProjM));

    //set the render state
    HR(_pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME));

    //draw the primitive
    HR(_pDevice->DrawPrimitive(D3DPT_LINESTRIP,0,6));
    
}

 

Here is my code about the view matrix and projection matrix:

void Exercise::buildViewM()
{
    D3DXVECTOR3 _pos(0.0f,0.0f,-10);
    D3DXVECTOR3 _target(0.0f,0.0f,0.0f);
    D3DXVECTOR3 _up(0.0f,1.0f,0.0f);
    D3DXMatrixLookAtLH(&m_ViewM,&_pos,&_target,&_up);
}

void Exercise::buildProjM()
{
    float _width = m_pD3d->getD3dParam().BackBufferWidth;
    float _height = m_pD3d->getD3dParam().BackBufferHeight;
    D3DXMatrixPerspectiveFovLH(&m_ProjM,D3DX_PI,_width/_height,1.0f,1000.0f);
}

 

Is there any problem with my code ???

I appriciate your help .

 

Share this post


Link to post
Share on other sites
Advertisement

In such cases always start out weeding options.

 

Turn off lightning. Turn off cull mode. Turn off zbuffer. Set Texture to NULL (yes, wireframes can be textured)

 

Make the camera controllable and look around :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!