• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lcy

drawing circle in directx

14 posts in this topic

Solid or line circle? Either way just use a textured quad. Use the DirectX SDK Texture Tool to create a .dds file that contains a texture of your circle and an alpha map that shows what parts of the texture are transparent. Load this .dds file to a texture that has the format D3DFMT_A8R8G8B8, enable alpha blending, render and *bam* you have a circle.
0

Share this post


Link to post
Share on other sites
Here's what I've done:

//-----------------------------------------------------------------------------------
//Draw a simple circle centered around the given point, using the given
//radius and color. This is in Screen Space (2D).
//-----------------------------------------------------------------------------------
void Draw2DCircle(POINT pt, float radius, D3DCOLOR color, LPDIRECT3DDEVICE9 dev)
{
const int NUMPOINTS = 24;
const float PI = 3.14159;

D3DTLVERTEX Circle[NUMPOINTS + 1];
int i;
float X;
float Y;
float Theta;
float WedgeAngle; //Size of angle between two points on the circle (single wedge)

//Precompute WedgeAngle
WedgeAngle = (float)((2*PI) / NUMPOINTS);

//Set up vertices for a circle
//Used <= in the for statement to ensure last point meets first point (closed circle)
for(i=0; i<=NUMPOINTS; i++)
{
//Calculate theta for this vertex
Theta = i * WedgeAngle;

//Compute X and Y locations
X = (float)(pt.x + radius * cos(Theta));
Y = (float)(pt.y - radius * sin(Theta));

Circle[i] = CreateD3DTLVERTEX(X, Y, 0.0f, 1.0f, color, 0.0f, 0.0f);
}

//Now draw the circle
dev->SetFVF(D3DFVF_TL);
dev->SetTexture(0, NULL);
dev->DrawPrimitiveUP(D3DPT_LINESTRIP, NUMPOINTS, &Circle[0], sizeof(Circle[0]));

}//Draw2DCircle


Edit - Coder: Used source instead of code tags. The code block is large enough, and it's much more clear now [smile]

[Edited by - Coder on July 27, 2004 11:59:34 AM]
0

Share this post


Link to post
Share on other sites
thank for reply
Teric the program got error
i am try to draw circle with wireframe in directx 9
i want the calculation of the circle in directx
0

Share this post


Link to post
Share on other sites
What was the error? Yes, my above code draws a wireframe circle (just the circumference, not filled) in DirectX 9.

EDIT: I just looked again, and I saw that there are a couple of things in there that need explanation. First is the CreateD3DTLVERTEX function:

struct D3DTLVERTEX
{
float fX;
float fY;
float fZ;
float fRHW;
D3DCOLOR Color;
float fU;
float fV;
};

//-----------------------------------------------------------------------------------
//CreateD3DTLVERTEX--Populate a D3DTLVERTEX structure
//-----------------------------------------------------------------------------------
D3DTLVERTEX CreateD3DTLVERTEX (float X, float Y, float Z, float RHW,
D3DCOLOR color, float U, float V)
{
D3DTLVERTEX v;

v.fX = X;
v.fY = Y;
v.fZ = Z;
v.fRHW = RHW;
v.Color = color;
v.fU = U;
v.fV = V;

return v;
}//CreateD3DTLVERTEX



And the other thing that needs explanation: D3DFVF_TL. This is a #define that I put together:

#define D3DFVF_TL (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)

0

Share this post


