+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Ultimate Subscriber
    Join Date
    Oct 2009
    Posts
    31

    Triangles Class using lines

    Simple call i use, just to keep my pigeons in a row..

    Code:
    class Triangles
    {
        public:
    void Free(int p1x, int p1y, int p2x, int p2y, int p3x, int p3y,DWORD color);
    void Isosceles(int x, int y, int Width, int Height, DWORD color);
    void Right(int x, int y, int Width, int Height, DWORD color);
    };
    Triangles Tri;
    
    
    void Triangles::Free(int p1x, int p1y, int p2x, int p2y, int p3x, int p3y,DWORD color)
    {
        D3DXVECTOR2 pD3DXLine[4];
        
        pD3DXLine[0].x = p1x;
        pD3DXLine[0].y = p1y;
        pD3DXLine[1].x = p2x;
        pD3DXLine[1].y = p2y;  
        pD3DXLine[2].x = p3x;
        pD3DXLine[2].y = p3y;  
        pD3DXLine[3].x = p1x;
        pD3DXLine[3].y = p1y;
        Line->Begin( );
        Line->Draw( pD3DXLine, 4, color );
        Line->End( );
    }
    
    void Triangles::Isosceles(int x, int y, int Width, int Height, DWORD color)
    {
        D3DXVECTOR2 pD3DXLine[4];
        
        pD3DXLine[0].x = x;//start point
        pD3DXLine[0].y = y;//start point
        pD3DXLine[1].x = (x+Width)/2;//top point
        pD3DXLine[1].y = y+Height;//top point
        pD3DXLine[2].x = x+Width;//far point
        pD3DXLine[2].y = y;//far point
        pD3DXLine[3].x = x;//return to first point
        pD3DXLine[3].y = y;//return to first point
        Line->Begin( );
        Line->Draw( pD3DXLine, 4, color );
        Line->End( );
    }
    
    void Triangles::Right(int x, int y, int Width, int Height, DWORD color)
    {
        D3DXVECTOR2 pD3DXLine[4];
        
        pD3DXLine[0].x = x;//start point
        pD3DXLine[0].y = y;//start point
        pD3DXLine[1].x = x;//top point
        pD3DXLine[1].y = y+Height;//top point
        pD3DXLine[2].x = x+Width;//far point
        pD3DXLine[2].y = y;//far point
        pD3DXLine[3].x = x;//return to first point
        pD3DXLine[3].y = y;//return to first point
        Line->Begin( );
        Line->Draw( pD3DXLine, 4, color );
        Line->End( );
    }
    you'll need to setup llines using ID3DXLine. use it or dont, i figured it would save some time..

    EDIT: you can also add anti-aliasing to the triangles with:

    Code:
    Line->SetAntialias( State);


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts