DirectX Shapes

Posts 112 of 12 · Page 1 of 1
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.
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));
}
You were going so good with the draw triangle then you had to use the useless code and wrong function in DrawSquare.
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
What is this pDevice->Clear? Sorry i don't code in C++. Just interested
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
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
why is this in the "Hack Coding Releases"?
hmm why are you using 4 rect's and calling Clear 4 times in drawsquare?
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
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.
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.
Posts 112 of 12 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?