Thread: DirectX Shapes

Results 1 to 12 of 12
  1. #1
    CAFlames's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Where ever my imagination takes me
    Posts
    3,014
    Reputation
    202
    Thanks
    2,934
    My Mood
    Twisted

    DirectX Shapes

    Hi there,

    Here are some useful D3D (Non-Filled) Shapes I made.

    In Globals:
    Code:
    ID3DXLine *pLine;
    LPDIRECT3DDEVICE9 pDevice;
    struct D3D
    {
    float x, y, z, rhw;
    DWORD color;
    };
    __________________________________________________ ____________

    Triangle:
    Code:
    void DrawTriangle( float X, float Y, float X2, float Y2,  float X3, float Y3, D3DCOLOR Color, LPDIRECT3DDEVICE9 pDevice)
    {
    	D3D V[3] =
    {
    { (float)X, (float)Y, 0.0f, w, Color },
    { (float)X2, (float)Y2, 0.0f, w, Color },
    { (float)X3, (float)Y3, 0.0f, w, Color },
    };
    pDevice->DrawPrimitiveUP( D3DPT_LINELIST, 1, V, sizeof( D3D ) );
    }
    To use (In Present / Endscene):
    Code:
    DrawTriangle(  First X,  First Y,  Second X,  Second Y,  Third X,  Third Y, D3DCOLOR_ARGB(Alpha,Red,Green,Blue), pDevice);
    __________________________________________________ ____________


    Square:
    Code:
    void DrawSquare( int X, int Y, int w, int h, int thickness, D3DCOLOR Color, LPDIRECT3DDEVICE9 pDevice)
    {
    	D3DRECT S1 = { x, y, x + w, y+thickness };
    	pDevice->Clear( 1, &S1, D3DCLEAR_TARGET, Color, 0, 0 );
            D3DRECT S2 = { x, y, x + thickness, y + h };
    	pDevice->Clear( 1, &S2, D3DCLEAR_TARGET, Color, 0, 0 );
            D3DRECT S3 = { x+w, y, x + w - thickness, y + h };
    	pDevice->Clear( 1, &S3, D3DCLEAR_TARGET, Color, 0, 0 );
            D3DRECT S4 = { x, y + h, x + w, y + h - thickness };
    	pDevice->Clear( 1, &S4, D3DCLEAR_TARGET, Color, 0, 0 );
    }
    To use (In Present / Endscene):
    Code:
    DrawSquare( Starting X, Starting Y, Width, Height, How thick is border should be, D3DCOLOR_ARGB(Alpha, Red, Green, Blue), pDevice);
    __________________________________________________ ____________


    Line:
    Code:
    void DrawLine( float X, float Y, float X2, float Y2, int w, D3DCOLOR Color, LPDIRECT3DDEVICE9 pDevice)
    {
    	D3D V[2] =
    {
    { (float)X, (float)Y, 0.0f, w, Color },
    { (float)X2, (float)Y2, 0.0f, w, Color },
    };
    pDevice->DrawPrimitiveUP( D3DPT_LINELIST, 1, V, sizeof( D3D ) );
    }
    To use (In Present / Endscene):
    Code:
    DrawLine( Starting X, Starting Y, Ending X2, Ending Y2, Line Width, D3DCOLOR_ARGB( Alpha, Red, Green, Blue ), pDevice);
    __________________________________________________ ____________


    Circle (You MUST Create Line FIRST):
    Code:
    void DrawCircle(int x, int y, int radius, int numSides, DWORD Color) //Credits to Ac1d_Burn I think
    {
    D3DXVECTOR2 Line[128];
    float Step = PI * 2.0 / numSides;
    int Count = 0;
    for (float a=0; a < PI*2.0; a += Step)
    {
    float X1 = radius * cos(a) + x;
    float Y1 = radius * sin(a) + y;
    float X2 = radius * cos(a+Step) + x;
    float Y2 = radius * sin(a+Step) + y;
    Line[Count].x = X1;
    Line[Count].y = Y1;
    Line[Count+1].x = X2;
    Line[Count+1].y = Y2;
    Count += 2;
    }
    pLine->Begin();
    pLine->Draw(Line,Count,Color);
    pLine->End();
    }
    A Create-Line Method (In Present / Endscene and It is laggy and unreliable.. but it works):
    Code:
    if(pLine==0)
    		D3DXCreateLine(pDevice,&pLine);
    Then to Use the Circle:
    Code:
    DrawCircle(Center X, Center Y, Radius, number of sides?, D3DCOLOR_ARGB( Alpha, Red, Green, Blue));
    Don't ask me about the circle too much. I have not looked over it a lot..
    __________________________________________________ ____________


    Solid Square:
    Code:
    void FilledSquare( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* pDevice ) // Credits to whomever first made?
    {
    	D3DRECT rec = { x, y, x + w, y + h };
    	pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
    }
    To use (In Present / Endscene):
    Code:
    FilledSquare( Starting X, Starting Y, Width, Height, D3DCOLOR_ARGB( Alpha, Red, Green, Blue), pDevice );


    Thanks for looking and if you have any questions or recommendations, just leave me a mention and I will try to get back to you ASAP.
    Last edited by CAFlames; 07-03-2011 at 06:30 PM.

    Current Works:
    ---Horror Game






    Special thanks to drgnforce9 for my sig picture

    Quote Originally Posted by m_t_h View Post

    CAflames is one epic coder.

    Rep and thanks him.. or you're perma banned.

  2. The Following 2 Users Say Thank You to CAFlames For This Useful Post:

    [MPGH]Flengo (07-04-2011),higatoria (07-15-2011)

  3. #2
    flameswor10's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    12,528
    Reputation
    981
    Thanks
    10,404
    My Mood
    In Love
    I released a DrawTriangle method already

    Code:
    void FillARGBTriangle(int x1, int y1, int x2, int y2, int x3, int y3, D3DCOLOR color, IDirect3DDevice9 *pDevice)
    {
    	struct Vertex
    	{
    		float x,y,z,ht;
    		DWORD Color;
    	};
    
    	Vertex V[4];
        V[0].Color = V[1].Color = V[2].Color = V[3].Color = color;
        V[0].z   = V[1].z   = V[2].z   = V[3].z   = 0.0f;
        V[0].ht = V[1].ht = V[2].ht = V[3].ht = 0.0f;
    
    	V[0].x = (float)x1;
    	V[0].y = (float)y1;
    	V[1].x = (float)x2;
    	V[1].y = (float)y2;
    	V[2].x = (float)x3;
    	V[2].y = (float)y3;
    	V[3].x = (float)x1 + 1;
    	V[3].y = (float)y1 + 1;
    
    	pDevice->SetTexture(0, NULL);
    	pDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); 
    	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,V,sizeof(Vertex));
    }
    Last edited by flameswor10; 07-04-2011 at 04:59 AM.
    No I do not make game hacks anymore, please stop asking.


    Been MPGH Minion: 6 July 2011 - 1 August 2012

  4. The Following User Says Thank You to flameswor10 For This Useful Post:

    OBrozz (07-04-2011)

  5. #3
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    You were going so good with the draw triangle then you had to use the useless code and wrong function in DrawSquare.
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  6. #4
    Threadstarter
    We are the CONTRIBUFORCE
    MPGH Member
    CAFlames's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Where ever my imagination takes me
    Posts
    3,014
    Reputation
    202
    Thanks
    2,934
    My Mood
    Twisted
    Quote Originally Posted by topblast View Post
    You were going so good with the draw triangle then you had to use the useless code and wrong function in DrawSquare.
    This method works so its not wrong

    Current Works:
    ---Horror Game






    Special thanks to drgnforce9 for my sig picture

    Quote Originally Posted by m_t_h View Post

    CAflames is one epic coder.

    Rep and thanks him.. or you're perma banned.

  7. #5
    OBrozz's Avatar
    Join Date
    May 2011
    Gender
    male
    Posts
    820
    Reputation
    65
    Thanks
    813
    What is this pDevice->Clear? Sorry i don't code in C++. Just interested

  8. #6
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    Quote Originally Posted by CAFlames View Post


    This method works so its not wrong
    It works, because you guys like the easy way out of everything, not knowing the logic nor the reason behind things.

    LPDIRECT3DDEVICE9->Clear is used to CLEAR the back buffer, the color is just because it cant be blank, screens need a color.

    If you guys read a little more about what your using or take advice from someone who knows you will learn. You guys and your hacks with the nasty coding.

    Not only are you using a function for the wrong reason, your also using it more times then you Need to.


    Quote Originally Posted by OBrozz View Post
    What is this pDevice->Clear? Sorry i don't code in C++. Just interested
    It is a function From the "LPDIRECT3DDEVICE9" class/structure.

    DirectX SDK
    Last edited by topblast; 07-04-2011 at 10:00 PM.
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  9. The Following User Says Thank You to topblast For This Useful Post:

    OBrozz (07-05-2011)

  10. #7
    pashak's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Posts
    350
    Reputation
    29
    Thanks
    42
    why is this in the "Hack Coding Releases"?

  11. #8
    whit's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    7,170
    Reputation
    490
    Thanks
    2,252
    hmm why are you using 4 rect's and calling Clear 4 times in drawsquare?

  12. #9
    _Fk127_'s Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    724
    Reputation
    16
    Thanks
    208
    My Mood
    Bitchy
    Quote Originally Posted by OBrozz View Post
    What is this pDevice->Clear? Sorry i don't code in C++. Just interested
    Clears the viewport or a set of rectangles in the viewport to a specified RGBA color, clears the depth buffer, and erases the stencil buffer.
    -MSDN
    Here is the MSDN page



    Put this image in your signature if you support HTML5 development!

  13. #10
    Threadstarter
    We are the CONTRIBUFORCE
    MPGH Member
    CAFlames's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Where ever my imagination takes me
    Posts
    3,014
    Reputation
    202
    Thanks
    2,934
    My Mood
    Twisted
    Quote Originally Posted by whit View Post
    hmm why are you using 4 rect's and calling Clear 4 times in drawsquare?
    Why not? And for each side of the square O.o

    Current Works:
    ---Horror Game






    Special thanks to drgnforce9 for my sig picture

    Quote Originally Posted by m_t_h View Post

    CAflames is one epic coder.

    Rep and thanks him.. or you're perma banned.

  14. #11
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    Quote Originally Posted by CAFlames View Post


    Why not? And for each side of the square O.o
    LOL LBAR!!!!!!!!!1..

    WAIT WAIT WAIT!!!!! OH MY GODDDDDDDDDDDDDD!!!!!!!!!!!


    Clear is a 2D Square already... you dont have to do any sides. all it needs is the position(x, y) Width and Height (w, h)

    and the Structure RECT has 4 variables. which holds x, y, w and h. See what i mean dont know what they are doing.
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  15. #12
    Threadstarter
    We are the CONTRIBUFORCE
    MPGH Member
    CAFlames's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Where ever my imagination takes me
    Posts
    3,014
    Reputation
    202
    Thanks
    2,934
    My Mood
    Twisted
    Quote Originally Posted by topblast View Post


    LOL LBAR!!!!!!!!!1..

    WAIT WAIT WAIT!!!!! OH MY GODDDDDDDDDDDDDD!!!!!!!!!!!


    Clear is a 2D Square already... you dont have to do any sides. all it needs is the position(x, y) Width and Height (w, h)

    and the Structure RECT has 4 variables. which holds x, y, w and h. See what i mean dont know what they are doing.
    are you even looking at the thread? IT IS A HOLLOW SQUARE! As in it is only sides and no middle. so I am clearing each side around the square... not just the whole square including middle.

    Current Works:
    ---Horror Game






    Special thanks to drgnforce9 for my sig picture

    Quote Originally Posted by m_t_h View Post

    CAflames is one epic coder.

    Rep and thanks him.. or you're perma banned.