Archived

This topic is now archived and is closed to further replies.

Sardius2

Drawing a circle with vertices?

Recommended Posts

Raloth    379
Equation for a circle:

r² = (x-h)² + (y-k)²

Where r is the radius, (x,y) is your point on the circle, and (h,k) is the center of the circle.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
better yet:

x = Rcos(theta)
y = Rsin(theta)

use values between 0 and 2pi. More values = more circular circle.

Share this post


Link to post
Share on other sites
Sardius2    122
Yes thank you for giving me equations for circles which I already knew. Now, how do I apply this to the vertices in DirectX?

[edited by - Sardius2 on August 14, 2003 10:16:24 PM]

Share this post


Link to post
Share on other sites
RenderTarget    398
It sounds like what you''re asking is, "How do I use DirectX?"

Step 1: Learn DirectX.


Specifically, you lock a vertex buffer, copy values, unlock it, set it up.. blah blah. You use DirectX, basically.

I like pie.

Share this post


Link to post
Share on other sites
Sardius2    122
Sounds like your not very helpful. I know how to do all that. Im not asking how to draw with Direct3d, I''m asking how to create the circle in the vertices. But aparently no one else here knows how to do that. Moot point then?

Share this post


Link to post
Share on other sites
Hawkeye3    122
AP gave you your x and your y, what else do you need? Simply iterate from 0 to 2pi, the size of the ''step'' between iteration decides the smoothness of the circle.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Yes, amazingly, no one here has figured out how to draw circles, and frankly, we''re quite upset about it, so no need to rub salt in old wounds!!

This is as far as we''ve gotten (we are presently working on getting more DARPA funding)
1. Create a vertex buffer, fill it with 2 vertices to draw a line. If you can draw it, have a beer.
2. Add one more vertex to the buffer and draw a line strip. If the strip draws, have another beer.
3. Use the aforementioned equations when adding more points to the vertex buffer. If you can implement the equations, have another beer.

At this point, we usually pass out and wake up with serious headaches (we''re lightweights), forcing us to start at #1. Perhaps you can get farther.

Share this post


Link to post
Share on other sites
RhoneRanger    100
quote:
Original post by Anonymous Poster
Yes, amazingly, no one here has figured out how to draw circles, and frankly, we''re quite upset about it, so no need to rub salt in old wounds!!

This is as far as we''ve gotten (we are presently working on getting more DARPA funding)
1. Create a vertex buffer, fill it with 2 vertices to draw a line. If you can draw it, have a beer.
2. Add one more vertex to the buffer and draw a line strip. If the strip draws, have another beer.
3. Use the aforementioned equations when adding more points to the vertex buffer. If you can implement the equations, have another beer.

At this point, we usually pass out and wake up with serious headaches (we''re lightweights), forcing us to start at #1. Perhaps you can get farther.



when I was doing this same thing, I substituted 3 beers, (instead of 1) so it took me 3 days to do a circle!!


for the ones who want to try this:::


First you x and y values for a circle are based on itinerations.


Than follow AP''s post, or teh Pythagorean theorum, based on what you learned about VB and IB.

CHEERS!

(Too Many beers)

Matt

Share this post


Link to post
Share on other sites
Sardius2    122
Where and how do I preform the iterations? I have been putting my vertex coordinates ina custom vertex structure that I created, but how would I create an iteration to do put in the vertex coordinates for me, when this is all stored inside a structure?

Share this post


Link to post
Share on other sites
RhoneRanger    100
quote:
Original post by Anonymous Poster
Yes, amazingly, no one here has figured out how to draw circles, and frankly, we're quite upset about it, so no need to rub salt in old wounds!!

This is as far as we've gotten (we are presently working on getting more DARPA funding)
1. Create a vertex buffer, fill it with 2 vertices to draw a line. If you can draw it, have a beer.
2. Add one more vertex to the buffer and draw a line strip. If the strip draws, have another beer.
3. Use the aforementioned equations when adding more points to the vertex buffer. If you can implement the equations, have another beer.

At this point, we usually pass out and wake up with serious headaches (we're lightweights), forcing us to start at #1. Perhaps you can get farther.


4. Learn about loops, have a beer.

5. Do these things,! Have 6 more beers!

EDIT: DONT TAKE SHORTCUTS have another 6 beers.

[edited by - RhoneRanger on August 14, 2003 11:55:16 PM]

Share this post


Link to post
Share on other sites
Etnu    880
Circles are round, and directX can only draw in triangles. A circle can never be made from a triangle. The obvious solution is to change the laws of Geometry to accomodate your plan. I would kill for round triangles.

Share this post


Link to post
Share on other sites
RhoneRanger    100
quote:
Original post by Etnu
Circles are round, and directX can only draw in triangles. A circle can never be made from a triangle. The obvious solution is to change the laws of Geometry to accomodate your plan. I would kill for round triangles.


I wonder, can DX draw Line Strips?

I also wonder if we want our circle filled or not?

Although you wont get a perfectly round circle, depending on how many iterations, you can come close.

Share this post


Link to post
Share on other sites
Teric    204

//-----------------------------------------------------------------------------------

//Draw a simple circle centered around the given point, using the given

//radius and color

//-----------------------------------------------------------------------------------

void DrawCircle(POINT pt, float radius, D3DCOLOR color, LPDIRECT3DDEVICE8 dev)
{
const int NUMPOINTS = 24;

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->SetVertexShader(D3DFVF_TL);
dev->SetTexture(0, NULL);
dev->DrawPrimitiveUP(D3DPT_LINESTRIP, NUMPOINTS, &Circle[0], sizeof(Circle[0]));

}//DrawCircle


If you increase the NumPoints variable, you'll get more line segments drawing the circle, and thus a more round-looking circle. However, it will also increase your draw time.

[edited by - Teric on August 15, 2003 1:10:25 PM]

Share this post


Link to post
Share on other sites