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.