Link to post
Share on other sites
bool mrScreen::DrawCircle (float iCenterX, float iCenterY,
float iRadius, Unsigned int iRed,
Unsigned int iGreen, Unsigned intiBlue,
Unsigned int iAlpha, Unsigned intiVertices)
{

// the Algorithm is simple , a circle is a set of points and has a center and a radius ..etc

Unsigned int iColor;
iColor = D3DCOLOR_RGBA (iRed, iGreen, iBlue, iAlpha);
Vertex * pkVertices;
/* Allocate needed vertices */
pkVertices = new Vertex [iVertices + 1];

float fAngle = 0;
float fComplete;
floatiVertex;

/* Calculate each vertex position */
for (iVertex = 0; iVertex < iVertices; iVertex ++)
{
/* Percentage of circle already drawn */
fComplete = (float)iVertex / (float)iVertices;
pkVertices [iVertex].m_fX = (float) ((float)iCenterX +
((float)iRadius * cos (6.2831f*fComplete)));
pkVertices [iVertex].m_fY = (float) ((float)iCenterY +
((float)iRadius * sin (6.2831f*fComplete))); // Rx=r*sin(theta)

pkVertices [iVertex].m_fZ = 0; // We Are in 2D Space !
pkVertices [iVertex].m_fRHW = 1.0f; // Transformed Vertices
pkVertices [iVertex].m_iColor = iColor; // Your Circle Colour/Color
pkVertices [iVertex].m_ftU = 0; // U's Texture Co-ordinate
pkVertices [iVertex].m_ftV = 0;// V's Texture Co-ordinate
}

YourDevice->SetVertexShader (D3DFVF_MIRUSVERTEX);
YourDevice->DrawPrimitiveUP (D3DPT_LINESTRIP, iVertices,pkVertices, sizeof (Vertex)); // Draw The Circle!

delete [] pkVertices; // After Drawing,Free the Vertex Buffer
return true;
}


Ahmed Saleh.
Edited by Coder: code too wide, used source tags instead.

[Edited by - Coder on July 29, 2004 3:48:35 AM]
0

Share this post


Link to post
Share on other sites
Hi Teric,
dev->SetFVF(D3DFVF_TL); /<- Only found in DX9? How about DX8?

Another question to all: How to draw Arc and Eplise in DX8 or above?
Thanks
0

Share this post


Link to post
Share on other sites
Quote:
Original post by OrcishCoder
Hi Teric,
dev->SetFVF(D3DFVF_TL); /<- Only found in DX9? How about DX8?

Another question to all: How to draw Arc and Eplise in DX8 or above?
Thanks


Dev8->SetVertexShader();
0

Share this post


Link to post
Share on other sites
Quote:
Original post by OrcishCoder
Another question to all: How to draw Arc and Eplise in DX8 or above?
Thanks

An arc is a portion of a circle or elipse. An elipse is a circle with the radius biased in either the x- or y-axis.

To draw an elipse, bias like this:

pkVertices [iVertex].m_fX = (float) ((float)iCenterX +
((float)iRadius * xBias * cos (6.2831f*fComplete)));
pkVertices [iVertex].m_fY = (float) ((float)iCenterY +
((float)iRadius * yBias * sin (6.2831f*fComplete)));


To draw an arc, only calculate vertices in the area you need (ie, calculate positions in the loop for only a subset of those in the circle)

Or you could do everything my way and precalculate everything so you don't have to worry about the math .
0

Share this post


Link to post
Share on other sites
look up for Bresenham's circle algorithm. You basically draw 1/4 of the circle and flip it 3 more times to complete the circle. This is the code that I wrote a while back for a class, just replace the drawpixel routine to a specific API to plot a pixel for a given screen coordinate.

attempting to post code.
[SOURCE]
//Bresenham's circle algorithm
void drawCircle ()
{
int tx,ty;
int xp = 0;
int yp = rad;
//swap(centerX,centerY);
double d = 1-rad;
while(xp <= yp)
{

tx = xp+centerX;
ty = yp+centerY;

//second octant
drawPixle(tx,ty,1);
//third octant
drawPixle(xp-2*xp+centerX,ty,1);
//7th octant
drawPixle(tx,yp-2*(yp)+centerY,1);
//first octant
drawPixle(yp+centerX,xp+centerY,1);
//8th octant
drawPixle(yp+centerX,xp-2*xp+centerY,1);
//sixth octant
drawPixle(-1*xp+centerX,-yp+centerY,1);
//4th octant
drawPixle(-yp+centerX,(-xp+2*xp)+centerY,1);
//5th octant
drawPixle(-yp+centerX,-xp+centerY,1);

//go E
if(d < 0.0)
{
d = d + 2*xp + 3;
xp = xp+1;
}
else //go SE
{
d = d + 2*xp - 2*yp + 5;
xp = xp+1;
yp = yp - 1;
}
}
}
[/SOURCE]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0