a simple line

New to directx, I don't need any textures or anything, but i need to make a simple wireframe model. And would like to know if there is an easy way to draw a 3d line just using 2 points as input(hopefully, as this is what im used to)



Answer this question

a simple line

  • Che Guevara

    Still lost, read the tutorials, and something just doesn't seem to click. C# by the way. I want to understand the code, but am lost when i see 

        { {0.0f, 0.0f, 0.0f}, D3DCOLOR_XRGB( 255, 0, 0 ) },
        { {1.0f, 1.0f, 1.0f}, D3DCOLOR_XRGB( 255, 0, 0 ) }

    Are those the points of the line, and why do i keep seeing this f everywhere. From what I understand directX sees Vector3 as a vector poking out from the origin (0,0,0). So say I wanted a vector(a line) in space from say (2,4,6) to (5,6,7) I would give Vector3 values (3,1,1) then transform it to (2,4,6), then what, or am I lost, i need some direction

  • pamt1984

    { {x, y, z}, D3DCOLOR_XRGB(red, green, blue)}

    f means they are single precisions floats rather than the doubles that most languages default to. DirectX uses single precision for speed.

    Whilst the vector (x,y,z) can mean a line from (0,0,0) to (x,y,z) in this case it just means the point (x,y,z). So jacks code creates an array of 2 points and then draws a line between them.

    You can also use the D3DX line class.

    Tutorials list for .Net here http://www.thezbuffer.com/categories/tutorials.aspx

    There's only one that I have found that shows drawing lines.
    http://www.drunkenhyena.com/cgi-bin/view_net_article.pl chapter=2;article=21



  • gmerideth

    We need more details than this... Smile

    DirectX 8 or 9 - which SDK version
    Language - C/C++/C#/VB.Net

    There is an ID3DXLine class that will handle 2D lines if you want that... alternatively you can just construct a series of line segments (D3DPT_LINELIST) or a line strip (D3DPT_LINESTRIP) using regular geometry.

    The following is a very brief fragment of how you might be able to draw a line:

    struct LineVertex
    {
        D3DXVECTOR3 position;
        DWORD colour;
    };

    LineVertex line[] =
    {
        { {0.0f, 0.0f, 0.0f}, D3DCOLOR_XRGB( 255, 0, 0 ) },
        { {1.0f, 1.0f, 1.0f}, D3DCOLOR_XRGB( 255, 0, 0 ) }
    };

    device->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE );
    device->DrawPrimitiveUP( D3DPT_LINELIST, 1, line, sizeof( LineVertex ) );

     


    There is, as you might guess, a huge amount more to it... you'll have to set up your device for one, configure any transform matrices and render states etc... I highly recommend you read through the 6 tutorials in the SDK.

    One final thing... if you want a wireframe mesh then you can following the "meshes" tutorial and get a regular mesh on screen and then use IDirect3DDevice9::SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME ) and it'll do all the wireframe magic for you!

    hth
    Jack


  • a simple line